[PATCH 14/23] perf list: Add -q/--quiet option

From: Namhyung Kim
Date: Tue Mar 07 2017 - 10:21:46 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.

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

diff --git a/tools/perf/Documentation/perf-list.txt b/tools/perf/Documentation/perf-list.txt
index 41857cce5e86..7964d0e9dc8a 100644
--- a/tools/perf/Documentation/perf-list.txt
+++ b/tools/perf/Documentation/perf-list.txt
@@ -8,7 +8,7 @@ perf-list - List all symbolic event types
SYNOPSIS
--------
[verse]
-'perf list' [--no-desc] [--long-desc] [hw|sw|cache|tracepoint|pmu|event_glob]
+'perf list' <options> [hw|sw|cache|tracepoint|pmu|event_glob]

DESCRIPTION
-----------
@@ -24,6 +24,13 @@ Don't print descriptions.
--long-desc::
Print longer event descriptions.

+-q::
+--quiet::
+ Do not show any message.
+
+--debug::
+ Enable debugging output.
+

[[EVENT_MODIFIERS]]
EVENT MODIFIERS
diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c
index 3b9d98b5feef..b53b3597ee0f 100644
--- a/tools/perf/builtin-list.c
+++ b/tools/perf/builtin-list.c
@@ -32,6 +32,7 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)
"Print longer event descriptions."),
OPT_INCR(0, "debug", &verbose,
"Enable debugging output"),
+ OPT_BOOLEAN('q', "quiet", &quiet, "Do not show any message"),
OPT_END()
};
const char * const list_usage[] = {
@@ -44,9 +45,12 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)
argc = parse_options(argc, argv, list_options, list_usage,
PARSE_OPT_STOP_AT_NON_OPTION);

+ if (quiet)
+ perf_quiet_option();
+
setup_pager();

- if (!raw_dump && pager_in_use())
+ if (!raw_dump && pager_in_use() && !quiet)
printf("\nList of pre-defined events (to be used in -e):\n\n");

if (argc == 0) {
@@ -94,7 +98,8 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)
free(s);
} else {
if (asprintf(&s, "*%s*", argv[i]) < 0) {
- printf("Critical: Not enough memory! Trying to continue...\n");
+ if (!quiet)
+ printf("Critical: Not enough memory! Trying to continue...\n");
continue;
}
print_symbol_events(s, PERF_TYPE_HARDWARE,
--
2.11.0