Monitoring System 0.1.0
System resource monitoring with pluggable collectors and alerting
Loading...
Searching...
No Matches
kcenon::monitoring::scoped_timer Class Reference

Scoped performance timer. More...

#include <performance_monitor.h>

Collaboration diagram for kcenon::monitoring::scoped_timer:
Collaboration graph

Public Member Functions

 scoped_timer (performance_profiler *profiler, const std::string &operation_name)
 
 ~scoped_timer ()
 
void mark_failed ()
 Mark the operation as failed.
 
void complete ()
 Manually complete the timing.
 
std::chrono::nanoseconds elapsed () const
 Get elapsed time without completing.
 

Private Attributes

performance_profilerprofiler_
 
std::string operation_name_
 
std::chrono::high_resolution_clock::time_point start_time_
 
bool success_ {true}
 
bool completed_ {false}
 

Detailed Description

Scoped performance timer.

Definition at line 236 of file performance_monitor.h.

Constructor & Destructor Documentation

◆ scoped_timer()

kcenon::monitoring::scoped_timer::scoped_timer ( performance_profiler * profiler,
const std::string & operation_name )
inline
Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/core/performance_monitor.h.

Definition at line 245 of file performance_monitor.h.

246 : profiler_(profiler)
247 , operation_name_(operation_name)
248 , start_time_(std::chrono::high_resolution_clock::now()) {}
std::chrono::high_resolution_clock::time_point start_time_

◆ ~scoped_timer()

kcenon::monitoring::scoped_timer::~scoped_timer ( )
inline
Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/core/performance_monitor.h.

Definition at line 250 of file performance_monitor.h.

250 {
251 if (!completed_ && profiler_) {
252 complete();
253 }
254 }
void complete()
Manually complete the timing.

References complete(), completed_, and profiler_.

Here is the call graph for this function:

Member Function Documentation

◆ complete()

void kcenon::monitoring::scoped_timer::complete ( )
inline

Manually complete the timing.

Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/core/performance_monitor.h.

Definition at line 264 of file performance_monitor.h.

264 {
265 if (completed_) return;
266
267 auto end_time = std::chrono::high_resolution_clock::now();
268 auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(
269 end_time - start_time_
270 );
271
272 if (profiler_) {
274 }
275
276 completed_ = true;
277 }
common::Result< bool > record_sample(const std::string &operation_name, std::chrono::nanoseconds duration, bool success=true)
Record a performance sample.

References completed_, operation_name_, profiler_, kcenon::monitoring::performance_profiler::record_sample(), start_time_, and success_.

Referenced by ~scoped_timer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ elapsed()

std::chrono::nanoseconds kcenon::monitoring::scoped_timer::elapsed ( ) const
inline

Get elapsed time without completing.

Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/core/performance_monitor.h.

Definition at line 282 of file performance_monitor.h.

282 {
283 auto now = std::chrono::high_resolution_clock::now();
284 return std::chrono::duration_cast<std::chrono::nanoseconds>(
285 now - start_time_
286 );
287 }

References start_time_.

◆ mark_failed()

void kcenon::monitoring::scoped_timer::mark_failed ( )
inline

Mark the operation as failed.

Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/core/performance_monitor.h.

Definition at line 259 of file performance_monitor.h.

259{ success_ = false; }

References success_.

Member Data Documentation

◆ completed_

bool kcenon::monitoring::scoped_timer::completed_ {false}
private

◆ operation_name_

std::string kcenon::monitoring::scoped_timer::operation_name_
private

◆ profiler_

performance_profiler* kcenon::monitoring::scoped_timer::profiler_
private

◆ start_time_

std::chrono::high_resolution_clock::time_point kcenon::monitoring::scoped_timer::start_time_
private

◆ success_

bool kcenon::monitoring::scoped_timer::success_ {true}
private

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