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 \
8 { \
9 {0.5, 0.1}, {0.9, 0.1}, { 0.99, 0.1 } \
10 }
11
12PerformanceTracker::PerformanceTracker(const std::shared_ptr<prometheus::Registry> &reg, const std::string &name,
13 uint64_t metricID)
14{
15 _perfTiming = &prometheus::BuildSummary()
16 .Name(name + "_processing_time_" + std::to_string(metricID))
17 .Help(name + " processing performance")
18 .Register(*reg)
19 .Add({}, QUANTILE_DEFAULTS);
20 _maxTiming = &prometheus::BuildGauge()
21 .Name(name + "_maximum_processing_time_" + std::to_string(metricID))
22 .Help("Maximum value of the " + name + " processing performance")
23 .Register(*reg)
24 .Add({});
25 _minTiming = &prometheus::BuildGauge()
26 .Name(name + "_minimum_processing_time_" + std::to_string(metricID))
27 .Help("Minimum value of the " + name + " processing performance")
28 .Register(*reg)
29 .Add({});
30
31 _minTiming->Set(std::numeric_limits<int>::max());
32}
33
34void PerformanceTracker::startTimer() { _startTime = std::chrono::high_resolution_clock::now(); }
35
37{
38 const auto val = static_cast<double>((std::chrono::high_resolution_clock::now() - _startTime).count());
39
40 _perfTiming->Observe(val);
41 if (val < _minTiming->Value())
42 {
43 _minTiming->Set(val);
44 }
45 if (val > _maxTiming->Value())
46 {
47 _maxTiming->Set(val);
48 }
49
50 return val;
51}
#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.