20 #include <hdr/hdr_histogram.h>
31 FreeLatencyHistogram();
36 return (_histogram !=
nullptr);
41 return latency() ? hdr_min((
const hdr_histogram*)_histogram) : 0;
46 return latency() ? hdr_max((
const hdr_histogram*)_histogram) : 0;
51 return latency() ? hdr_mean((
const hdr_histogram*)_histogram) : 0;
56 return latency() ? hdr_stddev((
const hdr_histogram*)_histogram) : 0;
61 return (_total_operations > 0) ? (_total_time / _total_operations) : 0;
98 void PhaseMetrics::InitLatencyHistogram(
const std::tuple<int64_t, int64_t, int>& latency) noexcept
100 int64_t lowest = std::get<0>(latency);
101 int64_t highest = std::get<1>(latency);
102 int significant = std::get<2>(latency);
104 FreeLatencyHistogram();
105 int result = hdr_init(lowest, highest, significant, ((hdr_histogram**)&_histogram));
107 _histogram =
nullptr;
110 void PhaseMetrics::PrintLatencyHistogram(FILE* file, int32_t resolution)
const noexcept
112 if ((_histogram !=
nullptr) && (file !=
nullptr))
114 hdr_percentiles_print((hdr_histogram*)_histogram, file, resolution, 1.0, CLASSIC);
118 void PhaseMetrics::FreeLatencyHistogram() noexcept
120 if (_histogram !=
nullptr)
122 hdr_close((hdr_histogram*)_histogram);
123 _histogram =
nullptr;
129 if (_histogram !=
nullptr)
130 hdr_record_values((hdr_histogram*)_histogram, latency, 1);
133 void PhaseMetrics::StartCollecting() noexcept
135 _iterstamp = _total_operations;
139 void PhaseMetrics::StopCollecting() noexcept
142 int64_t iterations = _total_operations - _iterstamp;
146 int64_t
min_time = (iterations > 0) ? (duration / iterations) : std::numeric_limits<int64_t>::max();
147 int64_t
max_time = (iterations > 0) ? (duration / iterations) : std::numeric_limits<int64_t>::min();
154 _total_time += duration;
157 void PhaseMetrics::MergeMetrics(PhaseMetrics& metrics)
160 if (metrics._min_time < _min_time)
161 _min_time = metrics._min_time;
164 if (metrics._max_time > _max_time)
165 _max_time = metrics._max_time;
168 _custom_int.insert(metrics._custom_int.begin(), metrics._custom_int.end());
169 _custom_uint.insert(metrics._custom_uint.begin(), metrics._custom_uint.end());
170 _custom_int64.insert(metrics._custom_int64.begin(), metrics._custom_int64.end());
171 _custom_uint64.insert(metrics._custom_uint64.begin(), metrics._custom_uint64.end());
172 _custom_flt.insert(metrics._custom_flt.begin(), metrics._custom_flt.end());
173 _custom_dbl.insert(metrics._custom_dbl.begin(), metrics._custom_dbl.end());
174 _custom_str.insert(metrics._custom_str.begin(), metrics._custom_str.end());
177 if (metrics._total_time < _total_time)
179 std::swap(_histogram, metrics._histogram);
180 _total_time = metrics._total_time;
181 _total_operations = metrics._total_operations;
182 _total_items = metrics._total_items;
183 _total_bytes = metrics._total_bytes;
186 for (
const auto& it : metrics._custom_int)
187 _custom_int[it.first] = it.second;
188 for (
const auto& it : metrics._custom_uint)
189 _custom_uint[it.first] = it.second;
190 for (
const auto& it : metrics._custom_int64)
191 _custom_int64[it.first] = it.second;
192 for (
const auto& it : metrics._custom_uint64)
193 _custom_uint64[it.first] = it.second;
194 for (
const auto& it : metrics._custom_flt)
195 _custom_flt[it.first] = it.second;
196 for (
const auto& it : metrics._custom_dbl)
197 _custom_dbl[it.first] = it.second;
198 for (
const auto& it : metrics._custom_str)
199 _custom_str[it.first] = it.second;
202 _threads = metrics._threads;
206 void PhaseMetrics::ResetMetrics() noexcept
208 FreeLatencyHistogram();
209 _min_time = std::numeric_limits<int64_t>::max();
210 _max_time = std::numeric_limits<int64_t>::min();
212 _total_operations = 0;
double mean_latency() const noexcept
Get latency mean value of the phase execution.
int64_t min_time() const noexcept
Get minimal time of the phase execution.
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.
int64_t max_latency() const noexcept
Get latency maximal value of the phase execution.
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 AddLatency(int64_t latency) noexcept
Add latency value of the current phase.
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)
PhaseMetrics()
Default constructor.
bool latency() const noexcept
Is metrics contains latency values?
static uint64_t Timestamp()
Get the current timestamp in nanoseconds.
static uint64_t MulDiv64(uint64_t operant, uint64_t multiplier, uint64_t divider)
Calculate (operant * multiplier / divider) with 64-bit unsigned integer values.
C++ Benchmark project definitions.
Benchmark phase metrics definition.
System management definition.