9#include <QProgressDialog>
14#include "ui_portloggerdialog.h"
31 connect(ui->pushButtonRemove,
SIGNAL(
clicked()),
this,
SLOT(removeConnections()));
36 ui->pushButtonStart->setEnabled(
false);
37 ui->checkBoxCollect->setChecked(
true);
39 PortLoggerDialog::graph = graph;
43 for(itr = vertices.begin(); itr!=vertices.end(); itr++) {
45 for(
const auto& i :
v1.outEdges()) {
48 if(!
v1.property.check(
"hidden") && !
v2.property.check(
"hidden")) {
51 std::string source =
v1.property.find(
"name").asString();
52 std::string destination =
v2.property.find(
"name").asString();
55 QTreeWidgetItem*
item;
58 prop.append(source.c_str());
59 prop.append(destination.c_str());
60 prop.append(carrier.c_str());
61 item =
new QTreeWidgetItem( ui->treeWidgetCons, prop);
67 ui->pushButtonAdd->setEnabled(ui->treeWidgetCons->topLevelItemCount() > 0);
68 ui->pushButtonRemove->setEnabled(ui->treeWidgetSelectedCons->topLevelItemCount() > 0);
69 ui->lineEditLogPath->setText(QDir::homePath());
77void PortLoggerDialog::openCons()
81 QString filename = QFileDialog::getOpenFileName(
nullptr,
"Load connections list",
84 if (filename.size() == 0) {
89 file.open(filename.toStdString().c_str());
90 if (!file.is_open()) {
91 QMessageBox::critical(
nullptr, QObject::tr(
"Error"), QObject::tr(
"Cannot open the file for loading"));
95 ui->treeWidgetCons->clear();
97 unsigned int count = 0;
101 if(sample.size() == 3) {
104 QTreeWidgetItem*
item;
107 prop.append(sample.get(0).asString().c_str());
108 prop.append(sample.get(1).asString().c_str());
109 prop.append(sample.get(2).asString().c_str());
110 item =
new QTreeWidgetItem( ui->treeWidgetCons, prop);
113 yWarning() <<
"Wrong connection data at line" << count;
119void PortLoggerDialog::addConnections() {
121 itemList = ui->treeWidgetCons->selectedItems();
122 foreach(QTreeWidgetItem *
item, itemList) {
126 prop.append(
item->text(0));
127 prop.append(
item->text(1));
128 prop.append(
item->text(2));
129 newitem =
new QTreeWidgetItem( ui->treeWidgetSelectedCons, prop);
133 ui->pushButtonStart->setEnabled(ui->treeWidgetSelectedCons->topLevelItemCount() > 0);
134 ui->pushButtonAdd->setEnabled(ui->treeWidgetCons->topLevelItemCount() > 0);
135 ui->pushButtonRemove->setEnabled(ui->treeWidgetSelectedCons->topLevelItemCount() > 0);
138void PortLoggerDialog::removeConnections() {
140 itemList = ui->treeWidgetSelectedCons->selectedItems();
141 foreach(QTreeWidgetItem *
item, itemList) {
145 prop.append(
item->text(0));
146 prop.append(
item->text(1));
147 prop.append(
item->text(2));
148 newitem =
new QTreeWidgetItem( ui->treeWidgetCons, prop);
152 ui->pushButtonStart->setEnabled(ui->treeWidgetSelectedCons->topLevelItemCount() > 0);
153 ui->pushButtonAdd->setEnabled(ui->treeWidgetCons->topLevelItemCount() > 0);
154 ui->pushButtonRemove->setEnabled(ui->treeWidgetSelectedCons->topLevelItemCount() > 0);
157void PortLoggerDialog::startStopLoggers() {
160 prop.
put(
"context",
"yarpviz");
161 prop.
put(
"file",
"portrate");
164 for(
int i=0; i < ui->treeWidgetSelectedCons->topLevelItemCount(); ++i ){
165 QTreeWidgetItem *
item = ui->treeWidgetSelectedCons->topLevelItem(i);
176 connect(timer,
SIGNAL(timeout()),
this,
SLOT(MyTimerSlot()));
180 ui->pushButtonStart->setText(
"Sto&p");
186 messageBox.critical(
nullptr,
"Error",
"An error has occurred while starting the portrate plugin for some ports ! \n Please check if the LUA portmonitor carrier is enabled in YARP and portrate plugin can be found by the portmonitor.");
192 ui->treeWidgetSelectedCons->topLevelItemCount(),
this);
193 progressDlg->setLabelText(
"Collecting the results...");
194 progressDlg->reset();
195 progressDlg->setValue(0);
196 progressDlg->setWindowModality(Qt::WindowModal);
198 for(
int i=0; i < ui->treeWidgetSelectedCons->topLevelItemCount(); ++i ){
199 progressDlg->setValue(i);
200 progressDlg->update();
201 progressDlg->repaint();
202 QTreeWidgetItem *
item = ui->treeWidgetSelectedCons->topLevelItem(i);
203 if(ui->checkBoxCollect->checkState() == Qt::Checked) {
205 std::string portname =
item->text(1).toUtf8().constData();
209 yError()<<
"Got wrong result format from portrate plugin at "<<portname;
215 yError()<<
"Got wrong result format from portrate plugin at "<<portname;
219 QString filename = portname.c_str();
220 filename.replace(
"/",
"_");
221 filename = ui->lineEditLogPath->text() +
"/port." +filename +
".log";
222 if (!saveLog(filename.toStdString(), samples)) {
223 yError() <<
"could not save the result into " << filename.toStdString();
229 param.
put(
"log_save", 1);
242 ui->pushButtonStart->setText(
"&Start");
244 ui->treeWidgetCons->setEnabled(!isStarted);
245 ui->treeWidgetSelectedCons->setEnabled(!isStarted);
246 ui->pushButtonClose->setEnabled(!isStarted);
247 ui->pushButtonAdd->setEnabled(!isStarted);
248 ui->pushButtonRemove->setEnabled(!isStarted);
249 ui->checkBoxCollect->setEnabled(!isStarted);
252void PortLoggerDialog::MyTimerSlot() {
253 ui->lcdNumberLogTime->display(logTime.elapsed()/1000.0);
256bool PortLoggerDialog::saveLog(std::string filename,
yarp::os::Bottle* samples) {
258 file.
open(filename.c_str());
259 if(!file.is_open()) {
263 for(
size_t k=0;
k<samples->
size();
k++) {
265 file<<
smp->toString().c_str()<<
'\n';
272void PortLoggerDialog::setLogPath() {
275 QString filename = QFileDialog::getExistingDirectory(
nullptr,
"Set the log files path",
276 QDir::homePath(),QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
277 if (filename.size() == 0) {
280 ui->lineEditLogPath->setText(filename);
pvertex_set::const_iterator pvertex_const_iterator
std::vector< yarp::profiler::graph::Vertex * > pvertex_set
int SIGNAL(int pid, int signum)
PortLoggerDialog(yarp::profiler::graph::Graph *graph, QWidget *parent=0)
A simple collection of objects that can be described and transmitted in a portable way.
size_type size() const
Gets the number of elements in the bottle.
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
Bottle & findGroup(const std::string &key) const override
Gets a list corresponding to a given keyword.
bool isNull() const override
Checks if the object is invalid.
A mini-server for performing network communication in the background.
void close() override
Stop port activity.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
A class for storing options and configuration information.
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
virtual Bottle * asList() const
Get list value.
virtual std::string asString() const
Get string value.
static bool getPortmonitorParams(std::string portName, yarp::os::Bottle ¶m)
static bool attachPortmonitorPlugin(std::string portName, yarp::os::Property pluginProp)
static bool setPortmonitorParams(std::string portName, yarp::os::Property ¶m)
static bool detachPortmonitorPlugin(std::string portName)
The yarp::profiler::graph::Edge class.
const yarp::profiler::graph::Vertex & second() const
yarp::os::Property property
The yarp::profiler::graph::Graph class.
const pvertex_set & vertices()
The yarp::profiler::graph::Vertex class.
An interface to the operating system, including Port based communication.