From: Hengqi Chen Date: Sat, 25 Dec 2021 04:08:41 +0000 (+0800) Subject: libbpf-tools: Add verbose option to funclatency X-Git-Tag: v0.24.0~26^2~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d1b9603c99717345529faf3eb802c2e60916b2ff;p=platform%2Fupstream%2Fbcc.git libbpf-tools: Add verbose option to funclatency Support verbose mode and set custom libbpf print callback in funclatency. Signed-off-by: Hengqi Chen --- diff --git a/libbpf-tools/funclatency.c b/libbpf-tools/funclatency.c index 9e456db9..3ea0fec3 100644 --- a/libbpf-tools/funclatency.c +++ b/libbpf-tools/funclatency.c @@ -35,6 +35,7 @@ static struct prog_env { unsigned int iterations; bool timestamp; char *funcname; + bool verbose; } env = { .interval = 99999999, .iterations = 99999999, @@ -74,6 +75,7 @@ static const struct argp_option opts[] = { { "interval", 'i', "INTERVAL", 0, "Summary interval in seconds"}, { "duration", 'd', "DURATION", 0, "Duration to trace"}, { "timestamp", 'T', NULL, 0, "Print timestamp"}, + { "verbose", 'v', NULL, 0, "Verbose debug output" }, { NULL, 'h', NULL, OPTION_HIDDEN, "Show the full help"}, {}, }; @@ -128,6 +130,9 @@ static error_t parse_arg(int key, char *arg, struct argp_state *state) case 'T': env->timestamp = true; break; + case 'v': + env->verbose = true; + break; case 'h': argp_state_help(state, stderr, ARGP_HELP_STD_HELP); break; @@ -155,6 +160,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 && !env.verbose) + return 0; + return vfprintf(stderr, format, args); +} + static const char *unit_str(void) { switch (env.units) { @@ -285,6 +297,7 @@ int main(int argc, char **argv) sigaction(SIGINT, &sigact, 0); libbpf_set_strict_mode(LIBBPF_STRICT_ALL); + libbpf_set_print(libbpf_print_fn); obj = funclatency_bpf__open(); if (!obj) {