MIRA
Classes | Public Types | Static Public Member Functions | Static Protected Member Functions | List of all members
ThreadMonitor Class Reference

A thread monitor class. More...

#include <thread/ThreadMonitor.h>

Inheritance diagram for ThreadMonitor:
Inheritance graph
[legend]

Classes

struct  BasicThreadIdentity
 Serializable thread id. More...
 
struct  ThreadIdentity
 Extend basic thread id by boost thread id (not serializable). More...
 
struct  ThreadInfoBase
 Runtime thread info. More...
 
struct  ThreadInfoTempl
 Combine thread identity (template param) and runtime info. More...
 

Public Types

typedef Base::Type Type
 

Public Member Functions

Constructor and destructor
 ThreadMonitor ()
 Default constructor. More...
 
virtual ~ThreadMonitor ()
 The destructor. More...
 
Add and remove threads.
void addThisThread (const std::string &pName)
 Add the calling thread to the thread monitor. More...
 
void removeThisThread ()
 Remove the calling thread from the monitor. More...
 
void removeThread (const boost::thread &pThread)
 Remove a thread from the monitor. More...
 
void removeThread (const boost::thread::id &pThreadID)
 Remove a thread from the monitor. More...
 
void removeThread (ThreadID pThreadID)
 Remove a thread from the monitor. More...
 

Static Public Member Functions

static Typeinstance ()
 Returns a reference to the singleton instance. More...
 
static bool isDestroyed ()
 Returns true, if the singleton was already destroyed. More...
 

Static Protected Member Functions

static TypemakeInstance ()
 
static void destroyInstance (void)
 

Thread information

using BasicThreadInfo = ThreadInfoTempl< BasicThreadIdentity >
 Basic (serializable) thread info. More...
 
using BasicThreadInfoVector = std::vector< BasicThreadInfo >
 Vector of serializable thread info. More...
 
using ThreadInfo = ThreadInfoTempl< ThreadIdentity >
 Thread info including local thread id data. More...
 
using ThreadInfoVector = std::vector< ThreadInfo >
 Vector of local id thread data. More...
 
ThreadInfoVector getThreadInformation ()
 Collect information about all threads of the current process. More...
 
BasicThreadInfoVector getBasicThreadInformation ()
 Collect basic (serializable) information about all threads of the current process. More...
 

Detailed Description

A thread monitor class.

A thread monitor, which collects information about the resources of all running threads.

To add a new thread to the monitor, the method addThisThread must be called within the created thread. To remove a thread, the method removeThisThread or removeThread should be called. If a thread is stopped without calling removeThisThread first, it will be automatically removed from the internal thread list when getThreadInformation() is called.

The method getThreadInformation returns a vector of all threads of the current process (not only the threads which are added using addThisThread). For each thread, the creation time and the used CPU time in user mode and kernel mode are determined. For threads which were added using addThisThread, the registered name is included in the returned data.

The method getBasicThreadInformation can be used to query only the serializable subset of thread information (i.e. excluding some internal thread reference data).

Example:

void processThread()
{
ThreadMonitor::instance().addThisThread("MyThreadName");
while (!boost::this_thread::interruption_requested())
{
...
}
ThreadMonitor::instance().removeThisThread();
}
int main(int pArgc, char* pArgv[])
{
...
boost::thread tMyThread(boost::bind(&processThread));
...
ThreadMonitor::instance().getThreadInformation();
}

Member Typedef Documentation

◆ BasicThreadInfo

Basic (serializable) thread info.

◆ BasicThreadInfoVector

using BasicThreadInfoVector = std::vector<BasicThreadInfo>

Vector of serializable thread info.

◆ ThreadInfo

Thread info including local thread id data.

◆ ThreadInfoVector

using ThreadInfoVector = std::vector<ThreadInfo>

Vector of local id thread data.

◆ Type

typedef Base::Type Type
inherited

Constructor & Destructor Documentation

◆ ThreadMonitor()

Default constructor.

◆ ~ThreadMonitor()

virtual ~ThreadMonitor ( )
virtual

The destructor.

Member Function Documentation

◆ addThisThread()

void addThisThread ( const std::string &  pName)

Add the calling thread to the thread monitor.

Parameters
[in]pNameThe name of the thread.

◆ removeThisThread()

void removeThisThread ( )

Remove the calling thread from the monitor.

◆ removeThread() [1/3]

void removeThread ( const boost::thread &  pThread)

Remove a thread from the monitor.

Parameters
[in]pThreadThe thread, which should be removed.

◆ removeThread() [2/3]

void removeThread ( const boost::thread::id &  pThreadID)

Remove a thread from the monitor.

Parameters
[in]pThreadIDThe boost thread ID.

◆ removeThread() [3/3]

void removeThread ( ThreadID  pThreadID)

Remove a thread from the monitor.

Parameters
[in]pThreadIDThe native thread ID.

◆ getThreadInformation()

ThreadInfoVector getThreadInformation ( )

Collect information about all threads of the current process.

Returns
Vector of thread info

◆ getBasicThreadInformation()

BasicThreadInfoVector getBasicThreadInformation ( )

Collect basic (serializable) information about all threads of the current process.

Returns
Vector of basic thread info

◆ instance()

static Type& instance ( )
inlinestaticinherited

Returns a reference to the singleton instance.

Exceptions
XSingletonIf the singleton was already destroyed (dead reference) or not yet created (when using ExplicitInstantiation).

◆ isDestroyed()

static bool isDestroyed ( )
inlinestaticinherited

Returns true, if the singleton was already destroyed.

Trying to access it will result in an exception.

◆ makeInstance()

static Type* makeInstance ( )
inlinestaticprotectedinherited

◆ destroyInstance()

static void destroyInstance ( void  )
inlinestaticprotectedinherited

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