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 #include <ArmarXGui/gui-plugins/SystemStateMonitorPlugin/ui_ThreadViewer.h>
25 #include "ThreadViewerModel.h"
26 #include "RunningTaskModel.h"
27 #include "ProgressbarDelegate.h"
29 
32 
33 
34 namespace armarx
35 {
37  periodicTaskModel(0),
38  runningTaskModel(0),
39  ui(new Ui::ThreadViewer)
40 
41  {
42  ui->setupUi(getWidget());
43 
44  periodicTaskModel = new ThreadViewerModel(getWidget());
45 
46  ui->threadListView->setModel(periodicTaskModel);
47  ui->threadListView->setItemDelegateForColumn(3, new ProgressbarDelegate());
48 
49  ui->threadListView->setColumnWidth(0, 150);
50  ui->threadListView->setColumnWidth(1, 30);
51  ui->threadListView->setColumnWidth(2, 50);
52  ui->threadListView->setColumnWidth(3, 90);
53  ui->threadListView->setColumnWidth(4, 100);
54  ui->threadListView->setColumnWidth(5, 100);
55  ui->threadListView->setColumnWidth(6, 80);
56  ui->threadListView->setColumnWidth(7, 70);
57  ui->threadListView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
58 
59  runningTaskModel = new RunningTaskModel(getWidget());
60 
61  ui->runningTaskView->setModel(runningTaskModel);
62  ui->runningTaskView->setItemDelegateForColumn(2, new ProgressbarDelegate());
63 
64  ui->runningTaskView->setColumnWidth(0, 150);
65  ui->runningTaskView->setColumnWidth(1, 30);
66  ui->runningTaskView->setColumnWidth(2, 90);
67  ui->runningTaskView->setColumnWidth(3, 100);
68  ui->runningTaskView->setColumnWidth(4, 100);
69  ui->runningTaskView->setColumnWidth(5, 70);
70  ui->runningTaskView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
71 
72  QFont font;
73  font.setPointSize(8);
74  ui->threadListView->setFont(font);
75  ui->runningTaskView->setFont(font);
76 
77  connect(this, SIGNAL(threadManagerListUpdated(QStringList)), this, SLOT(updateThreadManagerList(QStringList)));
78  connect(this, SIGNAL(cpuUsageValueUpdated(int)), this, SLOT(cpuUsageValueSet(int)));
79  connect(ui->cbThreadListManager, SIGNAL(currentIndexChanged(QString)), this, SLOT(managedSelectionChanged(QString)));
80  connect(ui->btnRefresh, SIGNAL(clicked()), this, SLOT(triggerThreadManagerListUpdate()));
81  }
82 
84  {
85  delete ui;
86  }
87 
88  void ThreadViewer::loadSettings(QSettings* settings)
89  {
90  }
91 
92  void ThreadViewer::saveSettings(QSettings* settings)
93  {
94  }
95 
97  {
98 
99  }
100 
101 
102 
104  {
105 
107  periodicTask = new PeriodicTask<ThreadViewer>(this, &ThreadViewer::runThreadManagerUpdate, 500);
108  periodicTask->start();
109  }
110 
112  {
113  if (periodicTask)
114  {
115  periodicTask->stop();
116  }
117 
118  if (managerUpdateTask)
119  {
120  managerUpdateTask->stop();
121  }
122  }
124  {
125  if (managerUpdateTask && managerUpdateTask->isRunning())
126  {
127  return;
128  }
129 
130  ui->btnRefresh->setEnabled(false);
131  ui->btnRefresh->setToolTip("Refreshing manager list...please wait");
133  managerUpdateTask->start();
134  }
135 
136 
138  {
139  std::vector<std::string> managerList;
140  QStringList qManagerList;
141 
142  try
143  {
144  if (getIceManager() && getIceManager()->getIceGridSession())
145  managerList = getIceManager()->getIceGridSession()
146  ->getRegisteredObjectNames< ThreadListInterfacePrx >("*ThreadList");
147 
148  for (unsigned int i = 0; i < managerList.size(); ++i)
149  {
150  qManagerList << QString::fromStdString(managerList.at(i));
151  }
152  }
153  catch (...)
154  {
155  emit threadManagerListUpdated(qManagerList);
156  throw;
157  }
158 
159  emit threadManagerListUpdated(qManagerList);
160  }
161 
163  {
164  QString lastSelectionText = ui->cbThreadListManager->currentText();
165  ui->cbThreadListManager->clear();
166  ui->cbThreadListManager->addItems(list);
167  int index = ui->cbThreadListManager->findText(lastSelectionText);
168 
169  if (index > 0)
170  {
171  ui->cbThreadListManager->setCurrentIndex(index);
172  }
173 
174  ui->btnRefresh->setEnabled(true);
175  ui->btnRefresh->setToolTip("Refresh the thread manager list");
176 
177  }
178 
179  void ThreadViewer::managedSelectionChanged(QString selectedString)
180  {
181  if (selectedString.size() == 0)
182  {
183  return;
184  }
185 
186  std::unique_lock lock(proxyMutex);
187  threadManagerProxy = getProxy<ThreadListInterfacePrx>(selectedString.toStdString());
188  ARMARX_VERBOSE << "new proxy for ThreadViewerModel set: " << selectedString;
189  }
190 
192  {
193 
194  ui->cpuUsageProgressBar->setValue(value);
195  }
196 
197  void ThreadViewer::runThreadManagerUpdate()
198  {
199  std::unique_lock lock(proxyMutex);
200 
201  if (!threadManagerProxy)
202  {
203  return;
204  }
205 
206  try
207  {
208  PeriodicTaskList periodicTaskList = threadManagerProxy->getPeriodicTasks();
209  periodicTaskModel->setPeriodicTaskListData(periodicTaskList);
210 
211  RunningTaskList runningTaskList = threadManagerProxy->getRunningTasks();
212  runningTaskModel->setRunningTaskListData(runningTaskList);
213 
214  Ice::Double cpuProcTotalTime = threadManagerProxy->getCpuUsage();
215  int value = static_cast<int>(cpuProcTotalTime);
217  }
218  catch (Ice::NotRegisteredException& e)
219  {
220 
221  }
222  catch (Ice::ObjectAdapterDeactivatedException& e)
223  {
224 
225  }
226  catch (Ice::UnknownLocalException& e)
227  {
228 
229  }
230  }
231 }
armarx::ThreadViewer::cpuUsageValueUpdated
void cpuUsageValueUpdated(int value)
ARMARX_VERBOSE
#define ARMARX_VERBOSE
Definition: Logging.h:180
armarx::ManagedIceObject::getIceManager
IceManagerPtr getIceManager() const
Returns the IceManager.
Definition: ManagedIceObject.cpp:353
armarx::ThreadViewerModel::setPeriodicTaskListData
void setPeriodicTaskListData(const PeriodicTaskList &periodicTaskList)
Definition: ThreadViewerModel.cpp:175
ThreadViewer.h
ThreadViewerModel.h
armarx::ThreadViewer::~ThreadViewer
~ThreadViewer() override
Definition: ThreadViewer.cpp:83
index
uint8_t index
Definition: EtherCATFrame.h:59
armarx::ThreadViewer::onInitComponent
void onInitComponent() override
Definition: ThreadViewer.cpp:96
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:35
armarx::ThreadViewer::retrieveThreadManagerList
void retrieveThreadManagerList()
Definition: ThreadViewer.cpp:137
armarx::ThreadViewer::cpuUsageValueSet
void cpuUsageValueSet(int value)
Definition: ThreadViewer.cpp:191
armarx::ThreadViewer::loadSettings
void loadSettings(QSettings *settings) override
Load stored manager models.
Definition: ThreadViewer.cpp:88
armarx::VariantType::Double
const VariantTypeId Double
Definition: Variant.h:919
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::ThreadViewer::saveSettings
void saveSettings(QSettings *settings) override
Saves the manager models.
Definition: ThreadViewer.cpp:92
armarx::ThreadViewer
The ThreadViewer displays all threads of an ArmarX application.
Definition: ThreadViewer.h:58
Ui
ArmarX Headers.
Definition: ArmarXMainWindow.h:54
armarx::ThreadViewer::triggerThreadManagerListUpdate
void triggerThreadManagerListUpdate()
Definition: ThreadViewer.cpp:123
ThreadList.h
armarx::ThreadViewer::managedSelectionChanged
void managedSelectionChanged(QString selectedString)
Definition: ThreadViewer.cpp:179
armarx::ThreadViewer::updateThreadManagerList
void updateThreadManagerList(QStringList list)
Definition: ThreadViewer.cpp:162
IceGridAdmin.h
armarx::ProgressbarDelegate
Definition: ProgressbarDelegate.h:29
ExpressionException.h
armarx::ThreadViewer::onExitComponent
void onExitComponent() override
Hook for subclass.
Definition: ThreadViewer.cpp:111
armarx::ThreadViewer::ThreadViewer
ThreadViewer()
Definition: ThreadViewer.cpp:36
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:103
armarx::RunningTaskModel::setRunningTaskListData
void setRunningTaskListData(const RunningTaskList &runningTaskList)
Definition: RunningTaskModel.cpp:160
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
RunningTaskModel.h
armarx::RunningTaskModel
Definition: RunningTaskModel.h:34