Image Component Library (ICL)
|
The ProcessMonitor class grants access to processes memory and CPU usage. More...
#include <ProcessMonitor.h>
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 ProcessMonitor * | getInstance () |
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... | |
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.
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
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.
typedef Function<void,const Info&> icl::utils::ProcessMonitor::Callback |
callback function/functor type
|
protected |
Create a new instance.
icl::utils::ProcessMonitor::~ProcessMonitor | ( | ) |
Destructor.
Info icl::utils::ProcessMonitor::getInfo | ( | ) | const |
synchronized access to last queried data
|
static |
returns the singelton instance
int icl::utils::ProcessMonitor::registerCallback | ( | Callback | cb | ) |
registers a callback instance that is automatically called when new data is available
returns a callback ID
void icl::utils::ProcessMonitor::removeAllCallbacks | ( | ) |
removes all registered callbacks
void icl::utils::ProcessMonitor::removeCallback | ( | int | id | ) |
removes a callback registered before
|
virtual |
implements the Thread::run method
Implements icl::utils::Thread.
|
private |
internal data pointer