Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf report: Add -q/--quiet option

The -q/--quiet option is to suppress any message. Sometimes users just
want to see the numbers and it can be used for that case.

Before:

$ perf report | head -15
Failed to open /lib/modules/3.19.3-3-ARCH/kernel/fs/ext4/ext4.ko.gz, continuing without symbols
Failed to open /lib/modules/3.19.3-3-ARCH/kernel/fs/jbd2/jbd2.ko.gz, continuing without symbols
Failed to open /tmp/perf-14507.map, continuing without symbols
...
# To display the perf.data header info, please use --header/--header-only options.
#
#
# Total Lost Samples: 0
#
# Samples: 39K of event 'cycles'
# Event count (approx.): 30444796573
#
# Overhead Command Shared Object Symbol
# ........ ........... ................... .........................
#
9.28% swapper [kernel.vmlinux] [k] intel_idle
5.64% swapper [kernel.vmlinux] [k] native_write_msr_safe
1.93% swapper [kernel.vmlinux] [k] __switch_to
1.89% swapper [kernel.vmlinux] [k] menu_select
1.75% sched-pipe [kernel.vmlinux] [k] __switch_to

After:

$ perf report -q | head
9.28% swapper [kernel.vmlinux] [k] intel_idle
5.64% swapper [kernel.vmlinux] [k] native_write_msr_safe
1.93% swapper [kernel.vmlinux] [k] __switch_to
1.89% swapper [kernel.vmlinux] [k] menu_select
1.75% sched-pipe [kernel.vmlinux] [k] __switch_to
1.67% swapper [kernel.vmlinux] [k] cpu_startup_entry
1.48% sched-pipe [kernel.vmlinux] [k] enqueue_entity
1.46% swapper [kernel.vmlinux] [k] __schedule
1.36% swapper [kernel.vmlinux] [k] native_read_tsc
1.34% sched-pipe [kernel.vmlinux] [k] __schedule

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Suggested-and-Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: kernel-team@lge.com
Link: http://lkml.kernel.org/r/20170217081742.17417-4-namhyung@kernel.org
[ Removed builtin-report.c verbose > 0 hunk added to the previous patch ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Namhyung Kim and committed by
Arnaldo Carvalho de Melo
27fafab5 bb963e16

+19 -4
+4
tools/perf/Documentation/perf-report.txt
··· 25 25 --verbose:: 26 26 Be more verbose. (show symbol address, etc) 27 27 28 + -q:: 29 + --quiet:: 30 + Do not show any message. (Suppress -v) 31 + 28 32 -n:: 29 33 --show-nr-samples:: 30 34 Show the number of samples for each symbol
+15 -4
tools/perf/builtin-report.c
··· 320 320 size_t size = sizeof(buf); 321 321 int socked_id = hists->socket_filter; 322 322 323 + if (quiet) 324 + return 0; 325 + 323 326 if (symbol_conf.filter_relative) { 324 327 nr_samples = hists->stats.nr_non_filtered_samples; 325 328 nr_events = hists->stats.total_non_filtered_period; ··· 375 372 { 376 373 struct perf_evsel *pos; 377 374 378 - fprintf(stdout, "#\n# Total Lost Samples: %" PRIu64 "\n#\n", evlist->stats.total_lost_samples); 375 + if (!quiet) { 376 + fprintf(stdout, "#\n# Total Lost Samples: %" PRIu64 "\n#\n", 377 + evlist->stats.total_lost_samples); 378 + } 379 + 379 380 evlist__for_each_entry(evlist, pos) { 380 381 struct hists *hists = evsel__hists(pos); 381 382 const char *evname = perf_evsel__name(pos); ··· 389 382 continue; 390 383 391 384 hists__fprintf_nr_sample_events(hists, rep, evname, stdout); 392 - hists__fprintf(hists, true, 0, 0, rep->min_percent, stdout, 385 + hists__fprintf(hists, !quiet, 0, 0, rep->min_percent, stdout, 393 386 symbol_conf.use_callchain); 394 387 fprintf(stdout, "\n\n"); 395 388 } ··· 723 716 "input file name"), 724 717 OPT_INCR('v', "verbose", &verbose, 725 718 "be more verbose (show symbol address, etc)"), 719 + OPT_BOOLEAN('q', "quiet", &quiet, "Do not show any message"), 726 720 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, 727 721 "dump raw trace in ASCII"), 728 722 OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name, ··· 871 863 report.symbol_filter_str = argv[0]; 872 864 } 873 865 866 + if (quiet) 867 + perf_quiet_option(); 868 + 874 869 if (symbol_conf.vmlinux_name && 875 870 access(symbol_conf.vmlinux_name, R_OK)) { 876 871 pr_err("Invalid file: %s\n", symbol_conf.vmlinux_name); ··· 994 983 goto error; 995 984 } 996 985 997 - if (report.header || report.header_only) { 986 + if ((report.header || report.header_only) && !quiet) { 998 987 perf_session__fprintf_info(session, stdout, 999 988 report.show_full_info); 1000 989 if (report.header_only) { 1001 990 ret = 0; 1002 991 goto error; 1003 992 } 1004 - } else if (use_browser == 0) { 993 + } else if (use_browser == 0 && !quiet) { 1005 994 fputs("# To display the perf.data header info, please use --header/--header-only options.\n#\n", 1006 995 stdout); 1007 996 }