SurgSim::Framework::Timer Class Reference

Timer class, measures execution times. More...

`#include <SurgSim/Framework/Timer.h>`

## Public Member Functions

| Timer ()
| Instantiate a TimerClock and start a timing run. More...
void | start ()
| Begin a timing run by clearing out any stored frames and beginning a frame. More...
void | beginFrame ()
| Begin a frame (storing the current time). More...
void | endFrame ()
| End this frame by storing the duration since the current frame was begun. More...
void | markFrame ()
| End the current frame and begin a new frame. More...
double | getCumulativeTime () const
| Return the sum of the durations over all the stored frames. More...
double | getAverageFramePeriod () const
| Return the average duration across all stored frames. More...
double | getAverageFrameRate () const
| Return the inverse of the average duration across all stored frames. More...
double | getLastFramePeriod () const
| Return the duration of the most-recent frame (time between last `endFrame` and the previous `start`, `beginFrame`, or `endFrame` ). More...
double | getLastFrameRate () const
| Return the inverse of the duration of the most-recent frame. More...
void | setMaxNumberOfFrames (size_t numberOfFrames)
| Set the maximum number of frames to store. More...
size_t | getMaxNumberOfFrames ()
size_t | getCurrentNumberOfFrames () const
size_t | getNumberOfClockFails () const
double | getMaxFramePeriod () const
double | getMinFramePeriod () const
bool | isBufferFull () const

## Private Types

typedef boost::chrono::steady_clock | TimerClock
| The Clock used by the Timer class. More...
typedef boost::chrono::duration< double > | TimerDuration
| Durations used by the Timer class. More...
typedef boost::chrono::time_point< TimerClock, TimerDuration > | TimerTimePoint
| Time points used by the Timer class. More...

## Private Member Functions

TimerTimePoint | now ()
| Get the current time. More...

## Private Attributes

TimerTimePoint | m_lastTime
| The time at last `start`, `beginFrame`, or `markFrame`. More...
size_t | m_maxNumberOfFrames
| Maximum number of frames to store. More...
std::deque< TimerDuration > | m_frameDurations
| Durations of the frames, i.e., the "stored frames". More...
boost::shared_mutex | m_sharedMutex
| Mutex to access the data structure m_frameDurations safely. More...
size_t | m_clockFails
| Number of clock errors since last `start`. More...

## Static Private Attributes

static const TimerClock | m_clock
| The clock used to get the time. More...

## Detailed Description

Timer class, measures execution times.

Multiple times can be stored as "frames" to provide an average rate or period.

## Member Typedef Documentation

## TimerClock

typedef boost::chrono::steady_clock SurgSim::Framework::Timer::TimerClock

private

The Clock used by the Timer class.

## TimerDuration

typedef boost::chrono::duration<double> SurgSim::Framework::Timer::TimerDuration

private

Durations used by the Timer class.

## TimerTimePoint

typedef boost::chrono::time_point<TimerClock, TimerDuration> SurgSim::Framework::Timer::TimerTimePoint

private

Time points used by the Timer class.

## Constructor & Destructor Documentation

## Timer()

SurgSim::Framework::Timer::Timer | ( |  | ) |

Instantiate a TimerClock and start a timing run.

## Member Function Documentation

## beginFrame()

void SurgSim::Framework::Timer::beginFrame | ( |  | ) |

Begin a frame (storing the current time).

## endFrame()

void SurgSim::Framework::Timer::endFrame | ( |  | ) |

End this frame by storing the duration since the current frame was begun.

Note
  `endFrame` does not start a new frame, call `beginFrame` to do so.

See also
  Timer::markFrame

## getAverageFramePeriod()

double SurgSim::Framework::Timer::getAverageFramePeriod | ( |  | ) | const

Return the average duration across all stored frames.

Asserts if there are no frames.

Returns
  Average period in seconds.

## getAverageFrameRate()

double SurgSim::Framework::Timer::getAverageFrameRate | ( |  | ) | const

Return the inverse of the average duration across all stored frames.

Asserts if there are no frames.

Returns
  The average frequency in Hz.

## getCumulativeTime()

double SurgSim::Framework::Timer::getCumulativeTime | ( |  | ) | const

Return the sum of the durations over all the stored frames.

Returns
  Sum of stored frame durations in seconds.

## getCurrentNumberOfFrames()

size_t SurgSim::Framework::Timer::getCurrentNumberOfFrames | ( |  | ) | const

Returns
  Number of frames currently stored (not the maximum number of frames).

## getLastFramePeriod()

double SurgSim::Framework::Timer::getLastFramePeriod | ( |  | ) | const

Return the duration of the most-recent frame (time between last `endFrame` and the previous `start`, `beginFrame`, or `endFrame` ).

Asserts if there are no frames.

Returns
  Most-recent period in seconds.

## getLastFrameRate()

double SurgSim::Framework::Timer::getLastFrameRate | ( |  | ) | const

Return the inverse of the duration of the most-recent frame.

Asserts if there are no frames.

Returns
  Most-recent frequency in Hz.

## getMaxFramePeriod()

double SurgSim::Framework::Timer::getMaxFramePeriod | ( |  | ) | const

Returns
  The maximum duration across all the stored frames. Asserts if there are no frames.

## getMaxNumberOfFrames()

size_t SurgSim::Framework::Timer::getMaxNumberOfFrames | ( |  | ) |

Returns
  The maximum number of frames to store.

## getMinFramePeriod()

double SurgSim::Framework::Timer::getMinFramePeriod | ( |  | ) | const

Returns
  The minimum duration across all the stored frames. Asserts if there are no frames.

## getNumberOfClockFails()

size_t SurgSim::Framework::Timer::getNumberOfClockFails | ( |  | ) | const

Returns
  Number of times the clock returned an error code since `start`. If this is non-zero, the frame durations may be incorrect.

## isBufferFull()

bool SurgSim::Framework::Timer::isBufferFull | ( |  | ) | const

Returns
  true if the frame buffer is full.

## markFrame()

void SurgSim::Framework::Timer::markFrame | ( |  | ) |

End the current frame and begin a new frame.

## now()

Timer::TimerTimePoint SurgSim::Framework::Timer::now | ( |  | ) |

private

Get the current time.

Checks for any error code from the clock.

Returns
  Current time.

## setMaxNumberOfFrames()

void SurgSim::Framework::Timer::setMaxNumberOfFrames | ( | size_t | numberOfFrames | ) |

Set the maximum number of frames to store.

## start()

void SurgSim::Framework::Timer::start | ( |  | ) |

Begin a timing run by clearing out any stored frames and beginning a frame.

## Member Data Documentation

## m_clock

const TimerClock SurgSim::Framework::Timer::m_clock

static private

The clock used to get the time.

## m_clockFails

size_t SurgSim::Framework::Timer::m_clockFails

private

Number of clock errors since last `start`.

## m_frameDurations

std::deque<TimerDuration> SurgSim::Framework::Timer::m_frameDurations

private

Durations of the frames, i.e., the "stored frames".

## m_lastTime

TimerTimePoint SurgSim::Framework::Timer::m_lastTime

private

The time at last `start`, `beginFrame`, or `markFrame`.

## m_maxNumberOfFrames

size_t SurgSim::Framework::Timer::m_maxNumberOfFrames

private

Maximum number of frames to store.

## m_sharedMutex

boost::shared_mutex SurgSim::Framework::Timer::m_sharedMutex

mutable private

Mutex to access the data structure m_frameDurations safely.

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

- SurgSim/Framework/Timer.h
- SurgSim/Framework/Timer.cpp