Repo-Init
 
Loading...
Searching...
No Matches
Performance.cpp
Go to the documentation of this file.
2
3#include <prometheus/gauge.h>
4#include <prometheus/summary.h>
5
6#define QUANTILE_DEFAULTS \
7 prometheus::Summary::Quantiles { {0.5, 0.1}, {0.9, 0.1}, {0.99, 0.1} }
8
9PerformanceTracker::PerformanceTracker(const std::shared_ptr<prometheus::Registry> &reg, const std::string &name,
10 uint64_t metricID)
11{
12 _perfTiming = &prometheus::BuildSummary()
13 .Name(name + "_processing_time_" + std::to_string(metricID))
14 .Help(name + " processing performance")
15 .Register(*reg)
16 .Add({}, QUANTILE_DEFAULTS);
17 _maxTiming = &prometheus::BuildGauge()
18 .Name(name + "_maximum_processing_time_" + std::to_string(metricID))
19 .Help("Maximum value of the " + name + " processing performance")
20 .Register(*reg)
21 .Add({});
22 _minTiming = &prometheus::BuildGauge()
23 .Name(name + "_minimum_processing_time_" + std::to_string(metricID))
24 .Help("Minimum value of the " + name + " processing performance")
25 .Register(*reg)
26 .Add({});
27
28 _minTiming->Set(std::numeric_limits<int>::max());
29}
30
31void PerformanceTracker::startTimer() { _startTime = std::chrono::high_resolution_clock::now(); }
32
34{
35 const auto val = static_cast<double>((std::chrono::high_resolution_clock::now() - _startTime).count());
36
37 _perfTiming->Observe(val);
38 if (val < _minTiming->Value())
39 {
40 _minTiming->Set(val);
41 }
42 if (val > _maxTiming->Value())
43 {
44 _maxTiming->Set(val);
45 }
46
47 return val;
48}
#define QUANTILE_DEFAULTS
prometheus::Gauge * _minTiming
Minimum observed value.
std::chrono::high_resolution_clock::time_point _startTime
Set after startTimer to measure counter difference.
PerformanceTracker(const std::shared_ptr< prometheus::Registry > &reg, const std::string &name, uint64_t metricID=0)
prometheus::Summary * _perfTiming
Overall performance.
prometheus::Gauge * _maxTiming
Maximum observed value.