17#include <yarp/stats/ConnectionStats.h>
24 "yarp.portmonitor.StatsMonitor",
34 m_isSender = options.
find(
"sender_side").
asBool();
40 yCError(STATSMONITOR,
"Attaching on receiver side is not supported yet.");
45 m_stats_thread_forward = std::make_unique<StatsThread>(period, m_source, m_destination, m_carrier,
true);
46 if (!m_stats_thread_forward->start())
50 m_stats_thread_backward = std::make_unique<StatsThread>(period, m_destination, m_source, m_carrier,
false);
51 if (!m_stats_thread_backward->start())
68 m_stats_thread_forward->setData(bytes);
83 m_stats_thread_backward->setData(bytes);
91 std::lock_guard lock(m_mutex);
93 m_datasize_sum += datasize;
103 std::lock_guard lock(m_mutex);
104 local_sum = m_datasize_sum;
105 local_count = m_datasize_count;
106 m_datasize_count = 0;
110 yarp::stats::ConnectionStats msg;
112 msg.source = m_source;
113 msg.destination = m_destination;
114 msg.carrier = m_carrier;
115 msg.isForward = m_isForward;
116 msg.bytes_per_second = local_sum/m_period;
117 msg.frequency = local_count/m_period;
118 m_stats_port.
write(msg);
125 if (!m_stats_port.
open(m_stats_port_name))
127 yCError(STATSMONITOR,
"Could not open port %s.", m_stats_port_name.c_str());
135 m_stats_port.
close();
yarp::os::Things & update(yarp::os::Things &thing) override
After data get accpeted in the accept() callback, an instance of that is given to the update function...
yarp::os::Things & updateReply(yarp::os::Things &thing) override
The updateReply makes it possible to modify a reply from a port when the portmonitor object is attach...
bool create(const yarp::os::Property &options) override
This will be called when the dll is properly loaded by the portmonitor carrier.
void run() override
Loop function.
bool threadInit() override
Initialization method.
void setData(size_t datasize)
void threadRelease() override
Release method.
static LogCallback printCallback()
Get current print callback.
static LogType minimumPrintLevel()
Get current minimum print level.
bool write(const PortWriter &writer, const PortWriter *callback=nullptr) const override
Write an object to the port.
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.
static double nowSystem()
Base class for generic things.
bool write(yarp::os::ConnectionWriter &connection)
virtual bool asBool() const
Get boolean value.
virtual std::string asString() const
Get string value.
A helper for creating cached object descriptions.
virtual size_t dataSize() const
#define yCError(component,...)
#define YARP_LOG_COMPONENT(name,...)