JODA  0.13.1 (59b41972)
JSON On-Demand Analysis
Benchmark.h
Go to the documentation of this file.
1 //
2 // Created by Nico Schäfer on 9/19/17.
3 //
4 
5 #ifndef JODA_BENCHMARK_H
6 #define JODA_BENCHMARK_H
7 
8 #include <glog/logging.h>
9 #include <rapidjson/document.h>
10 #include <cassert>
11 #include <filesystem>
12 #include <iomanip>
13 #include <mutex>
14 #include <string>
15 #include <vector>
16 #include "RJFwd.h"
17 namespace fs = std::filesystem;
18 
27 class Benchmark {
28  public:
33  Benchmark();
34 
42  explicit Benchmark(const std::string &file);
43  Benchmark(const Benchmark &b) = delete;
44  Benchmark &operator=(const Benchmark &b) = delete;
45  Benchmark(Benchmark &&b);
47 
52  virtual ~Benchmark();
53 
59  template <typename T>
60  void addValue(const std::string &header, T &&val) {
61  return addValueAt("/" + header, val);
62  }
63 
70  template <typename T>
71  void addValue(const std::string &prefix, const std::string &header, T &&val) {
72  return addValueAt(prefix + "/" + header, val);
73  }
74 
81  template <typename T>
82  void addValueAt(const std::string &pointer, T &&val) {
83  if (!valid) return;
84  RJPointer ptr(pointer.c_str());
85  return addValueAt(ptr, val);
86  }
87 
94  template <typename T>
95  void addValueAt(const RJPointer &pointer, T &&val) {
96  if (!valid) return;
97  std::lock_guard<std::mutex> lock(mut);
98  DCHECK(currentLine.IsObject());
99  pointer.Set(currentLine, val, benchDoc.GetAllocator());
100  }
101 
105  void addThread(double bloom, double select, double project, double agg,
106  double copy, double serialize, double sample_view_cost);
107 
112  void finishLine();
113 
118  std::string toString() const;
119 
125  std::string lastLineToString() const;
126 
132  const RJValue &getLastLine() const;
133 
138  std::string currentLineToString() const;
139 
145  bool isValid() const;
146 
147  protected:
148  std::mutex mut;
151  bool valid = false;
152  bool local = true;
153  fs::path benchfile;
154 
155  void parseBenchfile();
156  void writeBenchfile() const;
157 
158  public:
159  /*
160  * prefixes
161  */
162  static auto constexpr RUNTIME = "/Runtime";
163  static auto constexpr THREADS = "/Runtime/Threads";
164 };
165 
166 #endif // JODA_BENCHMARK_H
rapidjson::GenericDocument< RJChar, RJMemoryPoolAlloc, RJBaseAlloc > RJDocument
Definition: RJFwd.h:28
rapidjson::GenericPointer< RJValue, RJBaseAlloc > RJPointer
Definition: RJFwd.h:30
rapidjson::GenericValue< RJChar, RJMemoryPoolAlloc > RJValue
Definition: RJFwd.h:29
Definition: Benchmark.h:27
void addValue(const std::string &prefix, const std::string &header, T &&val)
Definition: Benchmark.h:71
std::string toString() const
Definition: Benchmark.cpp:127
RJValue currentLine
Definition: Benchmark.h:150
virtual ~Benchmark()
Definition: Benchmark.cpp:137
static constexpr auto THREADS
Definition: Benchmark.h:163
static constexpr auto RUNTIME
Definition: Benchmark.h:162
std::mutex mut
Definition: Benchmark.h:148
Benchmark(const Benchmark &b)=delete
void addThread(double bloom, double select, double project, double agg, double copy, double serialize, double sample_view_cost)
Definition: Benchmark.cpp:159
const RJValue & getLastLine() const
Definition: Benchmark.cpp:201
std::string currentLineToString() const
Definition: Benchmark.cpp:149
RJDocument benchDoc
Definition: Benchmark.h:149
void addValueAt(const RJPointer &pointer, T &&val)
Definition: Benchmark.h:95
void addValue(const std::string &header, T &&val)
Definition: Benchmark.h:60
void addValueAt(const std::string &pointer, T &&val)
Definition: Benchmark.h:82
fs::path benchfile
Definition: Benchmark.h:153
void finishLine()
Definition: Benchmark.cpp:110
Benchmark()
Definition: Benchmark.cpp:19
Benchmark & operator=(const Benchmark &b)=delete
std::string lastLineToString() const
Definition: Benchmark.cpp:139
void parseBenchfile()
Definition: Benchmark.cpp:74
bool isValid() const
Definition: Benchmark.cpp:199
bool valid
Definition: Benchmark.h:151
void writeBenchfile() const
Definition: Benchmark.cpp:98