ThreadList.h
Go to the documentation of this file.
1/*
2* This file is part of ArmarX.
3*
4* Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5*
6* ArmarX is free software; you can redistribute it and/or modify
7* it under the terms of the GNU General Public License version 2 as
8* published by the Free Software Foundation.
9*
10* ArmarX is distributed in the hope that it will be useful, but
11* WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17*
18* @package ArmarX::
19* @author Mirko Waechter ( mirko.waechter at kit dot edu)
20* @date 2012
21* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22* GNU General Public License
23*/
24
25#pragma once
26
27#include <iosfwd>
28#include <memory>
29
30#include <IceUtil/Thread.h>
31#include <IceUtil/Time.h>
32
34#include <ArmarXCore/interface/core/ThreadingIceBase.h>
35
36namespace armarx
37{
38
39 class ThreadList;
40 using ThreadListPtr = IceInternal::Handle<ThreadList>;
41
42 class ProcessWatcher;
43
44 class ThreadList : virtual public ThreadListInterface, virtual public ManagedIceObject
45 {
46 public:
47 ThreadList();
49
50 Ice::StringSeq getRunningTaskNames(const Ice::Current& c = Ice::emptyCurrent) override;
51 Ice::StringSeq getPeriodicTaskNames(const Ice::Current& c = Ice::emptyCurrent) override;
52
53 double getCpuUsage(const Ice::Current& c = Ice::emptyCurrent) override;
54
55 RunningTaskList getRunningTasks(const Ice::Current& c = Ice::emptyCurrent) override;
56 PeriodicTaskList getPeriodicTasks(const Ice::Current& c = Ice::emptyCurrent) override;
57
58 /**
59 * @brief add RunningTask instance to this thread list
60 * @param threadPtr pointer to the RunningTask instance to add
61 */
62 void addRunningTask(RunningTaskIceBase* threadPtr);
63
64 /**
65 * @brief remove RunningTask instance from this thread list
66 * @param threadPtr pointer to the RunningTask instance to remove
67 */
68 bool removeRunningTask(RunningTaskIceBase* threadPtr);
69
70 /**
71 * @brief add PeriodicTask instance to this thread list
72 * @param threadPtr pointer to the PeriodicTask instance to add
73 */
74 void addPeriodicTask(PeriodicTaskIceBase* threadPtr);
75
76 /**
77 * @brief remove PeriodicTask instance from this thread list
78 * @param threadPtr pointer to the PeriodicTask instance to remove
79 */
80 bool removePeriodicTask(PeriodicTaskIceBase* threadPtr);
81
82 /**
83 * @brief getApplicationThreadList retrieves the ThreadList, that
84 * contains all TimerTasks and PeriodicTasks in this Application.
85 *
86 * @return
87 */
88
90 static int GetThreadJiffies(int threadId);
91 static int GetHertz();
92
93 protected:
94 void setApplicationThreadListName(const std::string& threadListName);
95 friend class ArmarXManager;
96 //inherited from ManagedIceObject
97 void onInitComponent() override;
98 void onConnectComponent() override;
99 void onDisconnectComponent() override;
100
101 std::string
102 getDefaultName() const override
103 {
104 return "ThreadList";
105 }
106
107 void updateCPUUsage();
108
109 private:
110 struct Impl;
111 std::unique_ptr<Impl> impl;
112 };
113} // namespace armarx
114
115namespace std
116{
117 ARMARXCORE_IMPORT_EXPORT ostream& operator<<(ostream& stream,
118 const armarx::RunningTaskIceBase& task);
119}
#define ARMARXCORE_IMPORT_EXPORT
constexpr T c
ManagedIceObject(ManagedIceObject const &other)
The ProcessWatcher class is instantiated once in each armarx::Application an monitors thread,...
friend class ArmarXManager
Definition ThreadList.h:95
void addRunningTask(RunningTaskIceBase *threadPtr)
add RunningTask instance to this thread list
void onInitComponent() override
Pure virtual hook for the subclass.
RunningTaskList getRunningTasks(const Ice::Current &c=Ice::emptyCurrent) override
PeriodicTaskList getPeriodicTasks(const Ice::Current &c=Ice::emptyCurrent) override
bool removePeriodicTask(PeriodicTaskIceBase *threadPtr)
remove PeriodicTask instance from this thread list
Ice::StringSeq getPeriodicTaskNames(const Ice::Current &c=Ice::emptyCurrent) override
void onDisconnectComponent() override
Hook for subclass.
static int GetHertz()
static ThreadListPtr getApplicationThreadList()
getApplicationThreadList retrieves the ThreadList, that contains all TimerTasks and PeriodicTasks in ...
void setApplicationThreadListName(const std::string &threadListName)
bool removeRunningTask(RunningTaskIceBase *threadPtr)
remove RunningTask instance from this thread list
static int GetThreadJiffies(int threadId)
void addPeriodicTask(PeriodicTaskIceBase *threadPtr)
add PeriodicTask instance to this thread list
void onConnectComponent() override
Pure virtual hook for the subclass.
Ice::StringSeq getRunningTaskNames(const Ice::Current &c=Ice::emptyCurrent) override
std::string getDefaultName() const override
Retrieve default name of component.
Definition ThreadList.h:102
double getCpuUsage(const Ice::Current &c=Ice::emptyCurrent) override
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< ThreadList > ThreadListPtr
Definition RunningTask.h:39
ARMARXCORE_IMPORT_EXPORT ostream & operator<<(ostream &stream, const armarx::RunningTaskIceBase &task)