Skip to main content

The SysTimeKeeper Class Reference

Declaration

class SysTimeKeeper { ... }

Public Member Functions Index

voidstart ()

start a timer for this thread More...

voidstop ()

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

doubleelapsedTime () const

Private Member Attributes Index

std::map< std::thread::id, std::chrono::steady_clock::time_point >m_startTimes
doublem_elapsedTime = 0
std::mutexm_mutex

Public Static Functions Index

static SysTimeKeeper &instance ()

Description

Helper class to keep time interval per thread

Definition at line 46 of file portable.cpp.

Public Member Functions

elapsedTime()

double SysTimeKeeper::elapsedTime ()
inline

Definition at line 73 of file portable.cpp.

73 double elapsedTime() const { return m_elapsedTime; }

Reference m_elapsedTime.

Referenced by Portable::getSysElapsedTime.

start()

void SysTimeKeeper::start ()
inline

start a timer for this thread

Definition at line 51 of file portable.cpp.

51 void start()
52 {
53 std::lock_guard<std::mutex> lock(m_mutex);
54 m_startTimes[std::this_thread::get_id()] = std::chrono::steady_clock::now();
55 }

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.

57 void stop()
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 }

References err, m_elapsedTime, m_mutex and m_startTimes.

Referenced by AutoTimeKeeper::~AutoTimeKeeper.

Private Member Attributes

m_elapsedTime

double SysTimeKeeper::m_elapsedTime = 0

Definition at line 81 of file portable.cpp.

81 double m_elapsedTime = 0;

Referenced by elapsedTime and stop.

m_mutex

std::mutex SysTimeKeeper::m_mutex

Definition at line 82 of file portable.cpp.

82 std::mutex m_mutex;

Referenced by start and stop.

m_startTimes

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

Definition at line 80 of file portable.cpp.

80 std::map<std::thread::id,std::chrono::steady_clock::time_point> m_startTimes;

Referenced by start and stop.

Public Static Functions

instance()

SysTimeKeeper & SysTimeKeeper::instance ()
static

Definition at line 49 of file portable.cpp.

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

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


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


Generated via doxygen2docusaurus by Doxygen 1.14.0.