Skip to content

Commit

Permalink
libbpf-tools/klockstat: Add verbose option
Browse files Browse the repository at this point in the history
Add -v(--verbose) option to klockstat to display libbpf log

Signed-off-by: Eunseon Lee <[email protected]>
  • Loading branch information
ekyooo authored and yonghong-song committed Feb 25, 2022
1 parent 3a03901 commit 87e73ab
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion libbpf-tools/klockstat.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ static struct prog_env {
unsigned int iterations;
bool reset;
bool timestamp;
bool verbose;
} env = {
.nr_locks = 99999999,
.nr_stack_entries = 1,
Expand All @@ -70,7 +71,7 @@ static const char args_doc[] = "FUNCTION";
static const char program_doc[] =
"Trace mutex lock acquisition and hold times, in nsec\n"
"\n"
"Usage: klockstat [-hRT] [-p PID] [-t TID] [-c FUNC] [-L LOCK] [-n NR_LOCKS]\n"
"Usage: klockstat [-hRTv] [-p PID] [-t TID] [-c FUNC] [-L LOCK] [-n NR_LOCKS]\n"
" [-s NR_STACKS] [-S SORT] [-d DURATION] [-i INTERVAL]\n"
"\v"
"Examples:\n"
Expand Down Expand Up @@ -104,6 +105,7 @@ static const struct argp_option opts[] = {
{ "interval", 'i', "SECONDS", 0, "Print interval" },
{ "reset", 'R', NULL, 0, "Reset stats each interval" },
{ "timestamp", 'T', NULL, 0, "Print timestamp" },
{ "verbose", 'v', NULL, 0, "Verbose debug output" },

{ NULL, 'h', NULL, OPTION_HIDDEN, "Show the full help" },
{},
Expand Down Expand Up @@ -230,6 +232,9 @@ static error_t parse_arg(int key, char *arg, struct argp_state *state)
case 'h':
argp_state_help(state, stderr, ARGP_HELP_STD_HELP);
break;
case 'v':
env->verbose = true;
break;
case ARGP_KEY_END:
if (env->duration) {
if (env->interval > env->duration)
Expand Down Expand Up @@ -471,6 +476,13 @@ static void sig_hand(int signr)

static struct sigaction sigact = {.sa_handler = sig_hand};

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);
}

int main(int argc, char **argv)
{
static const struct argp argp = {
Expand All @@ -494,6 +506,7 @@ int main(int argc, char **argv)
sigaction(SIGINT, &sigact, 0);

libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
libbpf_set_print(libbpf_print_fn);

ksyms = ksyms__load();
if (!ksyms) {
Expand Down

0 comments on commit 87e73ab

Please sign in to comment.