AGX Dynamics 2.40.1.3
Loading...
Searching...
No Matches
agx::Timer Class Reference

The Timer class permits timing execution speed with the same refinement as the built in hardware clock of the CPU. More...

#include <Timer.h>

Public Member Functions

 Timer (bool startImmediately=false)
 Creates a timer.
 
UInt64 getNumTicks () const
 Report execution time in CPU cycles.
 
UInt64 getStartTick () const
 
Real64 getTime () const
 Report total elapsed time since start in milliseconds, excluding intervals when the timer was suspended.
 
bool isRunning () const
 
void reset (bool startAfterReset=false)
 Clear all data.
 
void start ()
 Starts the timer.
 
void stop ()
 Stops the timer.
 

Static Public Member Functions

static Real64 convertToMs (UInt64 ticks)
 
static UInt64 getCurrentTick ()
 
static Real64 getTime (UInt64 startTick)
 
static void initClockSpeed ()
 For internal use only.
 

Detailed Description

The Timer class permits timing execution speed with the same refinement as the built in hardware clock of the CPU.

Profiling tools typically have sampling rates which are too coarse for detailed timing analysis. The Timer class uses the hardware clock to record beginning and end times of given code sections.

A Timer based upon std::chrono::high_resolution_clock is available in agx::HighAccuracyTimer. It has more overhead than agx::Timer, but can provide better accuracy in some cases e.g. virtualized environments where TSC-based measurements might not have full granularity.

Definition at line 61 of file Timer.h.

Constructor & Destructor Documentation

◆ Timer()

agx::Timer::Timer ( bool  startImmediately = false)
inline

Creates a timer.

Parameters
startImmediatelyShould the timer start immediately or start in stopped mode (now, but also after consequent calls to reset())?

Definition at line 132 of file Timer.h.

References reset(), and start().

Member Function Documentation

◆ convertToMs()

Real64 agx::Timer::convertToMs ( UInt64  ticks)
static
Returns
the given number of ticks in ms.

Definition at line 251 of file Timer.h.

Referenced by agxUtil::TimerBlock::create(), and getTime().

◆ getCurrentTick()

UInt64 agx::Timer::getCurrentTick ( )
static

◆ getNumTicks()

UInt64 agx::Timer::getNumTicks ( ) const

Report execution time in CPU cycles.

Definition at line 173 of file Timer.h.

◆ getStartTick()

UInt64 agx::Timer::getStartTick ( ) const
Returns
the start tick.

Definition at line 179 of file Timer.h.

◆ getTime() [1/2]

Real64 agx::Timer::getTime ( ) const

Report total elapsed time since start in milliseconds, excluding intervals when the timer was suspended.

Definition at line 191 of file Timer.h.

References getCurrentTick().

Referenced by agx::Job::getExecutionTime().

◆ getTime() [2/2]

Real64 agx::Timer::getTime ( UInt64  startTick)
static
Returns
time in ms relative to a start tick

Definition at line 246 of file Timer.h.

References convertToMs(), and getCurrentTick().

◆ initClockSpeed()

static void agx::Timer::initClockSpeed ( )
static

For internal use only.

◆ isRunning()

bool agx::Timer::isRunning ( ) const
Returns
true if running.

Definition at line 185 of file Timer.h.

◆ reset()

void agx::Timer::reset ( bool  startAfterReset = false)

Clear all data.

Definition at line 162 of file Timer.h.

References start().

Referenced by Timer().

◆ start()

void agx::Timer::start ( )

Starts the timer.

Calling start on a already started timer will have no effect.

Definition at line 140 of file Timer.h.

References getCurrentTick().

Referenced by Timer(), and reset().

◆ stop()

void agx::Timer::stop ( )

Stops the timer.

Calling stop on a already stopped timer will have no effect. Upon stopping, the amount of cycles and time ran will be updated.

Definition at line 151 of file Timer.h.

References getCurrentTick().


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