Image Component Library (ICL)
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Attributes | List of all members
icl::utils::ProcessMonitor Class Reference

The ProcessMonitor class grants access to processes memory and CPU usage. More...

#include <ProcessMonitor.h>

Inheritance diagram for icl::utils::ProcessMonitor:
icl::utils::Thread icl::utils::Uncopyable icl::utils::ShallowCopyable< ThreadImpl, ThreadImplDelOp >

Classes

struct  Info
 Utility struct, that is used to pass available information at once. More...
 

Public Types

typedef Function< void, const Info & > Callback
 callback function/functor type More...
 

Public Member Functions

 ~ProcessMonitor ()
 Destructor. More...
 
virtual void run ()
 implements the Thread::run method More...
 
Info getInfo () const
 synchronized access to last queried data More...
 
int registerCallback (Callback cb)
 registers a callback instance that is automatically called when new data is available More...
 
void removeCallback (int id)
 removes a callback registered before More...
 
void removeAllCallbacks ()
 removes all registered callbacks More...
 

Static Public Member Functions

static ProcessMonitorgetInstance ()
 returns the singelton instance More...
 

Protected Member Functions

 ProcessMonitor ()
 Create a new instance. More...
 
- Protected Member Functions inherited from icl::utils::Thread
void exit ()
 exits the thread using pthread_exit (must be called from within the run function) More...
 
void lock ()
 internal used lock function More...
 
int trylock ()
 internal used trylock function More...
 
void unlock ()
 internal used unlock function More...
 
void join ()
 internal used join function More...
 
 Thread ()
 Create a new Thread. More...
 
virtual ~Thread ()
 Destructor (if the thread is still running, it is ended) More...
 
void start ()
 starts the thread More...
 
virtual void stop ()
 stops the thread and waits till it is ended More...
 
void wait ()
 waits for this thread to be ended More...
 
virtual void finalize ()
 at the end of the stop function, this function is called More...
 
bool running () const
 returns the internal running state More...
 
bool runningNoLock () const
 returns the running state of the thread (without locking the mutex) More...
 
- Protected Member Functions inherited from icl::utils::ShallowCopyable< ThreadImpl, ThreadImplDelOp >
 ShallowCopyable (ThreadImpl *t=0)
 create a the implementation with a given T* value More...
 
bool isNull () const
 returns wheter the objects implementation holds a null pointer More...
 
- Protected Member Functions inherited from icl::utils::Uncopyable
 Uncopyable ()
 Empty base constructor. More...
 

Private Attributes

Data * m_data
 internal data pointer More...
 

Additional Inherited Members

- Protected Types inherited from icl::utils::ShallowCopyable< ThreadImpl, ThreadImplDelOp >
typedef ShallowCopyable< ThreadImpl, ThreadImplDelOp > ParentSC
 
- Static Protected Member Functions inherited from icl::utils::Thread
static void usleep (unsigned int usec)
 just calling usleep More...
 
static void msleep (unsigned int msecs)
 sets the current thread to sleep for some milli-seconds More...
 
static void sleep (float secs)
 sets the current thread to sleep for some seconds More...
 
- Protected Attributes inherited from icl::utils::ShallowCopyable< ThreadImpl, ThreadImplDelOp >
SmartPtrBase< ThreadImpl, ThreadImplDelOp > impl
 shared pointer for the classes implementation More...
 

Detailed Description

The ProcessMonitor class grants access to processes memory and CPU usage.

Since querying process specific information is not standardized in C++, Only a Linux solution is provided yet.

Source of the Information

The pid is obtained via getpid() numThreads and memoryUsage is obtained by parsing /proc/self/stats memoryUsage is obtained by reading a piped 'ps' processes output since querying information an in particular waiting for 'ps' output takes some time, all the information is collected in a dedicated thread. numCPUs is queried once at construction time by parsing /proc/processor allCPU usage is also queried by parsing the piped 'ps' output

Callbacks

Since sometimes, an application wants to do something, when new information is available, a callback mechanism is provided as well. Simply register an icl::Function instance that is then called whenever a new set of data is available.

Member Typedef Documentation

◆ Callback

callback function/functor type

Constructor & Destructor Documentation

◆ ProcessMonitor()

icl::utils::ProcessMonitor::ProcessMonitor ( )
protected

Create a new instance.

◆ ~ProcessMonitor()

icl::utils::ProcessMonitor::~ProcessMonitor ( )

Destructor.

Member Function Documentation

◆ getInfo()

Info icl::utils::ProcessMonitor::getInfo ( ) const

synchronized access to last queried data

◆ getInstance()

static ProcessMonitor* icl::utils::ProcessMonitor::getInstance ( )
static

returns the singelton instance

◆ registerCallback()

int icl::utils::ProcessMonitor::registerCallback ( Callback  cb)

registers a callback instance that is automatically called when new data is available

returns a callback ID

◆ removeAllCallbacks()

void icl::utils::ProcessMonitor::removeAllCallbacks ( )

removes all registered callbacks

◆ removeCallback()

void icl::utils::ProcessMonitor::removeCallback ( int  id)

removes a callback registered before

◆ run()

virtual void icl::utils::ProcessMonitor::run ( )
virtual

implements the Thread::run method

Implements icl::utils::Thread.

Member Data Documentation

◆ m_data

Data* icl::utils::ProcessMonitor::m_data
private

internal data pointer


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