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