1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2017 Jesper Dangaard Brouer, Red Hat, Inc. */
3 static const char *__doc__=
4 "XDP monitor tool, based on tracepoints\n";
6 static const char *__doc_err_only__=
7 " NOTICE: Only tracking XDP redirect errors\n"
8 " Enable redirect success stats via '-s/--stats'\n"
9 " (which comes with a per packet processing overhead)\n";
20 #include <sys/resource.h>
26 #include <bpf/libbpf.h>
28 #include "xdp_sample_user.h"
29 #include "xdp_monitor.skel.h"
31 static int mask = SAMPLE_REDIRECT_ERR_CNT | SAMPLE_CPUMAP_ENQUEUE_CNT |
32 SAMPLE_CPUMAP_KTHREAD_CNT | SAMPLE_EXCEPTION_CNT |
33 SAMPLE_DEVMAP_XMIT_CNT | SAMPLE_DEVMAP_XMIT_CNT_MULTI;
35 DEFINE_SAMPLE_INIT(xdp_monitor);
37 static const struct option long_options[] = {
38 { "help", no_argument, NULL, 'h' },
39 { "stats", no_argument, NULL, 's' },
40 { "interval", required_argument, NULL, 'i' },
41 { "verbose", no_argument, NULL, 'v' },
45 int main(int argc, char **argv)
47 unsigned long interval = 2;
48 int ret = EXIT_FAIL_OPTION;
49 struct xdp_monitor *skel;
50 bool errors_only = true;
51 int longindex = 0, opt;
54 /* Parse commands line args */
55 while ((opt = getopt_long(argc, argv, "si:vh",
56 long_options, &longindex)) != -1) {
60 mask |= SAMPLE_REDIRECT_CNT;
63 interval = strtoul(optarg, NULL, 0);
71 sample_usage(argv, long_options, __doc__, mask, error);
76 skel = xdp_monitor__open();
78 fprintf(stderr, "Failed to xdp_monitor__open: %s\n",
84 ret = sample_init_pre_load(skel);
86 fprintf(stderr, "Failed to sample_init_pre_load: %s\n", strerror(-ret));
91 ret = xdp_monitor__load(skel);
93 fprintf(stderr, "Failed to xdp_monitor__load: %s\n", strerror(errno));
98 ret = sample_init(skel, mask);
100 fprintf(stderr, "Failed to initialize sample: %s\n", strerror(-ret));
106 printf("%s", __doc_err_only__);
108 ret = sample_run(interval, NULL, NULL);
110 fprintf(stderr, "Failed during sample run: %s\n", strerror(-ret));
116 xdp_monitor__destroy(skel);