dodo  0.0.1
A C++ library to create containerized Linux services
dodo::threads::Thread Class Referenceabstract

Abstract Thread class. More...

#include <thread.hpp>

Inheritance diagram for dodo::threads::Thread:
Collaboration diagram for dodo::threads::Thread:

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...
 

Detailed Description

Abstract Thread class.

Inherit and implement pure virtual run() to run threaded code.

Definition at line 38 of file thread.hpp.

Constructor & Destructor Documentation

◆ Thread()

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_.

◆ ~Thread()

dodo::threads::Thread::~Thread ( )
virtual

Destructor.

Definition at line 54 of file thread.cpp.

References thread_.

Member Function Documentation

◆ getAvgBlkInRate()

double dodo::threads::Thread::getAvgBlkInRate ( )

Get the average block in rate since thread start()

Returns
that rate.

Definition at line 96 of file thread.cpp.

References getRunTime(), and rusage_.

Here is the call graph for this function:

◆ getAvgBlkOutRate()

double dodo::threads::Thread::getAvgBlkOutRate ( )

Get the average block out rate since thread start()

Returns
that rate.

Definition at line 100 of file thread.cpp.

References getRunTime(), and rusage_.

Here is the call graph for this function:

◆ getAvgICtx()

double dodo::threads::Thread::getAvgICtx ( )

Get the average involuntary context switch rate since thread start()

Returns
that rate.

Definition at line 108 of file thread.cpp.

References getRunTime(), and rusage_.

Here is the call graph for this function:

◆ getAvgMajFltRate()

double dodo::threads::Thread::getAvgMajFltRate ( )

Get the average major fault rate since thread start()

Returns
that rate.

Definition at line 92 of file thread.cpp.

References getRunTime(), and rusage_.

Here is the call graph for this function:

◆ getAvgMinFltRate()

double dodo::threads::Thread::getAvgMinFltRate ( )

Get the average minor fault rate since thread start()

Returns
that rate.

Definition at line 88 of file thread.cpp.

References getRunTime(), and rusage_.

Here is the call graph for this function:

◆ getAvgSysCPU()

double dodo::threads::Thread::getAvgSysCPU ( )

Get the average system mode cpu (cpu seconds/second) since thread start()

Returns
that utilization.

Definition at line 84 of file thread.cpp.

References getRunTime(), and rusage_.

Here is the call graph for this function:

◆ getAvgUserCPU()

double dodo::threads::Thread::getAvgUserCPU ( )

Get the average user mode cpu (cpu seconds/second) since thread start()

Returns
that utilization.

Definition at line 80 of file thread.cpp.

References getRunTime(), and rusage_.

Here is the call graph for this function:

◆ getAvgVCtx()

double dodo::threads::Thread::getAvgVCtx ( )

Get the average voluntary context switch rate since thread start()

Returns
that rate.

Definition at line 104 of file thread.cpp.

References getRunTime(), and rusage_.

Here is the call graph for this function:

◆ getId()

std::thread::id dodo::threads::Thread::getId ( ) const

Get the thread id.

Returns
that id.

Definition at line 75 of file thread.cpp.

References thread_.

◆ getLastBlkInRate()

double dodo::threads::Thread::getLastBlkInRate ( )

Get last block in rate since last sample.

Returns
that rate.

Definition at line 136 of file thread.cpp.

References getSnapDiffTime(), prev_rusage_, and rusage_.

Referenced by dodo::network::TCPListener::logStats().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getLastBlkOutRate()

double dodo::threads::Thread::getLastBlkOutRate ( )

Get last block out rate since last sample.

Returns
that rate.

Definition at line 141 of file thread.cpp.

References getSnapDiffTime(), prev_rusage_, and rusage_.

Referenced by dodo::network::TCPListener::logStats().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getLastICtx()

double dodo::threads::Thread::getLastICtx ( )

Get involuntary context switch rate since last sample.

Returns
that rate.

Definition at line 151 of file thread.cpp.

References getSnapDiffTime(), prev_rusage_, and rusage_.

Referenced by dodo::network::TCPListener::logStats().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getLastMajFltRate()

double dodo::threads::Thread::getLastMajFltRate ( )

Get the major fault rate since last sample.

Returns
that rate.

Definition at line 131 of file thread.cpp.

References getSnapDiffTime(), prev_rusage_, and rusage_.

Referenced by dodo::network::TCPListener::logStats().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getLastMinFltRate()

double dodo::threads::Thread::getLastMinFltRate ( )

Get the minor fault rate since last sample.

Returns
that rate.

Definition at line 126 of file thread.cpp.

References getSnapDiffTime(), prev_rusage_, and rusage_.

Referenced by dodo::network::TCPListener::logStats().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getLastSysCPU()

double dodo::threads::Thread::getLastSysCPU ( )

Get the system mode cpu (cpu seconds/second) since last sample.

Returns
that utilization.

Definition at line 121 of file thread.cpp.

References getSnapDiffTime(), prev_rusage_, and rusage_.

Referenced by dodo::network::TCPListener::logStats().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getLastUserCPU()

double dodo::threads::Thread::getLastUserCPU ( )

Get the user mode cpu (cpu seconds/second) since last sample.

Returns
that utilization.

Definition at line 116 of file thread.cpp.

References getSnapDiffTime(), prev_rusage_, and rusage_.

Referenced by dodo::network::TCPListener::logStats().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getLastVCtx()

double dodo::threads::Thread::getLastVCtx ( )

Get voluntary context switch rate since last sample.

Returns
that rate.

Definition at line 146 of file thread.cpp.

References getSnapDiffTime(), prev_rusage_, and rusage_.

Referenced by dodo::network::TCPListener::logStats().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getMaxRSS()

long dodo::threads::Thread::getMaxRSS ( )

Get the maximum resident set size seen on the thread.

Returns
that size.

Definition at line 112 of file thread.cpp.

References rusage_.

Referenced by dodo::network::TCPListener::logStats().

Here is the caller graph for this function:

◆ getRunTime()

double dodo::threads::Thread::getRunTime ( )

Time, in seconds, since thread start.

Returns
that time.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getSnapDiffTime()

double dodo::threads::Thread::getSnapDiffTime ( )

Time, in seconds, since last statistic update.

Returns
that time.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getTID()

pid_t dodo::threads::Thread::getTID ( ) const
inline

Return the tid.

Returns
the TID.

Definition at line 190 of file thread.hpp.

References tid_.

Referenced by dodo::network::TCPListener::cleanStoppedServers().

Here is the caller graph for this function:

◆ run()

virtual void dodo::threads::Thread::run ( )
protectedpure virtual

Decsendants must override the run function.

Implemented in dodo::network::TCPListener, dodo::network::TCPServer, and dodo::network::TCPListenerTimer.

Referenced by thread_method().

Here is the caller graph for this function:

◆ snapRUsage()

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().

Here is the caller graph for this function:

◆ start()

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ thread_method()

void * dodo::threads::Thread::thread_method ( void *  context)
staticprivate

Posix thread method - calls dodo::threads::Thread:::run().

Parameters
contextIs used to pass a Thread* so that its run() method can be called.
Returns
nullptr (always)

Definition at line 33 of file thread.cpp.

References run(), snapRUsage(), start_time_, and tid_.

Referenced by start().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ wait()

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().

Here is the caller graph for this function:

Field Documentation

◆ prev_rusage_

struct rusage dodo::threads::Thread::prev_rusage_
protected

◆ prev_snap_time_

struct timeval dodo::threads::Thread::prev_snap_time_
protected

Time of previous statistics snapshot.

Definition at line 212 of file thread.hpp.

Referenced by getSnapDiffTime(), snapRUsage(), and Thread().

◆ rusage_

◆ snap_time_

struct timeval dodo::threads::Thread::snap_time_
protected

Time of last statistics snapshot.

Definition at line 217 of file thread.hpp.

Referenced by getRunTime(), getSnapDiffTime(), snapRUsage(), and Thread().

◆ start_time_

struct timeval dodo::threads::Thread::start_time_
protected

Time Thread started.

Definition at line 207 of file thread.hpp.

Referenced by getRunTime(), Thread(), and thread_method().

◆ thread_

std::thread* dodo::threads::Thread::thread_
protected

The std::tread object.

Definition at line 202 of file thread.hpp.

Referenced by getId(), start(), wait(), and ~Thread().

◆ tid_

pid_t dodo::threads::Thread::tid_
private

The linux tid.

Definition at line 241 of file thread.hpp.

Referenced by getTID(), and thread_method().


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