| 1 | // SPDX-License-Identifier: BSD-2-Clause |
| 2 | /* |
| 3 | * Copyright (C) 2025 Linutronix GmbH |
| 4 | * Author Kurt Kanzenbach <[email protected]> |
| 5 | */ |
| 6 | |
| 7 | #include <stdio.h> |
| 8 | #include <unistd.h> |
| 9 | |
| 10 | #include "config.h" |
| 11 | #include "print.h" |
| 12 | #include "stat.h" |
| 13 | |
| 14 | volatile int print_stop = 0; |
| 15 | |
| 16 | void print_stats(void) |
| 17 | { |
| 18 | while (!print_stop) { |
| 19 | struct statistics global_statistics[NUM_FRAME_TYPES]; |
| 20 | int active = 0; |
| 21 | |
| 22 | stat_get_global_stats(global_statistics, sizeof(global_statistics)); |
| 23 | |
| 24 | for (int i = 0; i < NUM_FRAME_TYPES; i++) { |
| 25 | const char *name = i == GENERICL2_FRAME_TYPE |
| 26 | ? app_config.classes[GENERICL2_FRAME_TYPE].name |
| 27 | : stat_frame_type_to_string(i); |
| 28 | const struct statistics *stat = &global_statistics[i]; |
| 29 | uint64_t errors; |
| 30 | |
| 31 | errors = stat->frame_id_errors + stat->out_of_order_errors + |
| 32 | stat->payload_errors; |
| 33 | |
| 34 | if (config_is_traffic_class_active(stat_frame_type_to_string(i))) { |
| 35 | printf("%-8s: Tx:%10" PRIu64 " Rx:%10" PRIu64 |
| 36 | " RttMin[us]:%10" PRIu64 |
| 37 | " RttAvg[us]:%10lf RttMax[us]:%10" PRIu64 " Err:%8" PRIu64 |
| 38 | " Outlier:%8" PRIu64 "\n", |
| 39 | name, stat->frames_sent, stat->frames_received, |
| 40 | stat->round_trip_min, stat->round_trip_avg, |
| 41 | stat->round_trip_max, errors, stat->round_trip_outliers); |
| 42 | ++active; |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | printf("-------------------------------------------------------------------" |
| 47 | "-------------\n"); |
| 48 | |
| 49 | printf("\033[%dA", active + 1); |
| 50 | |
| 51 | sleep(1); |
| 52 | } |
| 53 | } |