From fa355cc21448e92a07c1bb93896dd8a71022fe13 Mon Sep 17 00:00:00 2001 From: Hengqi Chen Date: Sat, 25 Dec 2021 12:07:56 +0800 Subject: [PATCH] libbpf-tools: Add verbose option to filetop Support verbose mode and set custom libbpf print callback in filetop. Signed-off-by: Hengqi Chen --- libbpf-tools/filetop.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/libbpf-tools/filetop.c b/libbpf-tools/filetop.c index 1d2f5224..70240d85 100644 --- a/libbpf-tools/filetop.c +++ b/libbpf-tools/filetop.c @@ -42,6 +42,7 @@ static int output_rows = 20; static int sort_by = ALL; static int interval = 1; static int count = 99999999; +static bool verbose = false; const char *argp_program_version = "filetop 0.1"; const char *argp_program_bug_address = @@ -62,6 +63,7 @@ static const struct argp_option opts[] = { { "all", 'a', NULL, 0, "Include special files" }, { "sort", 's', "SORT", 0, "Sort columns, default all [all, reads, writes, rbytes, wbytes]" }, { "rows", 'r', "ROWS", 0, "Maximum rows to print, default 20" }, + { "verbose", 'v', NULL, 0, "Verbose debug output" }, { NULL, 'h', NULL, OPTION_HIDDEN, "Show the full help" }, {}, }; @@ -114,6 +116,9 @@ static error_t parse_arg(int key, char *arg, struct argp_state *state) if (output_rows > OUTPUT_ROWS_LIMIT) output_rows = OUTPUT_ROWS_LIMIT; break; + case 'v': + verbose = true; + break; case 'h': argp_state_help(state, stderr, ARGP_HELP_STD_HELP); break; @@ -143,6 +148,13 @@ static error_t parse_arg(int key, char *arg, struct argp_state *state) return 0; } +static int libbpf_print_fn(enum libbpf_print_level level, const char *format, va_list args) +{ + if (level == LIBBPF_DEBUG && !verbose) + return 0; + return vfprintf(stderr, format, args); +} + static void sig_int(int signo) { exiting = 1; @@ -257,6 +269,7 @@ int main(int argc, char **argv) return err; libbpf_set_strict_mode(LIBBPF_STRICT_ALL); + libbpf_set_print(libbpf_print_fn); obj = filetop_bpf__open(); if (!obj) { -- 2.34.1