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 | |
Public Member Functions | |
~ProcessMonitor () | |
Destructor. | |
virtual void | run () |
implements the Thread::run method | |
Info | getInfo () const |
synchronized access to last queried data | |
int | registerCallback (Callback cb) |
registers a callback instance that is automatically called when new data is available | |
void | removeCallback (int id) |
removes a callback registered before | |
void | removeAllCallbacks () |
removes all registered callbacks | |
Static Public Member Functions | |
static ProcessMonitor * | getInstance () |
returns the singelton instance | |
Protected Member Functions | |
ProcessMonitor () | |
Create a new instance. | |
Private Attributes | |
Data * | m_data |
internal data pointer |
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
icl::utils::ProcessMonitor::ProcessMonitor | ( | ) | [protected] |
Create a new instance.
Destructor.
Info icl::utils::ProcessMonitor::getInfo | ( | ) | const |
synchronized access to last queried data
static ProcessMonitor* icl::utils::ProcessMonitor::getInstance | ( | ) | [static] |
returns the singelton instance
registers a callback instance that is automatically called when new data is available
returns a callback ID
removes all registered callbacks
void icl::utils::ProcessMonitor::removeCallback | ( | int | id | ) |
removes a callback registered before
virtual void icl::utils::ProcessMonitor::run | ( | ) | [virtual] |
implements the Thread::run method
Implements icl::utils::Thread.
Data* icl::utils::ProcessMonitor::m_data [private] |
internal data pointer