GENIE
PerfLogger.h
Go to the documentation of this file.
1 
2 #ifndef PERF_LOGGER_H_
3 #define PERF_LOGGER_H_
4 
5 #include <cassert>
6 #include <cstdint>
7 #include <fstream>
8 #include <memory>
9 #include <string>
10 #include <vector>
11 
13 
14 #include "Logger.h"
15 
16 namespace genie
17 {
18 namespace utility
19 {
20 
21 template <typename T>
22 class PerfLogger{
23 public:
24  static PerfLogger& Instance()
25  {
26  static PerfLogger<T> pl;
27  return pl;
28  }
29 
30  T& New(const std::string &filename)
31  {
32  if (ofs_.is_open())
33  ofs_.close();
34  ofs_.open(filename.c_str(), std::ios_base::out | std::ios_base::trunc);
35  assert(ofs_.good());
36  perf_data_->WriteHeader(ofs_);
37  return *(perf_data_.get());
38  }
39 
40  T& Log()
41  {
42  assert(ofs_.good());
43  dirty_perf_data_ = true;
44  return *(perf_data_.get());
45  }
46 
47  T& Reset()
48  {
49  perf_data_.reset(new T);
50  dirty_perf_data_ = false;
51  return *(perf_data_.get());
52  }
53 
54  T& Next()
55  {
56  assert(ofs_.good());
57  // assert(dirty_perf_data_);
58  perf_data_->WriteLine(ofs_);
59  Reset();
60  return *(perf_data_.get());
61  }
62 
63  virtual ~PerfLogger()
64  {
65  if (dirty_perf_data_)
66  perf_data_->WriteLine(ofs_);
67  ofs_.close();
68  }
69 
70 protected:
71  PerfLogger() : perf_data_(new T), dirty_perf_data_(false) {};
72  PerfLogger(PerfLogger const&);
76 
77  std::ofstream ofs_;
78  std::unique_ptr<T> perf_data_;
80 };
81 
82 
96 {
97 public:
99  compr_(genie::compression::NO_COMPRESSION),
100  overall_time_(0.0),
101  query_compilation_time_(0.0),
102  preprocessing_time_(0.0),
103  query_transfer_time_(0.0),
104  data_transfer_time_(0.0),
105  constant_transfer_time_(0.0),
106  allocation_time_(0.0),
107  filling_time_(0.0),
108  matching_time_(0.0),
109  convert_time_(0.0),
110  inv_size_(0),
111  dims_size_(0),
112  hash_table_capacity_per_query_(0),
113  threshold_size_(0),
114  passcount_size_(0),
115  bitmap_size_(0),
116  num_items_in_hash_table_size_(0),
117  topks_size_(0),
118  hash_table_size_(0),
119  compr_ratio_(0.0) {}
120 
121  void WriteHeader(std::ofstream &ofs)
122  {
123  ofs << "codec" << ","
124  << "overallTime" << ","
125  << "queryCompilationTime" << ","
126  << "preprocessingTime" << ","
127  << "queryTransferTime" << ","
128  << "dataTransferTime" << ","
129  << "constantTransferTime" << ","
130  << "allocationTime" << ","
131  << "fillingTime" << ","
132  << "matchingTime" << ","
133  << "convertTime" << ","
134  << "invSize" << ","
135  << "dimsSize" << ","
136  << "hashTableCapacityPerQuery" << ","
137  << "thresholdSize" << ","
138  << "passCountSize" << ","
139  << "bitMapSize" << ","
140  << "numItemsInHashTableSize" << ","
141  << "topksSize" << ","
142  << "hashTableSize" << ","
143  << "comprRatio" << std::endl;
144  }
145 
146  void WriteLine(std::ofstream &ofs)
147  {
148  std::string codec_name("no");
149  #ifdef GENIE_COMPR
151  #endif
152  ofs << codec_name << ","
153  << std::fixed << std::setprecision(3) << overall_time_ << ","
154  << std::fixed << std::setprecision(3) << query_compilation_time_ << ","
155  << std::fixed << std::setprecision(3) << preprocessing_time_ << ","
156  << std::fixed << std::setprecision(3) << query_transfer_time_ << ","
157  << std::fixed << std::setprecision(3) << data_transfer_time_ << ","
158  << std::fixed << std::setprecision(3) << constant_transfer_time_ << ","
159  << std::fixed << std::setprecision(3) << allocation_time_ << ","
160  << std::fixed << std::setprecision(3) << filling_time_ << ","
161  << std::fixed << std::setprecision(3) << matching_time_ << ","
162  << std::fixed << std::setprecision(3) << convert_time_ << ","
163  << inv_size_ << ","
164  << dims_size_ << ","
165  << hash_table_capacity_per_query_ << ","
166  << threshold_size_ << ","
167  << passcount_size_ << ","
168  << bitmap_size_ << ","
169  << num_items_in_hash_table_size_ << ","
170  << topks_size_ << ","
171  << hash_table_size_ << ","
172  << std::fixed << std::setprecision(3) << compr_ratio_ << std::endl;
173  }
174 
176  {
177  compr_ = compr;
178  return *this;
179  }
180 
181  MatchingPerfData& OverallTime (float overall_time)
182  {
183  overall_time_ = overall_time;
184  return *this;
185  }
186 
187  MatchingPerfData& QueryCompilationTime (float query_compilation_time)
188  {
189  query_compilation_time_ = query_compilation_time;
190  return *this;
191  }
192 
193  MatchingPerfData& PreprocessingTime (float preprocessing_time)
194  {
195  preprocessing_time_ = preprocessing_time;
196  return *this;
197  }
198 
199  MatchingPerfData& QueryTransferTime (float query_transfer_time)
200  {
201  query_transfer_time_ = query_transfer_time;
202  return *this;
203  }
204 
205  MatchingPerfData& DataTransferTime (float data_transfer_time)
206  {
207  data_transfer_time_ = data_transfer_time;
208  return *this;
209  }
210 
211  MatchingPerfData& ConstantTransferTime (float constant_transfer_time)
212  {
213  constant_transfer_time_ = constant_transfer_time;
214  return *this;
215  }
216 
217  MatchingPerfData& AllocationTime (float allocation_time)
218  {
219  allocation_time_ = allocation_time;
220  return *this;
221  }
222 
223  MatchingPerfData& FillingTime (float filling_time)
224  {
225  filling_time_ = filling_time;
226  return *this;
227  }
228 
229  MatchingPerfData& MatchingTime (float matching_time)
230  {
231  matching_time_ = matching_time;
232  return *this;
233  }
234 
235  MatchingPerfData& ConvertTime (float convert_time)
236  {
237  convert_time_ = convert_time;
238  return *this;
239  }
240 
241  MatchingPerfData& InvSize (size_t inv_size)
242  {
243  inv_size_ = inv_size;
244  return *this;
245  }
246 
247  MatchingPerfData& DimsSize (size_t dims_size)
248  {
249  dims_size_ = dims_size;
250  return *this;
251  }
252 
253  MatchingPerfData& HashTableCapacityPerQuery (size_t hash_table_capacity_per_query)
254  {
255  hash_table_capacity_per_query_ = hash_table_capacity_per_query;
256  return *this;
257  }
258 
259  MatchingPerfData& ThresholdSize (size_t threshold_size)
260  {
261  threshold_size_ = threshold_size;
262  return *this;
263  }
264 
265  MatchingPerfData& PasscountSize (size_t passcount_size)
266  {
267  passcount_size_ = passcount_size;
268  return *this;
269  }
270 
271  MatchingPerfData& BitmapSize (size_t bitmap_size)
272  {
273  bitmap_size_ = bitmap_size;
274  return *this;
275  }
276 
277  MatchingPerfData& NumItemsInHashTableSize (size_t num_items_in_hash_table_size)
278  {
279  num_items_in_hash_table_size_ = num_items_in_hash_table_size;
280  return *this;
281  }
282 
283  MatchingPerfData& TopksSize (size_t topks_size)
284  {
285  topks_size_ = topks_size;
286  return *this;
287  }
288 
289  MatchingPerfData& HashTableSize (size_t hash_table_size)
290  {
291  hash_table_size_ = hash_table_size;
292  return *this;
293  }
294 
295  MatchingPerfData& ComprRatio (float compr_ratio)
296  {
297  compr_ratio_ = compr_ratio;
298  return *this;
299  }
300 
301 protected:
313  size_t inv_size_;
314  size_t dims_size_;
318  size_t bitmap_size_;
320  size_t topks_size_;
323 };
324 
325 
326 
328 {
329 public:
331  array_size_(0),
332  time_(0.0),
333  throughput_(0.0) {};
334 
335  void WriteHeader(std::ofstream &ofs)
336  {
337  ofs << "array_size" << ","
338  << "time" << ","
339  << "throughput" << std::endl;
340  }
341 
342  void WriteLine(std::ofstream &ofs)
343  {
344  ofs << array_size_ << ","
345  << time_ << ","
346  << throughput_ << std::endl;
347  }
348 
349  ScanPerfData& ArraySize(size_t array_size)
350  {
351  array_size_ = array_size;
352  return *this;
353  }
354 
355  ScanPerfData& Time(float time)
356  {
357  time_ = time;
358  return *this;
359  }
360 
361  ScanPerfData& Throughput(float throughput)
362  {
363  throughput_ = throughput;
364  return *this;
365  }
366 
367 protected:
368  size_t array_size_;
369  float time_;
370  float throughput_;
371 };
372 
373 
374 
376 {
377 public:
379  array_size_(0),
380  time_(0.0),
381  throughput_(0.0) {};
382 
383  void WriteHeader(std::ofstream &ofs)
384  {
385  ofs << "codec" << ","
386  << "array_size" << ","
387  << "compr_size" << ","
388  << "ratio" << ","
389  << "time" << ","
390  << "throughput" << std::endl;
391  }
392 
393  void WriteLine(std::ofstream &ofs)
394  {
395  ofs << static_cast<int>(codec_) << ","
396  << array_size_ << ","
397  << compr_size_ << ","
398  << compr_ratio_ << ","
399  << time_ << ","
400  << throughput_ << std::endl;
401  }
402 
404  {
405  codec_ = codec;
406  return *this;
407  }
408 
409  CodecPerfData& ArraySize(size_t array_size)
410  {
411  array_size_ = array_size;
412  return *this;
413  }
414 
415  CodecPerfData& ComprSize(size_t compr_size)
416  {
417  compr_size_ = compr_size;
418  return *this;
419  }
420 
421  CodecPerfData& ComprRatio(float compr_ratio)
422  {
423  compr_ratio_ = compr_ratio;
424  return *this;
425  }
426 
427  CodecPerfData& Time(float time)
428  {
429  time_ = time;
430  return *this;
431  }
432 
433  CodecPerfData& Throughput(float throughput)
434  {
435  throughput_ = throughput;
436  return *this;
437  }
438 
439 protected:
441  size_t array_size_;
442  size_t compr_size_;
444  float time_;
445  float throughput_;
446 };
447 
448 } // namespace utility
449 } // namesapce genie
450 
451 #endif
T & New(const std::string &filename)
Definition: PerfLogger.h:30
void WriteLine(std::ofstream &ofs)
Definition: PerfLogger.h:342
void WriteHeader(std::ofstream &ofs)
Definition: PerfLogger.h:335
MatchingPerfData & OverallTime(float overall_time)
Definition: PerfLogger.h:181
This is the top-level namespace of the project.
void WriteLine(std::ofstream &ofs)
Definition: PerfLogger.h:146
void WriteLine(std::ofstream &ofs)
Definition: PerfLogger.h:393
MatchingPerfData & ThresholdSize(size_t threshold_size)
Definition: PerfLogger.h:259
MatchingPerfData & HashTableCapacityPerQuery(size_t hash_table_capacity_per_query)
Definition: PerfLogger.h:253
MatchingPerfData & AllocationTime(float allocation_time)
Definition: PerfLogger.h:217
MatchingPerfData & ConstantTransferTime(float constant_transfer_time)
Definition: PerfLogger.h:211
ScanPerfData & Throughput(float throughput)
Definition: PerfLogger.h:361
MatchingPerfData & DimsSize(size_t dims_size)
Definition: PerfLogger.h:247
ScanPerfData & ArraySize(size_t array_size)
Definition: PerfLogger.h:349
PerfLogger< T > & operator=(PerfLogger const &)
MatchingPerfData & NumItemsInHashTableSize(size_t num_items_in_hash_table_size)
Definition: PerfLogger.h:277
MatchingPerfData & FillingTime(float filling_time)
Definition: PerfLogger.h:223
MatchingPerfData & TopksSize(size_t topks_size)
Definition: PerfLogger.h:283
MatchingPerfData & HashTableSize(size_t hash_table_size)
Definition: PerfLogger.h:289
genie::compression::COMPRESSION_TYPE compr_
Definition: PerfLogger.h:302
MatchingPerfData & MatchingTime(float matching_time)
Definition: PerfLogger.h:229
CodecPerfData & ComprRatio(float compr_ratio)
Definition: PerfLogger.h:421
CodecPerfData & Codec(genie::compression::COMPRESSION_TYPE codec)
Definition: PerfLogger.h:403
MatchingPerfData & PreprocessingTime(float preprocessing_time)
Definition: PerfLogger.h:193
std::unique_ptr< T > perf_data_
Definition: PerfLogger.h:78
MatchingPerfData & PasscountSize(size_t passcount_size)
Definition: PerfLogger.h:265
MatchingPerfData & ComprRatio(float compr_ratio)
Definition: PerfLogger.h:295
Record run-time information.
MatchingPerfData & DataTransferTime(float data_transfer_time)
Definition: PerfLogger.h:205
static PerfLogger & Instance()
Definition: PerfLogger.h:24
MatchingPerfData & QueryCompilationTime(float query_compilation_time)
Definition: PerfLogger.h:187
CodecPerfData & ComprSize(size_t compr_size)
Definition: PerfLogger.h:415
void WriteHeader(std::ofstream &ofs)
Definition: PerfLogger.h:121
ScanPerfData & Time(float time)
Definition: PerfLogger.h:355
MatchingPerfData & QueryTransferTime(float query_transfer_time)
Definition: PerfLogger.h:199
CodecPerfData & ArraySize(size_t array_size)
Definition: PerfLogger.h:409
MatchingPerfData & InvSize(size_t inv_size)
Definition: PerfLogger.h:241
MatchingPerfData & BitmapSize(size_t bitmap_size)
Definition: PerfLogger.h:271
MatchingPerfData & Compr(genie::compression::COMPRESSION_TYPE compr)
Definition: PerfLogger.h:175
MatchingPerfData & ConvertTime(float convert_time)
Definition: PerfLogger.h:235
CodecPerfData & Throughput(float throughput)
Definition: PerfLogger.h:433
CodecPerfData & Time(float time)
Definition: PerfLogger.h:427
static std::string getCompressionName(COMPRESSION_TYPE type)
void WriteHeader(std::ofstream &ofs)
Definition: PerfLogger.h:383
genie::compression::COMPRESSION_TYPE codec_
Definition: PerfLogger.h:440