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 45 of file portable.cpp.

Member Function Documentation

◆ elapsedTime()

double SysTimeKeeper::elapsedTime ( ) const
inline

Definition at line 72 of file portable.cpp.

72{ return m_elapsedTime; }
double m_elapsedTime
Definition portable.cpp:80

References m_elapsedTime.

Referenced by Portable::getSysElapsedTime().

◆ instance()

SysTimeKeeper & SysTimeKeeper::instance ( )
static

Definition at line 84 of file portable.cpp.

85{
86 static SysTimeKeeper theInstance;
87 return theInstance;
88}

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

◆ start()

void SysTimeKeeper::start ( )
inline

start a timer for this thread

Definition at line 50 of file portable.cpp.

51 {
52 std::lock_guard<std::mutex> lock(m_mutex);
53 m_startTimes[std::this_thread::get_id()] = std::chrono::steady_clock::now();
54 }
std::mutex m_mutex
Definition portable.cpp:81
std::map< std::thread::id, std::chrono::steady_clock::time_point > m_startTimes
Definition portable.cpp:79

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 56 of file portable.cpp.

57 {
58 std::lock_guard<std::mutex> lock(m_mutex);
59 std::chrono::steady_clock::time_point endTime = std::chrono::steady_clock::now();
60 auto it = m_startTimes.find(std::this_thread::get_id());
61 if (it == m_startTimes.end())
62 {
63 err("SysTimeKeeper stop() called without matching start()\n");
64 return;
65 }
66 double timeSpent = static_cast<double>(std::chrono::duration_cast<
67 std::chrono::microseconds>(endTime - it->second).count())/1000000.0;
68 //printf("timeSpent on thread %zu: %.4f seconds\n",std::hash<std::thread::id>{}(std::this_thread::get_id()),timeSpent);
69 m_elapsedTime += timeSpent;
70 }
#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 80 of file portable.cpp.

Referenced by elapsedTime(), and stop().

◆ m_mutex

std::mutex SysTimeKeeper::m_mutex
private

Definition at line 81 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 79 of file portable.cpp.

Referenced by start(), and stop().


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