MIRA
ThreadMonitor.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 by
3  * MetraLabs GmbH (MLAB), GERMANY
4  * and
5  * Neuroinformatics and Cognitive Robotics Labs (NICR) at TU Ilmenau, GERMANY
6  * All rights reserved.
7  *
8  * Contact: info@mira-project.org
9  *
10  * Commercial Usage:
11  * Licensees holding valid commercial licenses may use this file in
12  * accordance with the commercial license agreement provided with the
13  * software or, alternatively, in accordance with the terms contained in
14  * a written agreement between you and MLAB or NICR.
15  *
16  * GNU General Public License Usage:
17  * Alternatively, this file may be used under the terms of the GNU
18  * General Public License version 3.0 as published by the Free Software
19  * Foundation and appearing in the file LICENSE.GPL3 included in the
20  * packaging of this file. Please review the following information to
21  * ensure the GNU General Public License version 3.0 requirements will be
22  * met: http://www.gnu.org/copyleft/gpl.html.
23  * Alternatively you may (at your option) use any later version of the GNU
24  * General Public License if such license has been publicly approved by
25  * MLAB and NICR (or its successors, if any).
26  *
27  * IN NO EVENT SHALL "MLAB" OR "NICR" BE LIABLE TO ANY PARTY FOR DIRECT,
28  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
29  * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLAB" OR
30  * "NICR" HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * "MLAB" AND "NICR" SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
33  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
34  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
35  * ON AN "AS IS" BASIS, AND "MLAB" AND "NICR" HAVE NO OBLIGATION TO
36  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
37  */
38 
48 #ifndef _MIRA_THREADMONITOR_H_
49 #define _MIRA_THREADMONITOR_H_
50 
51 #include <map>
52 #include <vector>
53 
54 #include <platform/Platform.h>
55 #include <utils/Singleton.h>
56 #include <utils/Time.h>
57 
58 #include <thread/Thread.h>
59 #include <thread/ThreadID.h>
60 
61 namespace mira {
62 
64 
109  public LazySingleton<ThreadMonitor>
110 {
111 public:
114 
116  ThreadMonitor();
117 
119  virtual ~ThreadMonitor();
120 
122 
123 public:
126 
131  void addThisThread(const std::string& pName);
132 
136  void removeThisThread();
137 
142  void removeThread(const boost::thread& pThread);
143 
148  void removeThread(const boost::thread::id& pThreadID);
149 
154  void removeThread(ThreadID pThreadID);
155 
157 
158 public:
161 
163  struct ThreadInfo {
164  bool known;
166  boost::thread::id bid;
167  std::string name;
171  };
172 
174  typedef std::vector<ThreadInfo> ThreadInfoVector;
175 
180  ThreadInfoVector getThreadInformation();
181 
183 
184 private:
185  struct PrivateData {
186  ThreadID id;
187  boost::thread::id bid;
188  std::string name;
189  };
190 
191  typedef std::map<ThreadID, PrivateData> ThreadMap;
192 
193  boost::mutex mThreadsMutex;
194  ThreadMap mThreads;
195 };
196 
198 
199 }
200 
201 #endif
Duration kernel_time
The time amount in kernel-mode.
Definition: ThreadMonitor.h:170
Time create_time
Thread creation time in UTC.
Definition: ThreadMonitor.h:168
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
ThreadID id
Native thread ID (not boost::thread::native_handle_type!)
Definition: ThreadMonitor.h:165
Time and Duration wrapper class.
uint32 ThreadID
Platform independent thread ID.
Definition: ThreadID.h:68
Provided for convenience.
Definition: Singleton.h:564
Wrapper class for boost::posix_time::ptime for adding more functionality to it.
Definition: Time.h:416
OS independent thread id.
Includes, defines and functions for threads.
A singleton class that can be freely configured using policies that control the creation, instantiation, lifetime and thread-safety.
Use this class to represent time durations.
Definition: Time.h:104
std::vector< ThreadInfo > ThreadInfoVector
Definition of a vector of thread information.
Definition: ThreadMonitor.h:174
bool known
Indicates whether this thread is known by the ThreadMonitor.
Definition: ThreadMonitor.h:164
boost::thread::id bid
Boost thread ID.
Definition: ThreadMonitor.h:166
std::string name
The name of the thread.
Definition: ThreadMonitor.h:167
Duration user_time
The time amount in user-mode.
Definition: ThreadMonitor.h:169
#define MIRA_BASE_EXPORT
This is required because on windows there is a macro defined called ERROR.
Definition: Platform.h:153
A thread monitor class.
Definition: ThreadMonitor.h:108
A thread information type.
Definition: ThreadMonitor.h:163
Platform dependent defines and macros.