libbpf-tools: Add verbose option to funclatency
Support verbose mode and set custom libbpf print callback
in funclatency.
@@ -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) {
