Utopia 2
Framework for studying models of complex & adaptive systems.
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Attributes | List of all members
Utopia::DataIO::MonitorTimer Class Reference

The MonitorTimer keeps track of the time when to emit monitor data. More...

#include <monitor.hh>

Public Types

using Clock = std::chrono::high_resolution_clock
 Data type for the clock.
 
using Time = std::chrono::high_resolution_clock::time_point
 Data type for a time point.
 
using DurationType = std::chrono::duration< double >
 Data type for the time unit.
 

Public Member Functions

 MonitorTimer (const double emit_interval)
 Constructor.
 
bool time_has_come () const
 Check for whether the time to emit has come or not.
 
void reset ()
 Reset the timer to the current time.
 
template<class DurationT = DurationType>
const DurationT get_time_elapsed () const
 Get the time elapsed since the start of this timer.
 
double get_time_elapsed_seconds () const
 Get the time elapsed since start of this timer, converted to seconds.
 
const DurationType get_emit_interval () const
 Return the emit interval.
 

Private Attributes

const DurationType _emit_interval
 The emit interval.
 
const Time _start_time
 The starting time of the timer.
 
Time _last_emit
 The time of the last emit.
 

Detailed Description

The MonitorTimer keeps track of the time when to emit monitor data.

Member Typedef Documentation

◆ Clock

using Utopia::DataIO::MonitorTimer::Clock = std::chrono::high_resolution_clock

Data type for the clock.

◆ DurationType

Data type for the time unit.

◆ Time

using Utopia::DataIO::MonitorTimer::Time = std::chrono::high_resolution_clock::time_point

Data type for a time point.

Constructor & Destructor Documentation

◆ MonitorTimer()

Utopia::DataIO::MonitorTimer::MonitorTimer ( const double  emit_interval)
inline

Constructor.

Construct a new Monitor Timer object. The _last_emit time is set to the time of construction.

Parameters
emit_intervalThe time interval that defines whether the time has come to emit data. If more time than the _emit_interval has passed the time_has_come function returns true.
97 :
98 // Store the emit interval
100 // Set the starting time member
101 _start_time(Clock::now()),
102 // Initialize _last_emit empty, setting it to 1.1.1970, 0:00, meaning
103 // that no emit has occurred yet.
104 _last_emit(){};
const DurationType _emit_interval
The emit interval.
Definition monitor.hh:79
Time _last_emit
The time of the last emit.
Definition monitor.hh:85
const Time _start_time
The starting time of the timer.
Definition monitor.hh:82
Container select_entities(const Manager &mngr, const DataIO::Config &sel_cfg)
Select entities according to parameters specified in a configuration.
Definition select.hh:213

Member Function Documentation

◆ get_emit_interval()

const DurationType Utopia::DataIO::MonitorTimer::get_emit_interval ( ) const
inline

Return the emit interval.

147 {
148 return _emit_interval;
149 }

◆ get_time_elapsed()

template<class DurationT = DurationType>
const DurationT Utopia::DataIO::MonitorTimer::get_time_elapsed ( ) const
inline

Get the time elapsed since the start of this timer.

133 {
134 return Clock::now() - _start_time;
135 }

◆ get_time_elapsed_seconds()

double Utopia::DataIO::MonitorTimer::get_time_elapsed_seconds ( ) const
inline

Get the time elapsed since start of this timer, converted to seconds.

◆ reset()

void Utopia::DataIO::MonitorTimer::reset ( )
inline

Reset the timer to the current time.

125 {
126 _last_emit = Clock::now();
127 }

◆ time_has_come()

bool Utopia::DataIO::MonitorTimer::time_has_come ( ) const
inline

Check for whether the time to emit has come or not.

Parameters
resetReset the internal timer to the current time if the _emit_interval has been exceeded.
Returns
true if the internal timer has exceeded the _last_emit time.
114 {
115 // Calculate the time difference between now and the last emit
116 const DurationType duration = Clock::now() - _last_emit;
117
118 // If more time than the _emit_interval has passed, return true
119 return (duration > _emit_interval);
120 }
std::chrono::duration< double > DurationType
Data type for the time unit.
Definition monitor.hh:74

Member Data Documentation

◆ _emit_interval

const DurationType Utopia::DataIO::MonitorTimer::_emit_interval
private

The emit interval.

◆ _last_emit

Time Utopia::DataIO::MonitorTimer::_last_emit
private

The time of the last emit.

◆ _start_time

const Time Utopia::DataIO::MonitorTimer::_start_time
private

The starting time of the timer.


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