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 12 of file Performance.cpp.

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}
#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 36 of file Performance.cpp.

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}
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 34 of file Performance.cpp.

34{ _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: