30 yCInfo(
YARPCONNINFO) <<
"This is the tool yarpconnectionsstats, a tool that displays the frequency at which YARP ports broadcast data";
32 yCInfo(
YARPCONNINFO) <<
"In order to work properly, the connection we want to inspect must be monitored by a `stats_monitor` portmonitor.";
33 yCInfo(
YARPCONNINFO) <<
"e.g. yarp connect /sender /recv tcp+send.portmonitor+file.stats_monitor+type.dll";
37 yCInfo(
YARPCONNINFO) <<
"--display_zero_bps (default: true) if enabled, displays also if the connection is not transmitting anything";
39 yCInfo(
YARPCONNINFO) <<
"--display_by_dest_name order results by destination port name";
41 yCInfo(
YARPCONNINFO) <<
"--display_screen_frequency (default value: 1) refresh frequency";
51 bool display_backward =
false;
52 bool display_zero_bps =
true;
53 bool display_by_source_name =
false;
54 bool display_by_dest_name =
false;
55 bool display_by_bps =
false;
56 double display_screen_frequency = 1.0;
58 yarp::stats::StatsEngine m_engine;
59 std::list<std::string> m_ports;
60 yarp::stats::StatsEngine::PortInfoMap m_portsmap;
64 if (rf.
check(
"help")) { display_help();
return false; }
65 if (rf.
check(
"display_backward")) { display_backward = rf.
find(
"display_backward").
asBool(); }
66 if (rf.
check(
"display_zero_bps")) { display_zero_bps = rf.
find(
"display_zero_bps").
asBool(); }
67 if (rf.
check(
"display_by_source_name")) { display_by_source_name = rf.
find(
"display_by_source_name").
asBool(); }
68 if (rf.
check(
"display_by_dest_name")) { display_by_dest_name = rf.
find(
"display_by_dest_name").
asBool(); }
69 if (rf.
check(
"display_by_bps")) { display_by_bps = rf.
find(
"display_by_bps").
asBool(); }
70 if (rf.
check(
"display_screen_frequency")) { display_screen_frequency = rf.
find(
"display_screen_frequency").
asFloat64(); }
72 m_engine.m_display_backward = display_backward;
73 m_engine.m_display_zero_bps = display_zero_bps;
75 m_engine.discover(m_ports, m_portsmap);
76 m_engine.connect(m_ports);
83 m_engine.disconnect();
87 double getPeriod()
override
89 return display_screen_frequency;
92 bool updateModule()
override
94 std::cout <<
"\033[2J\033[H";
96 std::list<yarp::stats::ConnectionStats>
stats;
97 m_engine.update(
stats);
102 std::map<std::pair<std::string, std::string>,
double>
ip_pair_bytes;
114 if (
dest_it != m_portsmap.end()) {
126 if (display_by_source_name) {sortConnections(
stats, SortMode::Source);}
127 else if (display_by_dest_name) {sortConnections(
stats, SortMode::Destination);}
128 else if (display_by_bps) {sortConnections(
stats, SortMode::BytesPerSecondDesc);}
141 std::ostringstream line;
149 << std::setw(12) <<
it->bytes_per_second <<
" B/s"
151 << std::setw(8) <<
it->frequency <<
" pkt/s"
155 << std::setw(8) <<
it->carrier
157 << std::setw(8) << std::fixed << std::setprecision(3) <<
it->timestamp;
159 yInfo() << line.str();
167 std::ostringstream line;
169 << std::setw(15) <<
ip_pair.first
171 << std::setw(15) <<
ip_pair.second
175 yInfo() << line.str();
181 void sortConnections(std::list<yarp::stats::ConnectionStats>& connections, SortMode mode)
185 case SortMode::Source:
187 [](
const auto& a,
const auto& b)
189 return a.source < b.source;
193 case SortMode::Destination:
195 [](
const auto& a,
const auto& b)
197 return a.destination < b.destination;
201 case SortMode::BytesPerSecondDesc:
203 [](
const auto& a,
const auto& b)
205 return a.bytes_per_second > b.bytes_per_second;
int main(int argc, char *argv[])
struct stats_struct stats