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";
25 #include <bpf/libbpf.h>
27 #include "xdp_sample_user.h"
28 #include "xdp_monitor.skel.h"
30 static int mask = SAMPLE_REDIRECT_ERR_CNT | SAMPLE_CPUMAP_ENQUEUE_CNT |
31 SAMPLE_CPUMAP_KTHREAD_CNT | SAMPLE_EXCEPTION_CNT |
32 SAMPLE_DEVMAP_XMIT_CNT | SAMPLE_DEVMAP_XMIT_CNT_MULTI;
34 DEFINE_SAMPLE_INIT(xdp_monitor);
36 static const struct option long_options[] = {
37 { "help", no_argument, NULL, 'h' },
38 { "stats", no_argument, NULL, 's' },
39 { "interval", required_argument, NULL, 'i' },
40 { "verbose", no_argument, NULL, 'v' },
44 int main(int argc, char **argv)
46 unsigned long interval = 2;
47 int ret = EXIT_FAIL_OPTION;
48 struct xdp_monitor *skel;
49 bool errors_only = true;
50 int longindex = 0, opt;
53 /* Parse commands line args */
54 while ((opt = getopt_long(argc, argv, "si:vh",
55 long_options, &longindex)) != -1) {
59 mask |= SAMPLE_REDIRECT_CNT;
62 interval = strtoul(optarg, NULL, 0);
70 sample_usage(argv, long_options, __doc__, mask, error);
75 skel = xdp_monitor__open();
77 fprintf(stderr, "Failed to xdp_monitor__open: %s\n",
83 ret = sample_init_pre_load(skel);
85 fprintf(stderr, "Failed to sample_init_pre_load: %s\n", strerror(-ret));
90 ret = xdp_monitor__load(skel);
92 fprintf(stderr, "Failed to xdp_monitor__load: %s\n", strerror(errno));
97 ret = sample_init(skel, mask);
99 fprintf(stderr, "Failed to initialize sample: %s\n", strerror(-ret));
105 printf("%s", __doc_err_only__);
107 ret = sample_run(interval, NULL, NULL);
109 fprintf(stderr, "Failed during sample run: %s\n", strerror(-ret));
115 xdp_monitor__destroy(skel);