MySQL 9.1.0
Source Code Documentation
Time_based_metric Class Reference

Class that encodes how much time we waited for something. More...

#include <time_based_metric.h>

Inheritance diagram for Time_based_metric:
[legend]

Public Member Functions

 Time_based_metric (bool manual_counting=false)
 Constructor that allows you to define counting as being manual. More...
 
Time_based_metricoperator= (const Time_based_metric &other)
 Assignment operator. More...
 
 Time_based_metric (const Time_based_metric &)=delete
 Deleted copy constructor, move constructor, move assignment operator. More...
 
 Time_based_metric (Time_based_metric &&)=delete
 
Time_based_metricoperator= (Time_based_metric &&)=delete
 
 ~Time_based_metric () override=default
 Default destuctor. More...
 
void reset () override
 Resets the counter and summed time to 0. More...
 
void start_timer () override
 Starts counting time we are waiting on something. More...
 
void stop_timer () override
 Stops the timer for the wait. More...
 
int64_t get_sum_time_elapsed () const override
 Returns the time waited across all executions of the start/stop methods. More...
 
void increment_counter () override
 Increments the waiting counter. More...
 
int64_t get_count () const override
 Returns the number of time we waited on give spot. More...
 
- Public Member Functions inherited from Time_based_metric_interface
virtual ~Time_based_metric_interface ()=default
 

Static Private Member Functions

static int64_t now ()
 Helper to get current time. More...
 

Private Attributes

std::atomic< int64_t > m_time {0}
 The total nanoseconds of all completed waits, minus the absolute start time of an ongoing wait, if any. More...
 
std::atomic< int64_t > m_count {0}
 The number of times we waited. More...
 
bool m_manual_counting {false}
 If false, the counter is incremented automatically by start_time, and the caller must not invoke increment_counter. More...
 

Detailed Description

Class that encodes how much time we waited for something.

Constructor & Destructor Documentation

◆ Time_based_metric() [1/3]

Time_based_metric::Time_based_metric ( bool  manual_counting = false)
explicit

Constructor that allows you to define counting as being manual.

Parameters
manual_countingshall count be automatic on start_timer or not (default false)

◆ Time_based_metric() [2/3]

Time_based_metric::Time_based_metric ( const Time_based_metric )
delete

Deleted copy constructor, move constructor, move assignment operator.

◆ Time_based_metric() [3/3]

Time_based_metric::Time_based_metric ( Time_based_metric &&  )
delete

◆ ~Time_based_metric()

Time_based_metric::~Time_based_metric ( )
overridedefault

Default destuctor.

Member Function Documentation

◆ get_count()

int64_t Time_based_metric::get_count ( ) const
overridevirtual

Returns the number of time we waited on give spot.

Returns
the number of times waited

Implements Time_based_metric_interface.

◆ get_sum_time_elapsed()

int64_t Time_based_metric::get_sum_time_elapsed ( ) const
overridevirtual

Returns the time waited across all executions of the start/stop methods.

Returns
The total time waited

Implements Time_based_metric_interface.

◆ increment_counter()

void Time_based_metric::increment_counter ( )
overridevirtual

Increments the waiting counter.

Implements Time_based_metric_interface.

◆ now()

int64_t Time_based_metric::now ( )
staticprivate

Helper to get current time.

Returns
Current time since the epoch for steady_clock, in nanoseconds.

◆ operator=() [1/2]

Time_based_metric & Time_based_metric::operator= ( const Time_based_metric other)

Assignment operator.

Parameters
otherthe object that is copied
Returns
this object

◆ operator=() [2/2]

Time_based_metric & Time_based_metric::operator= ( Time_based_metric &&  )
delete

◆ reset()

void Time_based_metric::reset ( )
overridevirtual

Resets the counter and summed time to 0.

Implements Time_based_metric_interface.

◆ start_timer()

void Time_based_metric::start_timer ( )
overridevirtual

Starts counting time we are waiting on something.

Implements Time_based_metric_interface.

◆ stop_timer()

void Time_based_metric::stop_timer ( )
overridevirtual

Stops the timer for the wait.

Requires start_timer to be called first

Implements Time_based_metric_interface.

Member Data Documentation

◆ m_count

std::atomic<int64_t> Time_based_metric::m_count {0}
private

The number of times we waited.

◆ m_manual_counting

bool Time_based_metric::m_manual_counting {false}
private

If false, the counter is incremented automatically by start_time, and the caller must not invoke increment_counter.

If true, the counter is not incremented by start_time, so the caller has to invoke increment_counter.

◆ m_time

std::atomic<int64_t> Time_based_metric::m_time {0}
private

The total nanoseconds of all completed waits, minus the absolute start time of an ongoing wait, if any.

If there is no ongoing wait, this is nonnegative and is the correct metric. If there is an ongoing wait, this is negative, and the correct value is given by adding the current time to it: result = sum_of_completed_waits + current_time - start_of_current_wait


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