ThreadViewer.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package ArmarX::
17 * @author Mirko Waechter ( mirko.waechter at kit dot edu)
18 * @date 2013
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22 
23 #include "ThreadViewer.h"
24 
28 
29 #include <ArmarXGui/gui-plugins/SystemStateMonitorPlugin/ui_ThreadViewer.h>
30 
31 #include "ProgressbarDelegate.h"
32 #include "RunningTaskModel.h"
33 #include "ThreadViewerModel.h"
34 
35 namespace armarx
36 {
38  periodicTaskModel(0), runningTaskModel(0), ui(new Ui::ThreadViewer)
39 
40  {
41  ui->setupUi(getWidget());
42 
43  periodicTaskModel = new ThreadViewerModel(getWidget());
44 
45  ui->threadListView->setModel(periodicTaskModel);
46  ui->threadListView->setItemDelegateForColumn(3, new ProgressbarDelegate());
47 
48  ui->threadListView->setColumnWidth(0, 150);
49  ui->threadListView->setColumnWidth(1, 30);
50  ui->threadListView->setColumnWidth(2, 50);
51  ui->threadListView->setColumnWidth(3, 90);
52  ui->threadListView->setColumnWidth(4, 100);
53  ui->threadListView->setColumnWidth(5, 100);
54  ui->threadListView->setColumnWidth(6, 80);
55  ui->threadListView->setColumnWidth(7, 70);
56  ui->threadListView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
57 
58  runningTaskModel = new RunningTaskModel(getWidget());
59 
60  ui->runningTaskView->setModel(runningTaskModel);
61  ui->runningTaskView->setItemDelegateForColumn(2, new ProgressbarDelegate());
62 
63  ui->runningTaskView->setColumnWidth(0, 150);
64  ui->runningTaskView->setColumnWidth(1, 30);
65  ui->runningTaskView->setColumnWidth(2, 90);
66  ui->runningTaskView->setColumnWidth(3, 100);
67  ui->runningTaskView->setColumnWidth(4, 100);
68  ui->runningTaskView->setColumnWidth(5, 70);
69  ui->runningTaskView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
70 
71  QFont font;
72  font.setPointSize(8);
73  ui->threadListView->setFont(font);
74  ui->runningTaskView->setFont(font);
75 
76  connect(this,
77  SIGNAL(threadManagerListUpdated(QStringList)),
78  this,
79  SLOT(updateThreadManagerList(QStringList)));
80  connect(this, SIGNAL(cpuUsageValueUpdated(int)), this, SLOT(cpuUsageValueSet(int)));
81  connect(ui->cbThreadListManager,
82  SIGNAL(currentIndexChanged(QString)),
83  this,
84  SLOT(managedSelectionChanged(QString)));
85  connect(ui->btnRefresh, SIGNAL(clicked()), this, SLOT(triggerThreadManagerListUpdate()));
86  }
87 
89  {
90  delete ui;
91  }
92 
93  void
94  ThreadViewer::loadSettings(QSettings* settings)
95  {
96  }
97 
98  void
99  ThreadViewer::saveSettings(QSettings* settings)
100  {
101  }
102 
103  void
105  {
106  }
107 
108  void
110  {
111 
113  periodicTask =
114  new PeriodicTask<ThreadViewer>(this, &ThreadViewer::runThreadManagerUpdate, 500);
115  periodicTask->start();
116  }
117 
118  void
120  {
121  if (periodicTask)
122  {
123  periodicTask->stop();
124  }
125 
126  if (managerUpdateTask)
127  {
128  managerUpdateTask->stop();
129  }
130  }
131 
132  void
134  {
135  if (managerUpdateTask && managerUpdateTask->isRunning())
136  {
137  return;
138  }
139 
140  ui->btnRefresh->setEnabled(false);
141  ui->btnRefresh->setToolTip("Refreshing manager list...please wait");
142  managerUpdateTask =
144  managerUpdateTask->start();
145  }
146 
147  void
149  {
150  std::vector<std::string> managerList;
151  QStringList qManagerList;
152 
153  try
154  {
155  if (getIceManager() && getIceManager()->getIceGridSession())
156  managerList = getIceManager()
157  ->getIceGridSession()
158  ->getRegisteredObjectNames<ThreadListInterfacePrx>("*ThreadList");
159 
160  for (unsigned int i = 0; i < managerList.size(); ++i)
161  {
162  qManagerList << QString::fromStdString(managerList.at(i));
163  }
164  }
165  catch (...)
166  {
167  emit threadManagerListUpdated(qManagerList);
168  throw;
169  }
170 
171  emit threadManagerListUpdated(qManagerList);
172  }
173 
174  void
176  {
177  QString lastSelectionText = ui->cbThreadListManager->currentText();
178  ui->cbThreadListManager->clear();
179  ui->cbThreadListManager->addItems(list);
180  int index = ui->cbThreadListManager->findText(lastSelectionText);
181 
182  if (index > 0)
183  {
184  ui->cbThreadListManager->setCurrentIndex(index);
185  }
186 
187  ui->btnRefresh->setEnabled(true);
188  ui->btnRefresh->setToolTip("Refresh the thread manager list");
189  }
190 
191  void
193  {
194  if (selectedString.size() == 0)
195  {
196  return;
197  }
198 
199  std::unique_lock lock(proxyMutex);
200  threadManagerProxy = getProxy<ThreadListInterfacePrx>(selectedString.toStdString());
201  ARMARX_VERBOSE << "new proxy for ThreadViewerModel set: " << selectedString;
202  }
203 
204  void
206  {
207 
208  ui->cpuUsageProgressBar->setValue(value);
209  }
210 
211  void
212  ThreadViewer::runThreadManagerUpdate()
213  {
214  std::unique_lock lock(proxyMutex);
215 
216  if (!threadManagerProxy)
217  {
218  return;
219  }
220 
221  try
222  {
223  PeriodicTaskList periodicTaskList = threadManagerProxy->getPeriodicTasks();
224  periodicTaskModel->setPeriodicTaskListData(periodicTaskList);
225 
226  RunningTaskList runningTaskList = threadManagerProxy->getRunningTasks();
227  runningTaskModel->setRunningTaskListData(runningTaskList);
228 
229  Ice::Double cpuProcTotalTime = threadManagerProxy->getCpuUsage();
230  int value = static_cast<int>(cpuProcTotalTime);
232  }
233  catch (Ice::NotRegisteredException& e)
234  {
235  }
236  catch (Ice::ObjectAdapterDeactivatedException& e)
237  {
238  }
239  catch (Ice::UnknownLocalException& e)
240  {
241  }
242  }
243 } // namespace armarx
armarx::ThreadViewer::cpuUsageValueUpdated
void cpuUsageValueUpdated(int value)
ARMARX_VERBOSE
#define ARMARX_VERBOSE
Definition: Logging.h:187
armarx::ManagedIceObject::getIceManager
IceManagerPtr getIceManager() const
Returns the IceManager.
Definition: ManagedIceObject.cpp:366
armarx::ThreadViewerModel::setPeriodicTaskListData
void setPeriodicTaskListData(const PeriodicTaskList &periodicTaskList)
Definition: ThreadViewerModel.cpp:175
ThreadViewer.h
ThreadViewerModel.h
armarx::ThreadViewer::~ThreadViewer
~ThreadViewer() override
Definition: ThreadViewer.cpp:88
index
uint8_t index
Definition: EtherCATFrame.h:59
armarx::ThreadViewer::onInitComponent
void onInitComponent() override
Definition: ThreadViewer.cpp:104
list
list(APPEND SOURCES ${QT_RESOURCES}) set(COMPONENT_LIBS ArmarXGui ArmarXCoreObservers ArmarXCoreEigen3Variants PlotterController $
Definition: CMakeLists.txt:49
armarx::ThreadViewerModel
Definition: ThreadViewerModel.h:34
armarx::ThreadViewer::threadManagerListUpdated
void threadManagerListUpdated(QStringList list)
armarx::RunningTask
Definition: ArmarXMultipleObjectsScheduler.h:36
armarx::ThreadViewer::retrieveThreadManagerList
void retrieveThreadManagerList()
Definition: ThreadViewer.cpp:148
armarx::ThreadViewer::cpuUsageValueSet
void cpuUsageValueSet(int value)
Definition: ThreadViewer.cpp:205
armarx::ThreadViewer::loadSettings
void loadSettings(QSettings *settings) override
Load stored manager models.
Definition: ThreadViewer.cpp:94
armarx::VariantType::Double
const VariantTypeId Double
Definition: Variant.h:920
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:855
armarx::ThreadViewer::saveSettings
void saveSettings(QSettings *settings) override
Saves the manager models.
Definition: ThreadViewer.cpp:99
armarx::ThreadViewer
The ThreadViewer displays all threads of an ArmarX application.
Definition: ThreadViewer.h:60
Ui
ArmarX Headers.
Definition: ArmarXMainWindow.h:54
armarx::ThreadViewer::triggerThreadManagerListUpdate
void triggerThreadManagerListUpdate()
Definition: ThreadViewer.cpp:133
ThreadList.h
armarx::ThreadViewer::managedSelectionChanged
void managedSelectionChanged(QString selectedString)
Definition: ThreadViewer.cpp:192
armarx::ThreadViewer::updateThreadManagerList
void updateThreadManagerList(QStringList list)
Definition: ThreadViewer.cpp:175
IceGridAdmin.h
armarx::ProgressbarDelegate
Definition: ProgressbarDelegate.h:29
ExpressionException.h
armarx::ThreadViewer::onExitComponent
void onExitComponent() override
Hook for subclass.
Definition: ThreadViewer.cpp:119
armarx::ThreadViewer::ThreadViewer
ThreadViewer()
Definition: ThreadViewer.cpp:37
ProgressbarDelegate.h
armarx::ArmarXWidgetController::getWidget
virtual QPointer< QWidget > getWidget()
getWidget returns a pointer to the a widget of this controller.
Definition: ArmarXWidgetController.cpp:54
armarx::PeriodicTask
Definition: ArmarXManager.h:70
armarx::ThreadViewer::onConnectComponent
void onConnectComponent() override
Definition: ThreadViewer.cpp:109
armarx::RunningTaskModel::setRunningTaskListData
void setRunningTaskListData(const RunningTaskList &runningTaskList)
Definition: RunningTaskModel.cpp:162
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
RunningTaskModel.h
armarx::RunningTaskModel
Definition: RunningTaskModel.h:34