1717#include < algorithm>
1818#include < functional>
1919#include < memory>
20+ #include < vector>
2021
2122#include " ./utilities.hpp"
2223
@@ -65,18 +66,15 @@ void PingNode::print_statistics(std::chrono::seconds experiment_duration) const
6566{
6667 size_t ping_count = rtt_data_.size ();
6768
68- size_t high_pong_count = 0 ;
69- size_t low_pong_count = 0 ;
70- rclcpp::Duration high_rtt_sum (0 , 0 );
71- rclcpp::Duration low_rtt_sum (0 , 0 );
69+ std::vector<double > high_rtts;
70+ std::vector<double > low_rtts;
71+
7272 for (const auto & entry : rtt_data_) {
7373 if (entry.high_received_ .nanoseconds () >= entry.sent_ .nanoseconds ()) {
74- ++high_pong_count;
75- high_rtt_sum = high_rtt_sum + (entry.high_received_ - entry.sent_ );
74+ high_rtts.push_back ((entry.high_received_ - entry.sent_ ).seconds ());
7675 }
7776 if (entry.low_received_ .nanoseconds () >= entry.sent_ .nanoseconds ()) {
78- ++low_pong_count;
79- low_rtt_sum = low_rtt_sum + (entry.low_received_ - entry.sent_ );
77+ low_rtts.push_back ((entry.low_received_ - entry.sent_ ).seconds ());
8078 }
8179 }
8280
@@ -87,18 +85,22 @@ void PingNode::print_statistics(std::chrono::seconds experiment_duration) const
8785 ping_count, ideal_ping_count, 100 * ping_count / ideal_ping_count);
8886 RCLCPP_INFO (
8987 get_logger (), " High prio path: Received %zu pongs, i.e. for %zu%% of the pings." ,
90- high_pong_count , 100 * high_pong_count / ping_count);
91- if (high_pong_count > 0 ) {
92- double high_rtt_avg = (high_rtt_sum. seconds ( ) * 1000.0 / high_pong_count) ;
88+ high_rtts. size () , 100 * high_rtts. size () / ping_count);
89+ if (!high_rtts. empty () ) {
90+ double high_rtt_avg = calc_average (high_rtts ) * 1000.0 ;
9391 RCLCPP_INFO (get_logger (), " High prio path: Average RTT is %3.1fms." , high_rtt_avg);
92+ double high_rtt_jitter = calc_std_deviation (high_rtts) * 1000.0 ;
93+ RCLCPP_INFO (get_logger (), " High prio path: Jitter of RTT is %5.3fms." , high_rtt_jitter);
9494 }
9595
9696 RCLCPP_INFO (
9797 get_logger (), " Low prio path: Received %zu pongs, i.e. for %zu%% of the pings." ,
98- low_pong_count , 100 * low_pong_count / ping_count);
99- if (low_pong_count > 0 ) {
100- double low_rtt_avg = (low_rtt_sum. seconds ( ) * 1000.0 / low_pong_count) ;
98+ low_rtts. size () , 100 * low_rtts. size () / ping_count);
99+ if (!low_rtts. empty () ) {
100+ double low_rtt_avg = calc_average (low_rtts ) * 1000.0 ;
101101 RCLCPP_INFO (get_logger (), " Low prio path: Average RTT is %3.1fms." , low_rtt_avg);
102+ double low_rtt_jitter = calc_std_deviation (low_rtts) * 1000.0 ;
103+ RCLCPP_INFO (get_logger (), " Low prio path: Jitter of RTT is %5.3fms." , low_rtt_jitter);
102104 }
103105}
104106
0 commit comments