CppBenchmark 1.0.5.0
C++ Benchmark Library
Loading...
Searching...
No Matches
phase_metrics.h
Go to the documentation of this file.
1
9#ifndef CPPBENCHMARK_PHASE_METRICS_H
10#define CPPBENCHMARK_PHASE_METRICS_H
11
12#include <cstdint>
13#include <limits>
14#include <map>
15#include <string>
16
17namespace CppBenchmark {
18
20
37{
38 friend class PhaseCore;
39
40public:
43 PhaseMetrics(const PhaseMetrics&) = default;
44 PhaseMetrics(PhaseMetrics&&) noexcept = default;
45 ~PhaseMetrics();
46
47 PhaseMetrics& operator=(const PhaseMetrics&) = default;
48 PhaseMetrics& operator=(PhaseMetrics&&) noexcept = default;
49
51 bool latency() const noexcept;
53 int64_t min_latency() const noexcept;
55 int64_t max_latency() const noexcept;
57 double mean_latency() const noexcept;
59 double stdv_latency() const noexcept;
60
62 int64_t avg_time() const noexcept;
64 int64_t min_time() const noexcept;
66 int64_t max_time() const noexcept;
67
69 int64_t total_time() const noexcept { return _total_time; }
71 int64_t total_operations() const noexcept { return _total_operations; }
73 int64_t total_items() const noexcept { return _total_items; }
75 int64_t total_bytes() const noexcept { return _total_bytes; }
76
78 int64_t operations_per_second() const noexcept;
80 int64_t items_per_second() const noexcept;
82 int64_t bytes_per_second() const noexcept;
83
85 const std::map<std::string, int>& custom_int() const noexcept { return _custom_int; }
87 const std::map<std::string, unsigned>& custom_uint() const noexcept { return _custom_uint; }
89 const std::map<std::string, int64_t>& custom_int64() const noexcept { return _custom_int64; }
91 const std::map<std::string, uint64_t>& custom_uint64() const noexcept { return _custom_uint64; }
93 const std::map<std::string, float>& custom_flt() const noexcept { return _custom_flt; }
95 const std::map<std::string, double>& custom_dbl() const noexcept { return _custom_dbl; }
97 const std::map<std::string, std::string>& custom_str() const noexcept { return _custom_str; }
98
99 int threads() const noexcept { return _threads; }
100
102
105 void AddOperations(int64_t operations) noexcept
106 { _total_operations += operations; }
108
111 void AddItems(int64_t items) noexcept
112 { _total_items += items; }
114
117 void AddBytes(int64_t bytes) noexcept
118 { _total_bytes += bytes; }
119
121
125 void SetCustom(const std::string& name, int value)
126 { _custom_int[name] = value; }
128
132 void SetCustom(const std::string& name, unsigned value)
133 { _custom_uint[name] = value; }
135
139 void SetCustom(const std::string& name, int64_t value)
140 { _custom_int64[name] = value; }
142
146 void SetCustom(const std::string& name, uint64_t value)
147 { _custom_uint64[name] = value; }
149
153 void SetCustom(const std::string& name, float value)
154 { _custom_flt[name] = value; }
156
160 void SetCustom(const std::string& name, double value)
161 { _custom_dbl[name] = value; }
163
167 void SetCustom(const std::string& name, const std::string& value)
168 { _custom_str[name].assign(value); }
169
171
175 { _threads = threads; }
176
178
181 void AddLatency(int64_t latency) noexcept;
182
183private:
184 void* _histogram;
185 int64_t _min_time;
186 int64_t _max_time;
187 int64_t _total_time;
188 int64_t _total_operations;
189 int64_t _total_items;
190 int64_t _total_bytes;
191 std::map<std::string, int> _custom_int;
192 std::map<std::string, unsigned> _custom_uint;
193 std::map<std::string, int64_t> _custom_int64;
194 std::map<std::string, uint64_t> _custom_uint64;
195 std::map<std::string, float> _custom_flt;
196 std::map<std::string, double> _custom_dbl;
197 std::map<std::string, std::string> _custom_str;
198
199 int64_t _iterstamp;
200 int64_t _timestamp;
201
202 int _threads;
203
204 void InitLatencyHistogram(const std::tuple<int64_t, int64_t, int>& latency) noexcept;
205 void PrintLatencyHistogram(FILE* file, int32_t resolution) const noexcept;
206 void FreeLatencyHistogram() noexcept;
207
208 void StartCollecting() noexcept;
209 void StopCollecting() noexcept;
210
211 void MergeMetrics(PhaseMetrics& metrics);
212 void ResetMetrics() noexcept;
213};
214
215} // namespace CppBenchmark
216
217#endif // CPPBENCHMARK_PHASE_METRICS_H
Benchmark phase core.
Definition phase_core.h:27
Benchmark phase metrics.
const std::map< std::string, double > & custom_dbl() const noexcept
Get custom doubles map.
const std::map< std::string, unsigned > & custom_uint() const noexcept
Get custom unsigned integers map.
int64_t total_bytes() const noexcept
Get total bytes processed in the phase.
double mean_latency() const noexcept
Get latency mean value of the phase execution.
PhaseMetrics(const PhaseMetrics &)=default
int64_t total_time() const noexcept
Get total time of the phase execution.
const std::map< std::string, int > & custom_int() const noexcept
Get custom integers map.
void AddOperations(int64_t operations) noexcept
Increase operations count of the current phase.
int64_t min_time() const noexcept
Get minimal time of the phase execution.
void SetThreads(int threads)
Set threads value.
int64_t min_latency() const noexcept
Get latency minimal value of the phase execution.
double stdv_latency() const noexcept
Get latency standard deviation of the phase execution.
void SetCustom(const std::string &name, uint64_t value)
Set custom unsigned integer 64-bit value.
int64_t max_latency() const noexcept
Get latency maximal value of the phase execution.
const std::map< std::string, std::string > & custom_str() const noexcept
Get custom strings map.
void SetCustom(const std::string &name, double value)
Set custom double value.
int64_t total_items() const noexcept
Get total items processed in the phase.
void SetCustom(const std::string &name, unsigned value)
Set custom unsigned integer value.
void SetCustom(const std::string &name, const std::string &value)
Set custom string value.
const std::map< std::string, uint64_t > & custom_uint64() const noexcept
Get custom unsigned integers 64-bit map.
int64_t avg_time() const noexcept
Get average time of the phase execution.
int64_t max_time() const noexcept
Get maximal time of the phase execution.
void SetCustom(const std::string &name, int value)
Set custom integer value.
void SetCustom(const std::string &name, int64_t value)
Set custom integer 64-bit value.
void AddItems(int64_t items) noexcept
Register processed items in the current phase.
void AddBytes(int64_t bytes) noexcept
Register processed bytes in the current phase.
void AddLatency(int64_t latency) noexcept
Add latency value of the current phase.
PhaseMetrics(PhaseMetrics &&) noexcept=default
void SetCustom(const std::string &name, float value)
Set custom float value.
int64_t bytes_per_second() const noexcept
Get data throughput (bytes / second)
int64_t items_per_second() const noexcept
Get items throughput (items / second)
int64_t operations_per_second() const noexcept
Get operations throughput (operations / second)
const std::map< std::string, int64_t > & custom_int64() const noexcept
Get custom integers 64-bit map.
const std::map< std::string, float > & custom_flt() const noexcept
Get custom float map.
PhaseMetrics()
Default constructor.
bool latency() const noexcept
Is metrics contains latency values?
int64_t total_operations() const noexcept
Get total operations made in the phase.
int threads() const noexcept
C++ Benchmark project definitions.
Definition barrier.h:15