Timer that measures CPU time ticks using get_cpu_time().
More...
#include <CpuTickTimer.hpp>
|
| CpuTickTimer (bool is_start_immediately=true) noexcept |
| Construct timer and optionally start it immediately.
|
|
void | start () noexcept |
| Start measuring CPU time.
|
|
void | restart () noexcept |
| Restart timer and reset collected statistics.
|
|
void | stop () noexcept |
| Stop measuring CPU time and freeze elapsed ticks.
|
|
double | elapsed () const noexcept |
| Get elapsed CPU ticks since the last start.
|
|
double | record_sample () noexcept |
| Record sample using elapsed ticks and restart timer.
|
|
void | reset_samples () noexcept |
| Reset collected samples without touching running state.
|
|
std::size_t | sample_count () const noexcept |
| Get the number of recorded samples.
|
|
double | total_ticks () const noexcept |
| Get total recorded CPU ticks across samples.
|
|
double | average_ticks () const noexcept |
| Get average CPU ticks per sample.
|
|
double | last_sample_ticks () const noexcept |
| Get ticks collected during the last recorded sample.
|
|
Timer that measures CPU time ticks using get_cpu_time().
Class is intended for single-threaded use and assumes that get_cpu_time() is monotonic within the current process or thread. For long-running measurements (for example, durations longer than a day) it is recommended to periodically call record_sample() or restart() to limit floating-point precision loss.
- Note
- All reported durations are expressed in CPU tick units provided by get_cpu_time().
Definition at line 25 of file CpuTickTimer.hpp.
◆ CpuTickTimer()
time_shield::CpuTickTimer::CpuTickTimer |
( |
bool | is_start_immediately = true | ) |
|
|
inlineexplicitnoexcept |
Construct timer and optionally start it immediately.
- Parameters
-
is_start_immediately | Indicates whether the timer should start right away. |
Definition at line 29 of file CpuTickTimer.hpp.
◆ accumulate_ticks()
void time_shield::CpuTickTimer::accumulate_ticks |
( |
double | sample_ticks | ) |
|
|
inlineprivatenoexcept |
◆ average_ticks()
double time_shield::CpuTickTimer::average_ticks |
( |
| ) |
const |
|
inlinenodiscardnoexcept |
Get average CPU ticks per sample.
- Returns
- Average CPU tick units or NaN if there are no samples.
Definition at line 105 of file CpuTickTimer.hpp.
◆ elapsed()
double time_shield::CpuTickTimer::elapsed |
( |
| ) |
const |
|
inlinenodiscardnoexcept |
◆ last_sample_ticks()
double time_shield::CpuTickTimer::last_sample_ticks |
( |
| ) |
const |
|
inlinenodiscardnoexcept |
Get ticks collected during the last recorded sample.
- Returns
- Ticks from the most recent sample in CPU tick units.
Definition at line 114 of file CpuTickTimer.hpp.
◆ record_sample()
double time_shield::CpuTickTimer::record_sample |
( |
| ) |
|
|
inlinenoexcept |
Record sample using elapsed ticks and restart timer.
- Returns
- Collected sample value in CPU tick units or 0.0 when the timer was not previously running.
Definition at line 66 of file CpuTickTimer.hpp.
◆ reset_samples()
void time_shield::CpuTickTimer::reset_samples |
( |
| ) |
|
|
inlinenoexcept |
Reset collected samples without touching running state.
Definition at line 84 of file CpuTickTimer.hpp.
◆ restart()
void time_shield::CpuTickTimer::restart |
( |
| ) |
|
|
inlinenoexcept |
Restart timer and reset collected statistics.
Definition at line 43 of file CpuTickTimer.hpp.
◆ sample_count()
std::size_t time_shield::CpuTickTimer::sample_count |
( |
| ) |
const |
|
inlinenodiscardnoexcept |
Get the number of recorded samples.
- Returns
- Count of recorded samples.
Definition at line 93 of file CpuTickTimer.hpp.
◆ start()
void time_shield::CpuTickTimer::start |
( |
| ) |
|
|
inlinenoexcept |
◆ stop()
void time_shield::CpuTickTimer::stop |
( |
| ) |
|
|
inlinenoexcept |
Stop measuring CPU time and freeze elapsed ticks.
Definition at line 49 of file CpuTickTimer.hpp.
◆ total_ticks()
double time_shield::CpuTickTimer::total_ticks |
( |
| ) |
const |
|
inlinenodiscardnoexcept |
Get total recorded CPU ticks across samples.
- Returns
- Sum of recorded CPU tick units.
Definition at line 99 of file CpuTickTimer.hpp.
◆ m_end_ticks
double time_shield::CpuTickTimer::m_end_ticks { 0.0 } |
|
private |
◆ m_is_running
bool time_shield::CpuTickTimer::m_is_running { false } |
|
private |
◆ m_last_sample_ticks
double time_shield::CpuTickTimer::m_last_sample_ticks { 0.0 } |
|
private |
◆ m_sample_count
std::size_t time_shield::CpuTickTimer::m_sample_count { 0 } |
|
private |
◆ m_start_ticks
double time_shield::CpuTickTimer::m_start_ticks { 0.0 } |
|
private |
◆ m_total_compensation
double time_shield::CpuTickTimer::m_total_compensation { 0.0 } |
|
private |
◆ m_total_ticks
double time_shield::CpuTickTimer::m_total_ticks { 0.0 } |
|
private |
The documentation for this class was generated from the following file: