[PATCH 12/23] perf kmem: Add -q/--quiet option

From: Namhyung Kim
Date: Tue Mar 07 2017 - 10:20:25 EST


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

Before:

# perf kmem stat
Failed to open /usr/lib/libpthread-2.21.so, continuing without symbols
Failed to open /usr/lib/libc-2.21.so, continuing without symbols
Failed to open /lib/modules/3.18.6-1-ARCH/kernel/fs/ext4/ext4.ko.gz, continuing without symbols
SUMMARY (SLAB allocator)
========================
Total bytes requested: 172,628
Total bytes allocated: 173,088
Total bytes freed: 161,280
Net total bytes allocated: 11,808
Total bytes wasted on internal fragmentation: 460
Internal fragmentation: 0.265761%
Cross CPU allocations: 0/851

After:

# perf kmem stat -q
SUMMARY (SLAB allocator)
========================
Total bytes requested: 172,628
Total bytes allocated: 173,088
Total bytes freed: 161,280
Net total bytes allocated: 11,808
Total bytes wasted on internal fragmentation: 460
Internal fragmentation: 0.265761%
Cross CPU allocations: 0/851

Suggested-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxxx>
---
tools/perf/Documentation/perf-kmem.txt | 4 ++++
tools/perf/builtin-kmem.c | 4 ++++
2 files changed, 8 insertions(+)

diff --git a/tools/perf/Documentation/perf-kmem.txt b/tools/perf/Documentation/perf-kmem.txt
index 479fc3261a50..0731389501d4 100644
--- a/tools/perf/Documentation/perf-kmem.txt
+++ b/tools/perf/Documentation/perf-kmem.txt
@@ -29,6 +29,10 @@ OPTIONS
--verbose::
Be more verbose. (show symbol address, etc)

+-q::
+--quiet::
+ Do not show any message.
+
--caller::
Show per-callsite statistics

diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index 6da8d083e4e5..7148137c3a3d 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -1895,6 +1895,7 @@ int cmd_kmem(int argc, const char **argv, const char *prefix __maybe_unused)
OPT_STRING('i', "input", &input_name, "file", "input file name"),
OPT_INCR('v', "verbose", &verbose,
"be more verbose (show symbol address, etc)"),
+ OPT_BOOLEAN('q', "quiet", &quiet, "Do not show any message"),
OPT_CALLBACK_NOOPT(0, "caller", NULL, NULL,
"show per-callsite statistics", parse_caller_opt),
OPT_CALLBACK_NOOPT(0, "alloc", NULL, NULL,
@@ -1932,6 +1933,9 @@ int cmd_kmem(int argc, const char **argv, const char *prefix __maybe_unused)
if (!argc)
usage_with_options(kmem_usage, kmem_options);

+ if (quiet)
+ perf_quiet_option();
+
if (kmem_slab == 0 && kmem_page == 0) {
if (kmem_default == KMEM_SLAB)
kmem_slab = 1;
--
2.11.0