Repo-Init
 
Loading...
Searching...
No Matches
PerformanceTracker Class Reference

#include <Performance.hpp>

Public Member Functions

 PerformanceTracker (const std::shared_ptr< prometheus::Registry > &reg, const std::string &name, uint64_t metricID=0)
 
void startTimer ()
 
double endTimer ()
 

Private Attributes

std::chrono::high_resolution_clock::time_point _startTime
 Set after startTimer to measure counter difference.
 
prometheus::Summary * _perfTiming
 Overall performance.
 
prometheus::Gauge * _maxTiming
 Maximum observed value.
 
prometheus::Gauge * _minTiming
 Minimum observed value.
 

Detailed Description

Measures and calculates performance metrics.

The PerformanceTracker class is responsible for measuring and calculating performance metrics. It provides functionality to start and stop a timer, and calculates the elapsed time between the start and stop events. The class uses the prometheus library to store and manage the performance metrics.

Definition at line 13 of file Performance.hpp.

Constructor & Destructor Documentation

◆ PerformanceTracker()

PerformanceTracker::PerformanceTracker ( const std::shared_ptr< prometheus::Registry > & reg,
const std::string & name,
uint64_t metricID = 0 )

Construct a new PerformanceTracker object.

Parameters
[in]regThe registry to register the performance metrics.
[in]nameThe name of the metric.
[in]metricIDThe ID to append to metric names.

Definition at line 9 of file Performance.cpp.

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}
#define QUANTILE_DEFAULTS
prometheus::Gauge * _minTiming
Minimum observed value.
prometheus::Summary * _perfTiming
Overall performance.
prometheus::Gauge * _maxTiming
Maximum observed value.

Member Function Documentation

◆ endTimer()

double PerformanceTracker::endTimer ( )

Ends the timer and updates internal statistics.

Returns
The result of the timer in nanoseconds.

Definition at line 33 of file Performance.cpp.

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}
std::chrono::high_resolution_clock::time_point _startTime
Set after startTimer to measure counter difference.
Here is the caller graph for this function:

◆ startTimer()

void PerformanceTracker::startTimer ( )

Starts the timer.

Definition at line 31 of file Performance.cpp.

31{ _startTime = std::chrono::high_resolution_clock::now(); }
Here is the caller graph for this function:

Member Data Documentation

◆ _maxTiming

prometheus::Gauge* PerformanceTracker::_maxTiming
private

Maximum observed value.

Definition at line 17 of file Performance.hpp.

◆ _minTiming

prometheus::Gauge* PerformanceTracker::_minTiming
private

Minimum observed value.

Definition at line 18 of file Performance.hpp.

◆ _perfTiming

prometheus::Summary* PerformanceTracker::_perfTiming
private

Overall performance.

Definition at line 16 of file Performance.hpp.

◆ _startTime

std::chrono::high_resolution_clock::time_point PerformanceTracker::_startTime
private

Set after startTimer to measure counter difference.

Definition at line 15 of file Performance.hpp.


The documentation for this class was generated from the following files: