microRTPS: client: show diagnostic of average bandwidth usage on the 'status' option

This commit is contained in:
TSC21
2021-05-05 18:57:49 +02:00
committed by Nuno Marques
parent 40462bfc1f
commit d6ee15596d
3 changed files with 67 additions and 46 deletions
@@ -58,8 +58,9 @@
#define DEFAULT_RECV_PORT 2019
#define DEFAULT_SEND_PORT 2020
void *send(void *data);
void micrortps_start_topics(struct timespec &begin, uint64_t &total_read, uint64_t &received, int &loop);
void *send(void *args);
void micrortps_start_topics(struct timespec &begin, uint64_t &total_read, uint64_t &total_sent, uint64_t &received,
uint64_t &sent, int &rcvd_loop, int &sent_loop);
struct baudtype {
speed_t code;
@@ -55,6 +55,16 @@ bool _should_exit_task = false;
Transport_node *transport_node = nullptr;
struct options _options;
struct timespec begin;
struct timespec end;
uint64_t total_read{0};
uint64_t total_sent{0};
uint64_t received{0};
uint64_t sent{0};
int rcv_loop{0};
int send_loop{0};
static void usage(const char *name)
{
PRINT_MODULE_USAGE_NAME("micrortps_client", "communication");
@@ -179,22 +189,16 @@ static int micrortps_start(int argc, char *argv[])
return -1;
}
struct timespec begin;
struct timespec end;
uint64_t total_read = 0, received = 0;
int loop = 0;
micrortps_start_topics(begin, total_read, received, loop);
micrortps_start_topics(begin, total_read, total_sent, received, sent, rcv_loop, send_loop);
px4_clock_gettime(CLOCK_REALTIME, &end);
double elapsed_secs = static_cast<double>(end.tv_sec - begin.tv_sec + (end.tv_nsec - begin.tv_nsec) / 1e9);
const double elapsed_secs = static_cast<double>(end.tv_sec - begin.tv_sec + (end.tv_nsec - begin.tv_nsec) / 1e9);
PX4_INFO("RECEIVED: %" PRIu64 " messages in %d LOOPS, %" PRIu64 " bytes in %.03f seconds - %.02fKB/s",
received, loop, total_read, elapsed_secs, static_cast<double>(total_read / (1e3 * elapsed_secs)));
PX4_INFO("RECEIVED: %" PRIu64 " messages in %d LOOPS, %" PRIu64 " bytes in %.03f seconds - avg %.02fKB/s",
received, rcv_loop, total_read, elapsed_secs, static_cast<double>(total_read / (1e3 * elapsed_secs)));
PX4_INFO("SENT: %" PRIu64 " messages in %d LOOPS, %" PRIu64 " bytes in %.03f seconds - avg %.02fKB/s",
sent, send_loop, total_sent, elapsed_secs, total_sent / (1e3 * elapsed_secs));
delete transport_node;
@@ -243,7 +247,18 @@ int micrortps_client_main(int argc, char *argv[])
PX4_INFO("Not running");
} else {
PX4_INFO("Running");
px4_clock_gettime(CLOCK_REALTIME, &end);
const double elapsed_secs = static_cast<double>(end.tv_sec - begin.tv_sec + (end.tv_nsec - begin.tv_nsec) / 1e9);
printf("\tup and running for %.03f seconds\n", elapsed_secs);
printf("\tnr. of messages received: %" PRIu64 "\n", received);
printf("\tnr. of messages sent: %" PRIu64 "\n", sent);
printf("\ttotal data read: %" PRIu64 " bytes\n", total_read);
printf("\ttotal data sent: %" PRIu64 " bytes\n", total_sent);
printf("\trates:\n");
printf("\t avg rx: %.3f kB/s\n", static_cast<double>(total_read / (1e3 * elapsed_secs)));
printf("\t avg tx: %.3f kB/s\n", static_cast<double>(total_sent / (1e3 * elapsed_secs)));
}
return 0;