YARP
Yet Another Robot Platform
NetworkProfiler.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * All rights reserved.
4  *
5  * This software may be modified and distributed under the terms of the
6  * BSD-3-Clause license. See the accompanying LICENSE file for details.
7  */
8 
9 #ifndef YARP_PROFILER_NETWORK_PROFILER_H
10 #define YARP_PROFILER_NETWORK_PROFILER_H
11 
12 #include <string>
13 #include <sstream>
14 #include <iostream>
15 #include <vector>
16 
17 #include <yarp/profiler/Graph.h>
18 #include <yarp/os/Network.h>
19 #include <yarp/os/LogStream.h>
20 #include <yarp/os/Bottle.h>
21 
22 
23 namespace yarp {
24  namespace profiler {
25 
27 {
28 
29 public:
30 
32  {
33  public:
34  virtual ~ProgressCallback() { }
35  virtual void onProgress(unsigned int percentage) { }
36  };
37 
39  {
40  std::string name;
41  std::string carrier;
42  };
43 
44  struct MachineInfo
45  {
46  std::string os;
47  std::string hostname;
48 
49  };
50 
51  struct ProcessInfo
52  {
53  std::string name;
54  std::string arguments;
55  std::string os;
56  std::string hostname;
58  int pid;
59  int priority;
60  int policy;
61  ProcessInfo() { pid = priority = policy = -1; }
62  };
63 
64  struct PortDetails
65  {
66  std::string name;
67  std::vector<ConnectionInfo> outputs;
68  std::vector<ConnectionInfo> inputs;
70  std::string toString() const {
71  std::ostringstream str;
72  str<<"port name: "<<name<<std::endl;
73  str<<"outputs:"<<std::endl;
74  std::vector<ConnectionInfo>::const_iterator itr;
75  for(itr=outputs.begin(); itr!=outputs.end(); itr++)
76  str<<" + "<<(*itr).name<<" ("<<(*itr).carrier<<")"<<std::endl;
77  str<<"inputs:"<<std::endl;
78  for(itr=inputs.begin(); itr!=inputs.end(); itr++)
79  str<<" + "<<(*itr).name<<" ("<<(*itr).carrier<<")"<<std::endl;
80  str<<"owner:"<<std::endl;
81  str<<" + name: "<<owner.name<<std::endl;
82  str<<" + arguments: "<<owner.arguments<<std::endl;
83  str<<" + hostname: "<<owner.hostname<<std::endl;
84  str<<" + priority: "<<owner.priority<<std::endl;
85  str<<" + policy: "<<owner.policy<<std::endl;
86  str<<" + os: "<<owner.os<<std::endl;
87  str<<" + pid: "<<owner.pid<<std::endl;
88  return str.str();
89  }
90  };
91 
92  typedef std::vector<yarp::os::Bottle> ports_name_set;
93  typedef ports_name_set::iterator ports_name_iterator;
94 
95  typedef std::vector<PortDetails> ports_detail_set;
96  typedef ports_detail_set::iterator ports_detail_iterator;
97 
98 public:
105  static bool getPortDetails(const std::string& portName, PortDetails& info);
106 
112  static bool yarpNameList(ports_name_set& ports, bool complete=false);
113 
121 
123 
129  static bool yarpClean(float timeout=0.1);
130 
131  static void setProgressCallback(ProgressCallback* callback) {
132  progCallback = callback;
133  }
134 
136 
139 
140  static bool attachPortmonitorPlugin(std::string portName, yarp::os::Property pluginProp);
141  static bool detachPortmonitorPlugin(std::string portName);
142  static bool setPortmonitorParams(std::string portName, yarp::os::Property& param);
143  static bool getPortmonitorParams(std::string portName, yarp::os::Bottle &param);
144 
145 private:
146  static ProgressCallback* progCallback;
147 
148 };
149 
150  }
151 }
152 
153 
154 #endif //YARP_PROFILER_NETWORK_PROFILER_H
LogStream.h
yarp::os::Bottle
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:73
yarp::profiler::NetworkProfiler::yarpNameList
static bool yarpNameList(ports_name_set &ports, bool complete=false)
yarpNameList
Definition: NetworkProfiler.cpp:28
Network.h
yarp::profiler::NetworkProfiler::ProgressCallback::~ProgressCallback
virtual ~ProgressCallback()
Definition: NetworkProfiler.h:34
yarp::profiler::NetworkProfiler::PortDetails
Definition: NetworkProfiler.h:65
yarp::profiler::NetworkProfiler::ProcessInfo::arguments
std::string arguments
Definition: NetworkProfiler.h:54
yarp::profiler::NetworkProfiler::ports_name_set
std::vector< yarp::os::Bottle > ports_name_set
Definition: NetworkProfiler.h:92
yarp::profiler::NetworkProfiler::PortDetails::inputs
std::vector< ConnectionInfo > inputs
Definition: NetworkProfiler.h:68
yarp::profiler::NetworkProfiler::yarpClean
static bool yarpClean(float timeout=0.1)
NetworkProfiler::yarpClean.
Definition: NetworkProfiler.cpp:231
yarp::profiler::NetworkProfiler::updateConnectionQosStatus
static bool updateConnectionQosStatus(yarp::profiler::graph::Graph &graph)
Definition: NetworkProfiler.cpp:344
yarp::profiler::NetworkProfiler::getPortmonitorParams
static bool getPortmonitorParams(std::string portName, yarp::os::Bottle &param)
Definition: NetworkProfiler.cpp:448
yarp::profiler::NetworkProfiler::setProgressCallback
static void setProgressCallback(ProgressCallback *callback)
Definition: NetworkProfiler.h:131
yarp::profiler::NetworkProfiler::ProcessInfo::priority
int priority
Definition: NetworkProfiler.h:59
yarp::profiler::NetworkProfiler::PortDetails::name
std::string name
Definition: NetworkProfiler.h:66
yarp::profiler::NetworkProfiler::creatSimpleModuleGraph
static bool creatSimpleModuleGraph(yarp::profiler::graph::Graph &graph, yarp::profiler::graph::Graph &subgraph)
Definition: NetworkProfiler.cpp:245
yarp::profiler::NetworkProfiler::ConnectionInfo::carrier
std::string carrier
Definition: NetworkProfiler.h:41
yarp::profiler::NetworkProfiler::ConnectionInfo
Definition: NetworkProfiler.h:39
yarp::profiler::NetworkProfiler::ProcessInfo::owner
MachineInfo owner
Definition: NetworkProfiler.h:57
yarp::profiler::NetworkProfiler::PortDetails::owner
ProcessInfo owner
Definition: NetworkProfiler.h:69
yarp::profiler::NetworkProfiler::ports_detail_iterator
ports_detail_set::iterator ports_detail_iterator
Definition: NetworkProfiler.h:96
yarp::profiler::NetworkProfiler::ports_detail_set
std::vector< PortDetails > ports_detail_set
Definition: NetworkProfiler.h:95
yarp::profiler::NetworkProfiler::MachineInfo::hostname
std::string hostname
Definition: NetworkProfiler.h:47
yarp::profiler::NetworkProfiler::ProgressCallback::onProgress
virtual void onProgress(unsigned int percentage)
Definition: NetworkProfiler.h:35
yarp::profiler::NetworkProfiler::ProcessInfo
Definition: NetworkProfiler.h:52
yarp::profiler::NetworkProfiler::attachPortmonitorPlugin
static bool attachPortmonitorPlugin(std::string portName, yarp::os::Property pluginProp)
Definition: NetworkProfiler.cpp:377
yarp::profiler::NetworkProfiler::ports_name_iterator
ports_name_set::iterator ports_name_iterator
Definition: NetworkProfiler.h:93
yarp::profiler::NetworkProfiler::ConnectionInfo::name
std::string name
Definition: NetworkProfiler.h:40
yarp::profiler::NetworkProfiler::ProcessInfo::policy
int policy
Definition: NetworkProfiler.h:60
yarp::profiler::NetworkProfiler::ProcessInfo::ProcessInfo
ProcessInfo()
Definition: NetworkProfiler.h:61
yarp::profiler::NetworkProfiler::ProcessInfo::pid
int pid
Definition: NetworkProfiler.h:58
yarp::profiler::NetworkProfiler
Definition: NetworkProfiler.h:27
Graph.h
yarp::profiler::NetworkProfiler::ProgressCallback
Definition: NetworkProfiler.h:32
yarp::profiler::NetworkProfiler::PortDetails::toString
std::string toString() const
Definition: NetworkProfiler.h:70
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
yarp::os::QosStyle::PacketPriorityLevel
PacketPriorityLevel
The PacketPriorityLevel defines the packets quality of service (priority) levels.
Definition: QosStyle.h:33
yarp::profiler::graph::Graph
The yarp::profiler::graph::Graph class.
Definition: Graph.h:111
yarp::profiler::NetworkProfiler::PortDetails::outputs
std::vector< ConnectionInfo > outputs
Definition: NetworkProfiler.h:67
yarp::profiler::NetworkProfiler::packetPrioToString
static std::string packetPrioToString(yarp::os::QosStyle::PacketPriorityLevel level)
Definition: NetworkProfiler.cpp:305
yarp::profiler::NetworkProfiler::MachineInfo
Definition: NetworkProfiler.h:45
yarp::profiler::NetworkProfiler::MachineInfo::os
std::string os
Definition: NetworkProfiler.h:46
yarp::profiler::NetworkProfiler::setPortmonitorParams
static bool setPortmonitorParams(std::string portName, yarp::os::Property &param)
Definition: NetworkProfiler.cpp:420
yarp::profiler::NetworkProfiler::packetStringToPrio
static yarp::os::QosStyle::PacketPriorityLevel packetStringToPrio(std::string level)
Definition: NetworkProfiler.cpp:335
yarp::profiler::NetworkProfiler::ProcessInfo::name
std::string name
Definition: NetworkProfiler.h:53
yarp::profiler::NetworkProfiler::ProcessInfo::os
std::string os
Definition: NetworkProfiler.h:55
Bottle.h
yarp::profiler::NetworkProfiler::ProcessInfo::hostname
std::string hostname
Definition: NetworkProfiler.h:56
yarp::os::Property
A class for storing options and configuration information.
Definition: Property.h:37
yarp::profiler::NetworkProfiler::getPortDetails
static bool getPortDetails(const std::string &portName, PortDetails &info)
getPortDetails
Definition: NetworkProfiler.cpp:72
yarp::profiler::NetworkProfiler::creatNetworkGraph
static bool creatNetworkGraph(ports_detail_set details, yarp::profiler::graph::Graph &graph)
creatNetworkGraph
Definition: NetworkProfiler.cpp:154
yarp::profiler::NetworkProfiler::detachPortmonitorPlugin
static bool detachPortmonitorPlugin(std::string portName)
Definition: NetworkProfiler.cpp:402