dodo
0.0.1
A C++ library to create containerized Linux services
|
Abstract Thread class. More...
#include <thread.hpp>
Public Member Functions | |
Thread () | |
Constructor. More... | |
virtual | ~Thread () |
Destructor. More... | |
double | getAvgBlkInRate () |
Get the average block in rate since thread start() More... | |
double | getAvgBlkOutRate () |
Get the average block out rate since thread start() More... | |
double | getAvgICtx () |
Get the average involuntary context switch rate since thread start() More... | |
double | getAvgMajFltRate () |
Get the average major fault rate since thread start() More... | |
double | getAvgMinFltRate () |
Get the average minor fault rate since thread start() More... | |
double | getAvgSysCPU () |
Get the average system mode cpu (cpu seconds/second) since thread start() More... | |
double | getAvgUserCPU () |
Get the average user mode cpu (cpu seconds/second) since thread start() More... | |
double | getAvgVCtx () |
Get the average voluntary context switch rate since thread start() More... | |
std::thread::id | getId () const |
Get the thread id. More... | |
double | getLastBlkInRate () |
Get last block in rate since last sample. More... | |
double | getLastBlkOutRate () |
Get last block out rate since last sample. More... | |
double | getLastICtx () |
Get involuntary context switch rate since last sample. More... | |
double | getLastMajFltRate () |
Get the major fault rate since last sample. More... | |
double | getLastMinFltRate () |
Get the minor fault rate since last sample. More... | |
double | getLastSysCPU () |
Get the system mode cpu (cpu seconds/second) since last sample. More... | |
double | getLastUserCPU () |
Get the user mode cpu (cpu seconds/second) since last sample. More... | |
double | getLastVCtx () |
Get voluntary context switch rate since last sample. More... | |
long | getMaxRSS () |
Get the maximum resident set size seen on the thread. More... | |
double | getRunTime () |
Time, in seconds, since thread start. More... | |
double | getSnapDiffTime () |
Time, in seconds, since last statistic update. More... | |
pid_t | getTID () const |
Return the tid. More... | |
void | snapRUsage () |
Take a snapshot of the thread's resource usage. More... | |
void | start () |
Start the thread. More... | |
void | wait () |
Wait for the thread to join the current thread / wait for the thread to finish. More... | |
Protected Member Functions | |
virtual void | run ()=0 |
Decsendants must override the run function. More... | |
Protected Attributes | |
struct rusage | prev_rusage_ |
Previous statistics. More... | |
struct timeval | prev_snap_time_ |
Time of previous statistics snapshot. More... | |
struct rusage | rusage_ |
Last statistics. More... | |
struct timeval | snap_time_ |
Time of last statistics snapshot. More... | |
struct timeval | start_time_ |
Time Thread started. More... | |
std::thread * | thread_ |
The std::tread object. More... | |
Static Private Member Functions | |
static void * | thread_method (void *context) |
Posix thread method - calls dodo::threads::Thread:::run(). More... | |
Private Attributes | |
pid_t | tid_ |
The linux tid. More... | |
Abstract Thread class.
Inherit and implement pure virtual run() to run threaded code.
Definition at line 38 of file thread.hpp.
dodo::threads::Thread::Thread | ( | ) |
Constructor.
Definition at line 45 of file thread.cpp.
References prev_rusage_, prev_snap_time_, rusage_, snap_time_, and start_time_.
|
virtual |
double dodo::threads::Thread::getAvgBlkInRate | ( | ) |
Get the average block in rate since thread start()
Definition at line 96 of file thread.cpp.
References getRunTime(), and rusage_.
double dodo::threads::Thread::getAvgBlkOutRate | ( | ) |
Get the average block out rate since thread start()
Definition at line 100 of file thread.cpp.
References getRunTime(), and rusage_.
double dodo::threads::Thread::getAvgICtx | ( | ) |
Get the average involuntary context switch rate since thread start()
Definition at line 108 of file thread.cpp.
References getRunTime(), and rusage_.
double dodo::threads::Thread::getAvgMajFltRate | ( | ) |
Get the average major fault rate since thread start()
Definition at line 92 of file thread.cpp.
References getRunTime(), and rusage_.
double dodo::threads::Thread::getAvgMinFltRate | ( | ) |
Get the average minor fault rate since thread start()
Definition at line 88 of file thread.cpp.
References getRunTime(), and rusage_.
double dodo::threads::Thread::getAvgSysCPU | ( | ) |
Get the average system mode cpu (cpu seconds/second) since thread start()
Definition at line 84 of file thread.cpp.
References getRunTime(), and rusage_.
double dodo::threads::Thread::getAvgUserCPU | ( | ) |
Get the average user mode cpu (cpu seconds/second) since thread start()
Definition at line 80 of file thread.cpp.
References getRunTime(), and rusage_.
double dodo::threads::Thread::getAvgVCtx | ( | ) |
Get the average voluntary context switch rate since thread start()
Definition at line 104 of file thread.cpp.
References getRunTime(), and rusage_.
std::thread::id dodo::threads::Thread::getId | ( | ) | const |
double dodo::threads::Thread::getLastBlkInRate | ( | ) |
Get last block in rate since last sample.
Definition at line 136 of file thread.cpp.
References getSnapDiffTime(), prev_rusage_, and rusage_.
Referenced by dodo::network::TCPListener::logStats().
double dodo::threads::Thread::getLastBlkOutRate | ( | ) |
Get last block out rate since last sample.
Definition at line 141 of file thread.cpp.
References getSnapDiffTime(), prev_rusage_, and rusage_.
Referenced by dodo::network::TCPListener::logStats().
double dodo::threads::Thread::getLastICtx | ( | ) |
Get involuntary context switch rate since last sample.
Definition at line 151 of file thread.cpp.
References getSnapDiffTime(), prev_rusage_, and rusage_.
Referenced by dodo::network::TCPListener::logStats().
double dodo::threads::Thread::getLastMajFltRate | ( | ) |
Get the major fault rate since last sample.
Definition at line 131 of file thread.cpp.
References getSnapDiffTime(), prev_rusage_, and rusage_.
Referenced by dodo::network::TCPListener::logStats().
double dodo::threads::Thread::getLastMinFltRate | ( | ) |
Get the minor fault rate since last sample.
Definition at line 126 of file thread.cpp.
References getSnapDiffTime(), prev_rusage_, and rusage_.
Referenced by dodo::network::TCPListener::logStats().
double dodo::threads::Thread::getLastSysCPU | ( | ) |
Get the system mode cpu (cpu seconds/second) since last sample.
Definition at line 121 of file thread.cpp.
References getSnapDiffTime(), prev_rusage_, and rusage_.
Referenced by dodo::network::TCPListener::logStats().
double dodo::threads::Thread::getLastUserCPU | ( | ) |
Get the user mode cpu (cpu seconds/second) since last sample.
Definition at line 116 of file thread.cpp.
References getSnapDiffTime(), prev_rusage_, and rusage_.
Referenced by dodo::network::TCPListener::logStats().
double dodo::threads::Thread::getLastVCtx | ( | ) |
Get voluntary context switch rate since last sample.
Definition at line 146 of file thread.cpp.
References getSnapDiffTime(), prev_rusage_, and rusage_.
Referenced by dodo::network::TCPListener::logStats().
long dodo::threads::Thread::getMaxRSS | ( | ) |
Get the maximum resident set size seen on the thread.
Definition at line 112 of file thread.cpp.
References rusage_.
Referenced by dodo::network::TCPListener::logStats().
double dodo::threads::Thread::getRunTime | ( | ) |
Time, in seconds, since thread start.
Definition at line 156 of file thread.cpp.
References dodo::common::getSecondDiff(), snap_time_, and start_time_.
Referenced by getAvgBlkInRate(), getAvgBlkOutRate(), getAvgICtx(), getAvgMajFltRate(), getAvgMinFltRate(), getAvgSysCPU(), getAvgUserCPU(), and getAvgVCtx().
double dodo::threads::Thread::getSnapDiffTime | ( | ) |
Time, in seconds, since last statistic update.
Definition at line 160 of file thread.cpp.
References dodo::common::getSecondDiff(), prev_snap_time_, and snap_time_.
Referenced by getLastBlkInRate(), getLastBlkOutRate(), getLastICtx(), getLastMajFltRate(), getLastMinFltRate(), getLastSysCPU(), getLastUserCPU(), and getLastVCtx().
|
inline |
Return the tid.
Definition at line 190 of file thread.hpp.
References tid_.
Referenced by dodo::network::TCPListener::cleanStoppedServers().
|
protectedpure virtual |
Decsendants must override the run function.
Implemented in dodo::network::TCPListener, dodo::network::TCPServer, and dodo::network::TCPListenerTimer.
Referenced by thread_method().
void dodo::threads::Thread::snapRUsage | ( | ) |
Take a snapshot of the thread's resource usage.
Definition at line 68 of file thread.cpp.
References prev_rusage_, prev_snap_time_, rusage_, and snap_time_.
Referenced by dodo::network::TCPListener::logStats(), dodo::network::TCPServer::run(), and thread_method().
void dodo::threads::Thread::start | ( | ) |
Start the thread.
Definition at line 58 of file thread.cpp.
References thread_, and thread_method().
Referenced by dodo::network::TCPListener::addServers(), dodo::network::TCPListener::cleanStoppedServers(), and dodo::network::TCPListener::run().
|
staticprivate |
Posix thread method - calls dodo::threads::Thread:::run().
context | Is used to pass a Thread* so that its run() method can be called. |
Definition at line 33 of file thread.cpp.
References run(), snapRUsage(), start_time_, and tid_.
Referenced by start().
void dodo::threads::Thread::wait | ( | ) |
Wait for the thread to join the current thread / wait for the thread to finish.
Definition at line 64 of file thread.cpp.
References thread_.
Referenced by dodo::network::TCPListener::cleanStoppedServers().
|
protected |
Previous statistics.
Definition at line 222 of file thread.hpp.
Referenced by getLastBlkInRate(), getLastBlkOutRate(), getLastICtx(), getLastMajFltRate(), getLastMinFltRate(), getLastSysCPU(), getLastUserCPU(), getLastVCtx(), snapRUsage(), and Thread().
|
protected |
Time of previous statistics snapshot.
Definition at line 212 of file thread.hpp.
Referenced by getSnapDiffTime(), snapRUsage(), and Thread().
|
protected |
Last statistics.
Definition at line 227 of file thread.hpp.
Referenced by getAvgBlkInRate(), getAvgBlkOutRate(), getAvgICtx(), getAvgMajFltRate(), getAvgMinFltRate(), getAvgSysCPU(), getAvgUserCPU(), getAvgVCtx(), getLastBlkInRate(), getLastBlkOutRate(), getLastICtx(), getLastMajFltRate(), getLastMinFltRate(), getLastSysCPU(), getLastUserCPU(), getLastVCtx(), getMaxRSS(), snapRUsage(), and Thread().
|
protected |
Time of last statistics snapshot.
Definition at line 217 of file thread.hpp.
Referenced by getRunTime(), getSnapDiffTime(), snapRUsage(), and Thread().
|
protected |
Time Thread started.
Definition at line 207 of file thread.hpp.
Referenced by getRunTime(), Thread(), and thread_method().
|
protected |
|
private |
The linux tid.
Definition at line 241 of file thread.hpp.
Referenced by getTID(), and thread_method().