Doxygen
Loading...
Searching...
No Matches
SysTimeKeeper Class Reference

Classes

struct  TimeData

Public Member Functions

void start ()
 start a timer for this thread
void stop ()
 ends a timer for this thread, accumulate time difference since start
double elapsedTime () const

Static Public Member Functions

static SysTimeKeeperinstance ()

Private Attributes

std::map< std::thread::id, std::chrono::steady_clock::time_point > m_startTimes
double m_elapsedTime = 0
std::mutex m_mutex

Detailed Description

Helper class to keep time interval per thread

Definition at line 61 of file portable.cpp.

Member Function Documentation

◆ elapsedTime()

double SysTimeKeeper::elapsedTime ( ) const
inline

Definition at line 88 of file portable.cpp.

88{ return m_elapsedTime; }
double m_elapsedTime
Definition portable.cpp:96

References m_elapsedTime.

Referenced by Portable::getSysElapsedTime().

◆ instance()

SysTimeKeeper & SysTimeKeeper::instance ( )
static

Definition at line 100 of file portable.cpp.

101{
102 static SysTimeKeeper theInstance;
103 return theInstance;
104}

Referenced by AutoTimeKeeper::AutoTimeKeeper(), Portable::getSysElapsedTime(), and AutoTimeKeeper::~AutoTimeKeeper().

◆ start()

void SysTimeKeeper::start ( )
inline

start a timer for this thread

Definition at line 66 of file portable.cpp.

67 {
68 std::lock_guard<std::mutex> lock(m_mutex);
69 m_startTimes[std::this_thread::get_id()] = std::chrono::steady_clock::now();
70 }
std::mutex m_mutex
Definition portable.cpp:97
std::map< std::thread::id, std::chrono::steady_clock::time_point > m_startTimes
Definition portable.cpp:95

References m_mutex, and m_startTimes.

Referenced by AutoTimeKeeper::AutoTimeKeeper().

◆ stop()

void SysTimeKeeper::stop ( )
inline

ends a timer for this thread, accumulate time difference since start

Definition at line 72 of file portable.cpp.

73 {
74 std::lock_guard<std::mutex> lock(m_mutex);
75 std::chrono::steady_clock::time_point endTime = std::chrono::steady_clock::now();
76 auto it = m_startTimes.find(std::this_thread::get_id());
77 if (it == m_startTimes.end())
78 {
79 err("SysTimeKeeper stop() called without matching start()\n");
80 return;
81 }
82 double timeSpent = static_cast<double>(std::chrono::duration_cast<
83 std::chrono::microseconds>(endTime - it->second).count())/1000000.0;
84 //printf("timeSpent on thread %zu: %.4f seconds\n",std::hash<std::thread::id>{}(std::this_thread::get_id()),timeSpent);
85 m_elapsedTime += timeSpent;
86 }
#define err(fmt,...)
Definition message.h:127

References err, m_elapsedTime, m_mutex, and m_startTimes.

Referenced by AutoTimeKeeper::~AutoTimeKeeper().

Member Data Documentation

◆ m_elapsedTime

double SysTimeKeeper::m_elapsedTime = 0
private

Definition at line 96 of file portable.cpp.

Referenced by elapsedTime(), and stop().

◆ m_mutex

std::mutex SysTimeKeeper::m_mutex
private

Definition at line 97 of file portable.cpp.

Referenced by start(), and stop().

◆ m_startTimes

std::map<std::thread::id,std::chrono::steady_clock::time_point> SysTimeKeeper::m_startTimes
private

Definition at line 95 of file portable.cpp.

Referenced by start(), and stop().


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