summaryrefslogtreecommitdiff
path: root/src/xdp/utils
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-12-23 15:22:32 +0100
committerChristian Poessinger <christian@poessinger.com>2020-12-23 15:42:53 +0100
commitc69190bb2b9a3c0f105ea630d328b294aa7810d7 (patch)
tree8ade90f7eb2660b59447f11181f5999861889313 /src/xdp/utils
parent440ce3011e8718c917933026e68047fcfb008031 (diff)
downloadvyos-1x-c69190bb2b9a3c0f105ea630d328b294aa7810d7.tar.gz
vyos-1x-c69190bb2b9a3c0f105ea630d328b294aa7810d7.zip
xdp: op-mode: T2666: support per interface statistics
Diffstat (limited to 'src/xdp/utils')
-rw-r--r--src/xdp/utils/xdp_stats.c49
1 files changed, 26 insertions, 23 deletions
diff --git a/src/xdp/utils/xdp_stats.c b/src/xdp/utils/xdp_stats.c
index 5dbec8351..f9fa7438f 100644
--- a/src/xdp/utils/xdp_stats.c
+++ b/src/xdp/utils/xdp_stats.c
@@ -197,6 +197,7 @@ static int stats_poll(const char *pin_dir, int map_fd, __u32 id,
{
struct bpf_map_info info = {};
struct stats_record prev, record = { 0 };
+ int counter = 0;
/* Trick to pretty printf with thousands separators use %' */
setlocale(LC_NUMERIC, "en_US");
@@ -219,6 +220,10 @@ static int stats_poll(const char *pin_dir, int map_fd, __u32 id,
stats_collect(map_fd, map_type, &record);
stats_print(&record, &prev);
sleep(interval);
+ counter++;
+ if (counter > 1) {
+ return 0;
+ }
}
return 0;
@@ -265,31 +270,29 @@ int main(int argc, char **argv)
return EXIT_FAIL_OPTION;
}
- for ( ;; ) {
- stats_map_fd = open_bpf_map_file(pin_dir, "xdp_stats_map", &info);
- if (stats_map_fd < 0) {
- return EXIT_FAIL_BPF;
- }
-
- /* check map info, e.g. datarec is expected size */
- err = check_map_fd_info(&info, &map_expect);
- if (err) {
- fprintf(stderr, "ERR: map via FD not compatible\n");
- return err;
- }
- if (verbose) {
- printf("\nCollecting stats from BPF map\n");
- printf(" - BPF map (bpf_map_type:%d) id:%d name:%s"
- " key_size:%d value_size:%d max_entries:%d\n",
- info.type, info.id, info.name,
- info.key_size, info.value_size, info.max_entries
- );
- }
+ stats_map_fd = open_bpf_map_file(pin_dir, "xdp_stats_map", &info);
+ if (stats_map_fd < 0) {
+ return EXIT_FAIL_BPF;
+ }
- err = stats_poll(pin_dir, stats_map_fd, info.id, info.type, interval);
- if (err < 0)
- return err;
+ /* check map info, e.g. datarec is expected size */
+ err = check_map_fd_info(&info, &map_expect);
+ if (err) {
+ fprintf(stderr, "ERR: map via FD not compatible\n");
+ return err;
}
+ if (verbose) {
+ printf("\nCollecting stats from BPF map\n");
+ printf(" - BPF map (bpf_map_type:%d) id:%d name:%s"
+ " key_size:%d value_size:%d max_entries:%d\n",
+ info.type, info.id, info.name,
+ info.key_size, info.value_size, info.max_entries
+ );
+ }
+
+ err = stats_poll(pin_dir, stats_map_fd, info.id, info.type, interval);
+ if (err < 0)
+ return err;
return EXIT_OK;
}