Image Component Library (ICL)
ProcessMonitor.h
Go to the documentation of this file.
1 /********************************************************************
2 ** Image Component Library (ICL) **
3 ** **
4 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld **
5 ** Neuroinformatics Group **
6 ** Website: www.iclcv.org and **
7 ** http://opensource.cit-ec.de/projects/icl **
8 ** **
9 ** File : ICLUtils/src/ICLUtils/ProcessMonitor.h **
10 ** Module : ICLUtils **
11 ** Authors: Christof Elbrechter **
12 ** **
13 ** **
14 ** GNU LESSER GENERAL PUBLIC LICENSE **
15 ** This file may be used under the terms of the GNU Lesser General **
16 ** Public License version 3.0 as published by the **
17 ** **
18 ** Free Software Foundation and appearing in the file LICENSE.LGPL **
19 ** included in the packaging of this file. Please review the **
20 ** following information to ensure the license requirements will **
21 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt **
22 ** **
23 ** The development of this software was supported by the **
24 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. **
25 ** The Excellence Cluster EXC 277 is a grant of the Deutsche **
26 ** Forschungsgemeinschaft (DFG) in the context of the German **
27 ** Excellence Initiative. **
28 ** **
29 ********************************************************************/
30 
31 #pragma once
32 
33 #include <ICLUtils/CompatMacros.h>
34 #include <ICLUtils/Thread.h>
35 #include <ICLUtils/Mutex.h>
36 #include <ICLUtils/Uncopyable.h>
37 #include <ICLUtils/Function.h>
38 #include <iostream>
39 
40 namespace icl{
41  namespace utils{
42 
44 
64  class ICLUtils_API ProcessMonitor : protected Thread, public Uncopyable{
66  struct Data;
67 
69  Data *m_data;
70 
71  public:
72 
74  struct Info{
75  int pid; // current process ID
76  int numThreads; // number of threads of the current process
77  float cpuUsage; // percent 0-numCPUs*100
78  float allCpuUsage; // percent 0-100
79  float memoryUsage; // used memory in MB
80  int numCPUs; // sometimes, this helps for visualization
81  };
82 
83  protected:
86 
87  public:
88 
90  static ProcessMonitor *getInstance();
91 
93  ~ProcessMonitor();
94 
96  virtual void run();
97 
99  Info getInfo() const;
100 
103 
105 
106  int registerCallback(Callback cb);
107 
109  void removeCallback(int id);
110 
112  void removeAllCallbacks();
113  };
114 
116  ICLUtils_API std::ostream &operator<<(std::ostream &s, const ProcessMonitor::Info &info);
117  } // namespace utils
118 }
119 
120 
The General Function Template.
Definition: Function.h:284
float allCpuUsage
Definition: ProcessMonitor.h:78
undocument this line if you encounter any issues!
Definition: Any.h:37
Class interface for un-copyable classes.
Definition: Uncopyable.h:64
Simple object oriented thread class wrapping the pthread library.
Definition: Thread.h:90
#define ICLUtils_API
this macros are important for creating dll's
Definition: CompatMacros.h:171
Data * m_data
internal data pointer
Definition: ProcessMonitor.h:66
float memoryUsage
Definition: ProcessMonitor.h:79
int numCPUs
Definition: ProcessMonitor.h:80
int numThreads
Definition: ProcessMonitor.h:76
Function< void, const Info & > Callback
callback function/functor type
Definition: ProcessMonitor.h:102
float cpuUsage
Definition: ProcessMonitor.h:77
ICLUtils_API std::ostream & operator<<(std::ostream &s, const ConfigFile &cf)
Default ostream operator to put a ConfigFile into a stream.
The ProcessMonitor class grants access to processes memory and CPU usage.
Definition: ProcessMonitor.h:64
int pid
Definition: ProcessMonitor.h:75
Utility struct, that is used to pass available information at once.
Definition: ProcessMonitor.h:74