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

Member Function Documentation

◆ elapsedTime()

double SysTimeKeeper::elapsedTime ( ) const
inline

Definition at line 73 of file portable.cpp.

73{ return m_elapsedTime; }
double m_elapsedTime
Definition portable.cpp:81

References m_elapsedTime.

Referenced by Portable::getSysElapsedTime().

◆ instance()

SysTimeKeeper & SysTimeKeeper::instance ( )
static

Definition at line 85 of file portable.cpp.

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

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

◆ start()

void SysTimeKeeper::start ( )
inline

start a timer for this thread

Definition at line 51 of file portable.cpp.

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

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

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

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

Referenced by elapsedTime(), and stop().

◆ m_mutex

std::mutex SysTimeKeeper::m_mutex
private

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

Referenced by start(), and stop().


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