Skip to contentSkip to conversation

perf tools: Add -q/--quiet option

PATCH Applied Namhyung Kim 4 participants 32 messages Mar 7, 2017 – Mar 15, 2017 perf events

lore
Share & tools
lore

Namhyung Kim

author maintainer
#0 lore raw

cover perf tools: Add -q/--quiet option

Hello,

This patchset adds -q/--quiet option for most commands. I skipped commands missing -v/--verbose option. While the -q option in this patchset just suppresses warning messages, some command might want to mute other outputs too. I added a few obvious ones and if you have some thought, please let me know.

The patch 1, 4 and 5 are fixes and can be applied separately.

The code is available on the 'perf/quiet-v2' branche on my tree

git://git.kernel.org/pub/scm/linux/kernel/git/namhyung/linux-perf.git

Thanks,
Namhyung

Namhyung Kim (23):
perf report: Hide tip message when -q option is given perf buildid-cache: Add -q/--quiet option perf buildid-list: Add -q/--quiet option perf c2c: Fix help message of --stats option perf c2c: Fix display bug when using pipe perf c2c: Add -q/--quiet option
perf data: Add -q/--quiet option
perf evlist: Add -q/--quiet option
perf ftrace: Add -q/--quiet option
perf inject: Add -q/--quiet option
perf kallsyms: Add -q/--quiet option
perf kmem: Add -q/--quiet option
perf kvm: Add -q/--quiet option
perf list: Add -q/--quiet option
perf lock: Add -q/--quiet option
perf mem: Add -q/--quiet option
perf sched: Add -q/--quiet option
perf script: Use pr_err() for error messages perf script: Add -q/--quiet option
perf stat: Use pr_err() for error messages perf stat: Add -q/--quiet option
perf top: Add -q/--quiet option
perf trace: Add -q/--quiet option

 tools/perf/Documentation/perf-buildid-cache.txt |  4 ++
 tools/perf/Documentation/perf-buildid-list.txt  |  3 ++
 tools/perf/Documentation/perf-c2c.txt           |  8 ++++
 tools/perf/Documentation/perf-data.txt          |  4 ++
 tools/perf/Documentation/perf-evlist.txt        |  4 ++
 tools/perf/Documentation/perf-ftrace.txt        |  4 ++
 tools/perf/Documentation/perf-inject.txt        |  3 ++
 tools/perf/Documentation/perf-kallsyms.txt      |  4 ++
 tools/perf/Documentation/perf-kmem.txt          |  4 ++
 tools/perf/Documentation/perf-kvm.txt           |  3 ++
 tools/perf/Documentation/perf-list.txt          |  9 +++-
 tools/perf/Documentation/perf-lock.txt          |  8 ++++
 tools/perf/Documentation/perf-mem.txt           |  8 ++++
 tools/perf/Documentation/perf-sched.txt         |  8 ++++
 tools/perf/Documentation/perf-script.txt        |  8 ++++
 tools/perf/Documentation/perf-stat.txt          |  4 ++
 tools/perf/Documentation/perf-top.txt           |  4 ++
 tools/perf/Documentation/perf-trace.txt         |  4 ++
 tools/perf/builtin-buildid-cache.c              |  4 ++
 tools/perf/builtin-buildid-list.c               |  4 ++
 tools/perf/builtin-c2c.c                        | 16 +++++--
 tools/perf/builtin-data.c                       |  4 ++
 tools/perf/builtin-evlist.c                     |  8 +++-
 tools/perf/builtin-ftrace.c                     |  7 ++-
 tools/perf/builtin-inject.c                     | 10 ++++-
 tools/perf/builtin-kallsyms.c                   |  7 ++-
 tools/perf/builtin-kmem.c                       |  4 ++
 tools/perf/builtin-kvm.c                        | 10 ++++-
 tools/perf/builtin-list.c                       |  9 +++-
 tools/perf/builtin-lock.c                       | 33 ++++++++------
 tools/perf/builtin-mem.c                        |  6 ++-
 tools/perf/builtin-report.c                     |  3 +-
 tools/perf/builtin-sched.c                      | 12 +++++
 tools/perf/builtin-script.c                     | 45 ++++++++++---------
 tools/perf/builtin-stat.c                       | 59 ++++++++++++++++---------
 tools/perf/builtin-top.c                        |  6 ++-
 tools/perf/builtin-trace.c                      | 33 +++++++++-----
 37 files changed, 291 insertions(+), 83 deletions(-)
Signature · 1 line
2.11.0
author maintainer
#1 lore raw

PATCH 1/23 perf report: Hide tip message when -q option is given

The tip message at the end was printed regardless of the -q option. Originally, the message suggested only '-s comm,dso' option for higher level view when no sort option and parent option were given. Now it shows random help message regardless of the options so the condition can be simplified to honor the -q option.

---
 tools/perf/builtin-report.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
tools/perf/builtin-report.c +1 -2
index 0a88670e56f3..f03a5eac2a62 100644
@@ -394,8 +394,7 @@ static int perf_evlist__tty_browse_hists(struct perf_evlist *evlist,
 		fprintf(stdout, "\n\n");
 	}
 
-	if (sort_order == NULL &&
-	    parent_pattern == default_parent_pattern)
+	if (!quiet)
 		fprintf(stdout, "#\n# (%s)\n#\n", help);
 
 	if (rep->show_threads) {
Signature · 1 line
2.11.0
maintainer Applied
#2 lore raw

Re: [PATCH 01/23] perf report: Hide tip message when -q option is given

Em Wed, Mar 08, 2017 at 12:08:29AM +0900, Namhyung Kim escreveu:

Quoted 6 lines

The tip message at the end was printed regardless of the -q option. Originally, the message suggested only '-s comm,dso' option for higher level view when no sort option and parent option were given. Now it shows random help message regardless of the options so the condition can be simplified to honor the -q option.

Applied, with this:

Before:

  $ perf report --stdio -q
    42.77%  ls       ls                [.] _init
    13.21%  ls       ld-2.24.so        [.] match_symbol
    12.55%  ls       libc-2.24.so      [.] __strcoll_l
    11.94%  ls       libc-2.24.so      [.] _init

#
# (Tip: Show current config key-value pairs: perf config --list) #
$

After:

  $ perf report --stdio -q
    42.77%  ls       ls                [.] _init
    13.21%  ls       ld-2.24.so        [.] match_symbol
    12.55%  ls       libc-2.24.so      [.] __strcoll_l
    11.94%  ls       libc-2.24.so      [.] _init

$

We still have those two extra lines tho, food for another patch...

#3 lore raw

[tip:perf/core] perf report: Hide tip message when -q option is given

In reply to Namhyung Kim
perf report: Hide tip message when -q option is given
Commit-ID:  8b53dbef2aeaad6bf532bd4db2f4b2beefd42e49
Gitweb:     http://git.kernel.org/tip/8b53dbef2aeaad6bf532bd4db2f4b2beefd42e49
Author:     Namhyung Kim <[email protected]>
AuthorDate: Wed, 8 Mar 2017 00:08:29 +0900
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Tue, 7 Mar 2017 12:25:27 -0300

perf report: Hide tip message when -q option is given

The tip message at the end was printed regardless of the -q option.

Originally, the message suggested only '-s comm,dso' option for higher level view when no sort option and parent option were given.

Now it shows random help message regardless of the options so the condition can be simplified to honor the -q option.

Committer notes:

Before:

  $ perf report --stdio -q
    42.77%  ls       ls                [.] _init
    13.21%  ls       ld-2.24.so        [.] match_symbol
    12.55%  ls       libc-2.24.so      [.] __strcoll_l
    11.94%  ls       libc-2.24.so      [.] _init

#
# (Tip: Show current config key-value pairs: perf config --list) #
$

After:

  $ perf report --stdio -q
    42.77%  ls       ls                [.] _init
    13.21%  ls       ld-2.24.so        [.] match_symbol
    12.55%  ls       libc-2.24.so      [.] __strcoll_l
    11.94%  ls       libc-2.24.so      [.] _init

$

We still have those two extra lines tho (that git commit insists in turning into one, or git commit --amend doesn't make me add), food for another patch...

---
 tools/perf/builtin-report.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
tools/perf/builtin-report.c +1 -2
index 0a88670..f03a5ea 100644
@@ -394,8 +394,7 @@ static int perf_evlist__tty_browse_hists(struct perf_evlist *evlist,
 		fprintf(stdout, "\n\n");
 	}
 
-	if (sort_order == NULL &&
-	    parent_pattern == default_parent_pattern)
+	if (!quiet)
 		fprintf(stdout, "#\n# (%s)\n#\n", help);
 
 	if (rep->show_threads) {
author maintainer
#4 lore raw

PATCH 2/23 perf buildid-cache: Add -q/--quiet option

In reply to Namhyung Kim

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.

---
 tools/perf/Documentation/perf-buildid-cache.txt | 4 ++++
 tools/perf/builtin-buildid-cache.c              | 4 ++++
 2 files changed, 8 insertions(+)
tools/perf/Documentation/perf-buildid-cache.txt +4 -0
index 058064db39d2..b9c2f8c9fcef 100644
@@ -61,6 +61,10 @@ OPTIONS
 --verbose::
 	Be more verbose.
 
+-q::
+--quiet::
+	Do not show any message.
+
 SEE ALSO
 --------
 linkperf:perf-record[1], linkperf:perf-report[1], linkperf:perf-buildid-list[1]
tools/perf/builtin-buildid-cache.c +4 -0
index 30e2b2cb2421..ff437a678976 100644
@@ -311,6 +311,7 @@ int cmd_buildid_cache(int argc, const char **argv,
 	OPT_STRING('u', "update", &update_name_list_str, "file list",
 		    "file(s) to update"),
 	OPT_INCR('v', "verbose", &verbose, "be more verbose"),
+	OPT_BOOLEAN('q', "quiet", &quiet, "Do not show any message"),
 	OPT_END()
 	};
 	const char * const buildid_cache_usage[] = {
@@ -326,6 +327,9 @@ int cmd_buildid_cache(int argc, const char **argv,
 		     !missing_filename && !update_name_list_str))
 		usage_with_options(buildid_cache_usage, buildid_cache_options);
 
+	if (quiet)
+		perf_quiet_option();
+
 	if (missing_filename) {
 		file.path = missing_filename;
 		file.force = force;
Signature · 1 line
2.11.0
#5 lore raw

Re: [PATCH 02/23] perf buildid-cache: Add -q/--quiet option

Em Wed, Mar 08, 2017 at 12:08:30AM +0900, Namhyung Kim escreveu:

Quoted 2 lines

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.

<SNIP>

tools/perf/builtin-buildid-cache.c int cmd_buildid_cache(int argc, const char **argv, · line 330

Quoted 12 lines

+++ b/tools/perf/builtin-buildid-cache.c

tools/perf/builtin-buildid-cache.c +4 -0
@@ -311,6 +311,7 @@ int cmd_buildid_cache(int argc, const char **argv,
 	OPT_INCR('v', "verbose", &verbose, "be more verbose"),
+	OPT_BOOLEAN('q', "quiet", &quiet, "Do not show any message"),
 	OPT_END()
 	};
 	const char * const buildid_cache_usage[] = {
@@ -326,6 +327,9 @@ int cmd_buildid_cache(int argc, const char **argv,
 
+	if (quiet)
+		perf_quiet_option();
+

Hey, I see that this is done lots of times, can't we use that parent option stuff? Or some fallback we can have in perf's main() for thing like this?

- Arnaldo

author maintainer
#6 lore raw

Re: [PATCH 02/23] perf buildid-cache: Add -q/--quiet option

Hi Arnaldo,

Quoted 15 lines · Arnaldo Carvalho de Melo

Em Wed, Mar 08, 2017 at 12:08:30AM +0900, Namhyung Kim escreveu:

Quoted 2 lines

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.

<SNIP>

Quoted 9 lines

+++ b/tools/perf/builtin-buildid-cache.c

tools/perf/builtin-buildid-cache.c +1 -0
@@ -311,6 +311,7 @@ int cmd_buildid_cache(int argc, const char **argv,
      OPT_INCR('v', "verbose", &verbose, "be more verbose"),
+     OPT_BOOLEAN('q', "quiet", &quiet, "Do not show any message"),
      OPT_END()
      };
      const char * const buildid_cache_usage[] = {
@@ -326,6 +327,9 @@ int cmd_buildid_cache(int argc, const char **argv,
 
Quoted 7 lines

tools/perf/builtin-buildid-cache.c int cmd_buildid_cache(int argc, const char **argv, · line 332

Quoted 3 lines
tools/perf/builtin-buildid-cache.c +3 -0
+     if (quiet)
+             perf_quiet_option();
+

Hey, I see that this is done lots of times, can't we use that parent option stuff? Or some fallback we can have in perf's main() for thing like this?

I thought about it. But perf main option handling is different from command options. Also it needs to be called after option parsing is done to overwrite 'verbose' properly.

Thanks,
Namhyung

author maintainer
#7 lore raw

PATCH 3/23 perf buildid-list: Add -q/--quiet option

In reply to Namhyung Kim

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 buildid-list -H
  No kallsyms or vmlinux with build-id 0dde46afc62ef46be224391d5c64379f984901e5 was found
  /lib/modules/4.8.3-1-ARCH/build/vmlinux with build id 0dde46afc62ef46be224391d5c64379f984901e5 not found, continuing without symbols
  Failed to open /lib/modules/4.8.3-1-ARCH/kernel/drivers/ata/libata.ko.gz, continuing without symbols
  0dde46afc62ef46be224391d5c64379f984901e5 /lib/modules/4.8.3-1-ARCH/build/vmlinux
  2524206aeba0015f174f320fad4b301a59ac311d /home/namhyung/project/linux/tools/perf/perf
  c778954ffb0e2239cd454d40c9de504e8601d990 /usr/lib/ld-2.24.so
  13d24a5495ae34f58e52403f9153263488b62cf4 /usr/lib/libpthread-2.24.so
  17ec69093fc89b16363635ea7f76f46145a08384 /usr/lib/libdl-2.24.so
  ...

After:

  $ perf buildid-list -H -q
  0dde46afc62ef46be224391d5c64379f984901e5 /lib/modules/4.8.3-1-ARCH/build/vmlinux
  2524206aeba0015f174f320fad4b301a59ac311d /home/namhyung/project/linux/tools/perf/perf
  c778954ffb0e2239cd454d40c9de504e8601d990 /usr/lib/ld-2.24.so
  13d24a5495ae34f58e52403f9153263488b62cf4 /usr/lib/libpthread-2.24.so
  17ec69093fc89b16363635ea7f76f46145a08384 /usr/lib/libdl-2.24.so
  ...
---
 tools/perf/Documentation/perf-buildid-list.txt | 3 +++
 tools/perf/builtin-buildid-list.c              | 4 ++++
 2 files changed, 7 insertions(+)
tools/perf/Documentation/perf-buildid-list.txt +3 -0
index 25c52efcc7f0..a892f883d8b5 100644
@@ -36,6 +36,9 @@ OPTIONS
 -v::
 --verbose::
 	Be more verbose.
+-q::
+--quiet::
+	Do not show any message.
 
 SEE ALSO
 --------
tools/perf/builtin-buildid-list.c +4 -0
index 5e914ee79eb3..6fc2a2fe6627 100644
@@ -99,6 +99,7 @@ int cmd_buildid_list(int argc, const char **argv,
 	OPT_BOOLEAN('f', "force", &force, "don't complain, do it"),
 	OPT_BOOLEAN('k', "kernel", &show_kernel, "Show current kernel build id"),
 	OPT_INCR('v', "verbose", &verbose, "be more verbose"),
+	OPT_BOOLEAN('q', "quiet", &quiet, "Do not show any message"),
 	OPT_END()
 	};
 	const char * const buildid_list_usage[] = {
@@ -109,6 +110,9 @@ int cmd_buildid_list(int argc, const char **argv,
 	argc = parse_options(argc, argv, options, buildid_list_usage, 0);
 	setup_pager();
 
+	if (quiet)
+		perf_quiet_option();
+
 	if (show_kernel)
 		return !(sysfs__fprintf_build_id(stdout) > 0);
 
Signature · 1 line
2.11.0
author maintainer
#8 lore raw

PATCH 4/23 perf c2c: Fix help message of --stats option

In reply to Namhyung Kim
---
 tools/perf/builtin-c2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/builtin-c2c.c +1 -1
index e2b21723bbf8..3fac30ed92f1 100644
@@ -2536,7 +2536,7 @@ static int perf_c2c__report(int argc, const char **argv)
 	OPT_BOOLEAN(0, "stdio", &c2c.use_stdio, "Use the stdio interface"),
 #endif
 	OPT_BOOLEAN(0, "stats", &c2c.stats_only,
-		    "Use the stdio interface"),
+		    "Display only statistic tables (implies --stdio)"),
 	OPT_BOOLEAN(0, "full-symbols", &c2c.symbol_full,
 		    "Display full length of symbols"),
 	OPT_BOOLEAN(0, "no-source", &no_source,
Signature · 1 line
2.11.0
#9 lore raw

[tip:perf/core] perf c2c: Clarify help message of --stats option

perf c2c: Clarify help message of --stats option
Commit-ID:  f75d2895e053efb2a69194d98754e4d5f4fa3a28
Gitweb:     http://git.kernel.org/tip/f75d2895e053efb2a69194d98754e4d5f4fa3a28
Author:     Namhyung Kim <[email protected]>
AuthorDate: Wed, 8 Mar 2017 00:08:32 +0900
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Tue, 7 Mar 2017 12:48:41 -0300

perf c2c: Clarify help message of --stats option

As it is not strictly asking for only stdio output, but will imply using it.

---
 tools/perf/builtin-c2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/builtin-c2c.c +1 -1
index e2b2172..3fac30e 100644
@@ -2536,7 +2536,7 @@ static int perf_c2c__report(int argc, const char **argv)
 	OPT_BOOLEAN(0, "stdio", &c2c.use_stdio, "Use the stdio interface"),
 #endif
 	OPT_BOOLEAN(0, "stats", &c2c.stats_only,
-		    "Use the stdio interface"),
+		    "Display only statistic tables (implies --stdio)"),
 	OPT_BOOLEAN(0, "full-symbols", &c2c.symbol_full,
 		    "Display full length of symbols"),
 	OPT_BOOLEAN(0, "no-source", &no_source,
author maintainer
#10 lore raw

PATCH 5/23 perf c2c: Fix display bug when using pipe

In reply to Namhyung Kim

Currently perf c2c report determines display mode using --stdio option, but it could be a problem if the stdout is not a tty since setup_browser falls back to stdio in this case. But perf c2c didn't know this and tried to use TUI browser anyway. It should check "use_browser" variable instead.

For example, the following command showed nothing and broke terminal setting. Now it's fixed..

  $ perf c2c report | head
  =================================================
              Trace Event Information
  =================================================
    Total records                     :        136
    Locked Load/Store Operations      :          6
    Load Operations                   :         62
    Loads - uncacheable               :          0
    Loads - IO                        :          1
    Loads - Miss                      :          7
    Loads - no mapping                :          2
---
 tools/perf/builtin-c2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/builtin-c2c.c +1 -1
index 3fac30ed92f1..5cd6d7a047b9 100644
@@ -2334,7 +2334,7 @@ static int perf_c2c__hists_browse(struct hists *hists)
 
 static void perf_c2c_display(struct perf_session *session)
 {
-	if (c2c.use_stdio)
+	if (use_browser == 0)
 		perf_c2c__hists_fprintf(stdout, session);
 	else
 		perf_c2c__hists_browse(&c2c.hists.hists);
Signature · 1 line
2.11.0
#11 lore raw

[tip:perf/core] perf c2c: Fix display bug when using pipe

perf c2c: Fix display bug when using pipe
Commit-ID:  1936feae54a6724a27a6ca1b948fd0e80371f7b0
Gitweb:     http://git.kernel.org/tip/1936feae54a6724a27a6ca1b948fd0e80371f7b0
Author:     Namhyung Kim <[email protected]>
AuthorDate: Wed, 8 Mar 2017 00:08:33 +0900
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Tue, 7 Mar 2017 12:48:46 -0300

perf c2c: Fix display bug when using pipe

Currently 'perf c2c report' determines display mode using the --stdio option, but it could be a problem if stdout is not a tty since setup_browser falls back to stdio in this case.

But perf c2c didn't know this and tried to use TUI browser anyway. It should check "use_browser" variable instead.

For example, the following command showed nothing and broke terminal setting. Now it's fixed..

  $ perf c2c report | head
  =================================================
              Trace Event Information
  =================================================
    Total records                     :        136
    Locked Load/Store Operations      :          6
    Load Operations                   :         62
    Loads - uncacheable               :          0
    Loads - IO                        :          1
    Loads - Miss                      :          7
    Loads - no mapping                :          2

Committer notes:

When trying it without a proper perf.data file it results in a stuck terminal, just as Namhyung reported above:

[acme@jouet ~]$ perf c2c report | head
WARNING: no sample cpu value[acme@jouet ~]$

One has to kill it from some other xterm. Confirm that this patch fixes it:

After:

  $ perf c2c report | head
  WARNING: no sample cpu value=================================================
              Trace Event Information
  =================================================
    Total records                     :         14
    Locked Load/Store Operations      :          0
    Load Operations                   :          0
    Loads - uncacheable               :          0
    Loads - IO                        :          0
    Loads - Miss                      :          0
    Loads - no mapping                :          0
  $
---
 tools/perf/builtin-c2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/builtin-c2c.c +1 -1
index 3fac30e..5cd6d7a 100644
@@ -2334,7 +2334,7 @@ out:
 
 static void perf_c2c_display(struct perf_session *session)
 {
-	if (c2c.use_stdio)
+	if (use_browser == 0)
 		perf_c2c__hists_fprintf(stdout, session);
 	else
 		perf_c2c__hists_browse(&c2c.hists.hists);
author maintainer
#12 lore raw

PATCH 6/23 perf c2c: Add -q/--quiet option

In reply to Namhyung Kim

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 c2c report | head
  /usr/lib/mutter/libmutter-clutter-1.0.so with build id 32c8c08c8720ccc486a9b2d6169c8ef121652074 not found, continuing without symbols
  /usr/lib/mutter/libmutter-cogl-1.0.so with build id c490779d992d60a58a8ddfa15bbe9b4a9c22749f not found, continuing without symbols
  ...
  =================================================
              Trace Event Information
  =================================================
    Total records                     :        136
    Locked Load/Store Operations      :          6
    Load Operations                   :         62
    Loads - uncacheable               :          0
    Loads - IO                        :          1
    Loads - Miss                      :          7
    Loads - no mapping                :          2

After:

  $ perf c2c report -q | head
  =================================================
              Trace Event Information
  =================================================
    Total records                     :        136
    Locked Load/Store Operations      :          6
    Load Operations                   :         62
    Loads - uncacheable               :          0
    Loads - IO                        :          1
    Loads - Miss                      :          7
    Loads - no mapping                :          2
---
 tools/perf/Documentation/perf-c2c.txt |  8 ++++++++
 tools/perf/builtin-c2c.c              | 12 ++++++++++--
 2 files changed, 18 insertions(+), 2 deletions(-)
tools/perf/Documentation/perf-c2c.txt +8 -0
index 2da07e51e119..5f529c810e43 100644
@@ -44,6 +44,10 @@ RECORD OPTIONS
 --verbose::
 	Be more verbose (show counter open errors, etc).
 
+-q::
+--quiet::
+	Do not show any message.
+
 -l::
 --ldlat::
 	Configure mem-loads latency.
@@ -66,6 +70,10 @@ REPORT OPTIONS
 --verbose::
 	Be more verbose (show counter open errors, etc).
 
+-q::
+--quiet::
+	Do not show any message.
+
 -i::
 --input::
 	Specify the input file to process.
tools/perf/builtin-c2c.c +10 -2
index 5cd6d7a047b9..211f9f29620c 100644
@@ -103,6 +103,7 @@ static const char *display_str[DISPLAY_MAX] = {
 
 static const struct option c2c_options[] = {
 	OPT_INCR('v', "verbose", &verbose, "be more verbose (show counter open errors, etc)"),
+	OPT_BOOLEAN('q', "quiet", &quiet, "Do not show any message"),
 	OPT_END()
 };
 
@@ -184,7 +185,7 @@ he__get_c2c_hists(struct hist_entry *he,
 static void c2c_he__set_cpu(struct c2c_hist_entry *c2c_he,
 			    struct perf_sample *sample)
 {
-	if (WARN_ONCE(sample->cpu == (unsigned int) -1,
+	if (WARN_ONCE((sample->cpu == (unsigned int) -1) && !quiet,
 		      "WARNING: no sample cpu value"))
 		return;
 
@@ -1932,7 +1933,8 @@ static int setup_nodes(struct perf_session *session)
 		for (cpu = 0; cpu < map->nr; cpu++) {
 			set_bit(map->map[cpu], set);
 
-			if (WARN_ONCE(cpu2node[map->map[cpu]] != -1, "node/cpu topology bug"))
+			if (WARN_ONCE((cpu2node[map->map[cpu]] != -1) && !quiet,
+				      "node/cpu topology bug"))
 				return -EINVAL;
 
 			cpu2node[map->map[cpu]] = node;
@@ -2561,6 +2563,9 @@ static int perf_c2c__report(int argc, const char **argv)
 	if (argc)
 		usage_with_options(report_c2c_usage, options);
 
+	if (quiet)
+		perf_quiet_option();
+
 	if (c2c.stats_only)
 		c2c.use_stdio = true;
 
@@ -2707,6 +2712,9 @@ static int perf_c2c__record(int argc, const char **argv)
 	if (!rec_argv)
 		return -1;
 
+	if (quiet)
+		perf_quiet_option();
+
 	rec_argv[i++] = "record";
 
 	if (!event_set) {
Signature · 1 line
2.11.0
author maintainer
#13 lore raw

PATCH 7/23 perf data: Add -q/--quiet option

In reply to Namhyung Kim

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.

---
 tools/perf/Documentation/perf-data.txt | 4 ++++
 tools/perf/builtin-data.c              | 4 ++++
 2 files changed, 8 insertions(+)
tools/perf/Documentation/perf-data.txt +4 -0
index f0796a47dfa3..a063c6e83d99 100644
@@ -34,6 +34,10 @@ OPTIONS for 'convert'
 --verbose::
         Be more verbose (show counter open errors, etc).
 
+-q::
+--quiet::
+	Do not show any message.
+
 --all::
 	Convert all events, including non-sample events (comm, fork, ...), to output.
 	Default is off, only convert samples.
tools/perf/builtin-data.c +4 -0
index 7ad6e17ac6b3..895cc2fefa7d 100644
@@ -60,6 +60,7 @@ static int cmd_data_convert(int argc, const char **argv,
 	};
 	const struct option options[] = {
 		OPT_INCR('v', "verbose", &verbose, "be more verbose"),
+		OPT_BOOLEAN('q', "quiet", &quiet, "Do not show any message"),
 		OPT_STRING('i', "input", &input_name, "file", "input file name"),
 #ifdef HAVE_LIBBABELTRACE_SUPPORT
 		OPT_STRING(0, "to-ctf", &to_ctf, NULL, "Convert to CTF format"),
@@ -81,6 +82,9 @@ static int cmd_data_convert(int argc, const char **argv,
 		return -1;
 	}
 
+	if (quiet)
+		perf_quiet_option();
+
 	if (to_ctf) {
 #ifdef HAVE_LIBBABELTRACE_SUPPORT
 		return bt_convert__perf2ctf(input_name, to_ctf, &opts);
Signature · 1 line
2.11.0
author maintainer
#14 lore raw

PATCH 8/23 perf evlist: Add -q/--quiet option

In reply to Namhyung Kim

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 evlist -i perf.data.kmem
  kmem:kmalloc
  kmem:kmalloc_node
  kmem:kfree
  kmem:kmem_cache_alloc
  kmem:kmem_cache_alloc_node
  kmem:kmem_cache_free
  kmem:mm_page_alloc
  kmem:mm_page_free
  # Tip: use 'perf evlist --trace-fields' to show fields for tracepoint events

After:

  $ perf evlist -i perf.data.kmem -q
  kmem:kmalloc
  kmem:kmalloc_node
  kmem:kfree
  kmem:kmem_cache_alloc
  kmem:kmem_cache_alloc_node
  kmem:kmem_cache_free
  kmem:mm_page_alloc
  kmem:mm_page_free
---
 tools/perf/Documentation/perf-evlist.txt | 4 ++++
 tools/perf/builtin-evlist.c              | 8 +++++++-
 2 files changed, 11 insertions(+), 1 deletion(-)
tools/perf/Documentation/perf-evlist.txt +4 -0
index 6f7200fb85cf..033aac0d4d79 100644
@@ -28,6 +28,10 @@ OPTIONS
 --verbose=::
 	Show all fields.
 
+-q::
+--quiet::
+	Do not show any message.
+
 -g::
 --group::
 	Show event group information.
tools/perf/builtin-evlist.c +7 -1
index e09c4287fe87..37c2cf7d395f 100644
@@ -39,7 +39,7 @@ static int __cmd_evlist(const char *file_name, struct perf_attr_details *details
 			has_tracepoint = true;
 	}
 
-	if (has_tracepoint && !details->trace_fields)
+	if (has_tracepoint && !details->trace_fields && !quiet)
 		printf("# Tip: use 'perf evlist --trace-fields' to show fields for tracepoint events\n");
 
 	perf_session__delete(session);
@@ -54,6 +54,7 @@ int cmd_evlist(int argc, const char **argv, const char *prefix __maybe_unused)
 	OPT_BOOLEAN('F', "freq", &details.freq, "Show the sample frequency"),
 	OPT_BOOLEAN('v', "verbose", &details.verbose,
 		    "Show all event attr details"),
+	OPT_BOOLEAN('q', "quiet", &quiet, "Do not show any message"),
 	OPT_BOOLEAN('g', "group", &details.event_group,
 		    "Show event group information"),
 	OPT_BOOLEAN('f', "force", &details.force, "don't complain, do it"),
@@ -69,6 +70,11 @@ int cmd_evlist(int argc, const char **argv, const char *prefix __maybe_unused)
 	if (argc)
 		usage_with_options(evlist_usage, options);
 
+	if (quiet) {
+		perf_quiet_option();
+		details.verbose = false;
+	}
+
 	if (details.event_group && (details.verbose || details.freq)) {
 		usage_with_options_msg(evlist_usage, options,
 			"--group option is not compatible with other options\n");
Signature · 1 line
2.11.0
author maintainer
#15 lore raw

PATCH 9/23 perf ftrace: Add -q/--quiet option

In reply to Namhyung Kim

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.

---
 tools/perf/Documentation/perf-ftrace.txt | 4 ++++
 tools/perf/builtin-ftrace.c              | 7 +++++--
 2 files changed, 9 insertions(+), 2 deletions(-)
tools/perf/Documentation/perf-ftrace.txt +4 -0
index 6e6a8b22c859..361836114268 100644
@@ -30,6 +30,10 @@ OPTIONS
 --verbose=::
         Verbosity level.
 
+-q::
+--quiet::
+	Do not show any message.
+
 -p::
 --pid=::
 	Trace on existing process id (comma separated list).
tools/perf/builtin-ftrace.c +5 -2
index 6087295f8827..2d8e8924cfe6 100644
@@ -321,8 +321,8 @@ int cmd_ftrace(int argc, const char **argv, const char *prefix __maybe_unused)
 		   "tracer to use: function_graph(default) or function"),
 	OPT_STRING('p', "pid", &ftrace.target.pid, "pid",
 		   "trace on existing process id"),
-	OPT_INCR('v', "verbose", &verbose,
-		 "be more verbose"),
+	OPT_INCR('v', "verbose", &verbose, "be more verbose"),
+	OPT_BOOLEAN('q', "quiet", &quiet, "do not show any message"),
 	OPT_BOOLEAN('a', "all-cpus", &ftrace.target.system_wide,
 		    "system-wide collection from all CPUs"),
 	OPT_STRING('C', "cpu", &ftrace.target.cpu_list, "cpu",
@@ -339,6 +339,9 @@ int cmd_ftrace(int argc, const char **argv, const char *prefix __maybe_unused)
 	if (!argc && target__none(&ftrace.target))
 		usage_with_options(ftrace_usage, ftrace_options);
 
+	if (quiet)
+		perf_quiet_option();
+
 	ret = target__validate(&ftrace.target);
 	if (ret) {
 		char errbuf[512];
Signature · 1 line
2.11.0
author maintainer
#16 lore raw

PATCH 10/23 perf inject: Add -q/--quiet option

In reply to Namhyung Kim

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.

---
 tools/perf/Documentation/perf-inject.txt |  3 +++
 tools/perf/builtin-inject.c              | 10 ++++++++--
 2 files changed, 11 insertions(+), 2 deletions(-)
tools/perf/Documentation/perf-inject.txt +3 -0
index 87b2588d1cbd..c69fe37c38cc 100644
@@ -29,6 +29,9 @@ OPTIONS
 -v::
 --verbose::
 	Be more verbose.
+-q::
+--quiet::
+	Do not show any message.
 -i::
 --input=::
 	Input file name. (default: stdin)
tools/perf/builtin-inject.c +8 -2
index b9bc7e39833a..a2d94be1b27d 100644
@@ -484,8 +484,10 @@ static int perf_inject__sched_switch(struct perf_tool *tool,
 
 	ent = malloc(event->header.size + sizeof(struct event_entry));
 	if (ent == NULL) {
-		color_fprintf(stderr, PERF_COLOR_RED,
+		if (!quiet) {
+			color_fprintf(stderr, PERF_COLOR_RED,
 			     "Not enough memory to process sched switch event!");
+		}
 		return -1;
 	}
 
@@ -780,6 +782,7 @@ int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused)
 #endif
 		OPT_INCR('v', "verbose", &verbose,
 			 "be more verbose (show build ids, etc)"),
+		OPT_BOOLEAN('q', "quiet", &quiet, "do not show any message"),
 		OPT_STRING(0, "kallsyms", &symbol_conf.kallsyms_name, "file",
 			   "kallsyms pathname"),
 		OPT_BOOLEAN('f', "force", &file.force, "don't complain, do it"),
@@ -805,13 +808,16 @@ int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused)
 	if (argc)
 		usage_with_options(inject_usage, options);
 
+	if (quiet)
+		perf_quiet_option();
+
 	if (inject.strip && !inject.itrace_synth_opts.set) {
 		pr_err("--strip option requires --itrace option\n");
 		return -1;
 	}
 
 	if (perf_data_file__open(&inject.output)) {
-		perror("failed to create output file");
+		pr_err("failed to create output file: %s\n", strerror(errno));
 		return -1;
 	}
 
Signature · 1 line
2.11.0
author maintainer
#17 lore raw

PATCH 11/23 perf kallsyms: Add -q/--quiet option

In reply to Namhyung Kim

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 kallsyms vfs_open no_symbol
  vfs_open: [kernel] [kernel.kallsyms] 0xffffffff81207b90-0xffffffff81207c00 (0xffffffff81207b90-0xffffffff81207c00)
  no_symbol: not found

After:

  $ perf kallsyms -q vfs_open no_symbol
  vfs_open: [kernel] [kernel.kallsyms] 0xffffffff81207b90-0xffffffff81207c00 (0xffffffff81207b90-0xffffffff81207c00)
---
 tools/perf/Documentation/perf-kallsyms.txt | 4 ++++
 tools/perf/builtin-kallsyms.c              | 7 ++++++-
 2 files changed, 10 insertions(+), 1 deletion(-)
tools/perf/Documentation/perf-kallsyms.txt +4 -0
index 954ea9e21236..c3c2aebb4660 100644
@@ -22,3 +22,7 @@ OPTIONS
 -v::
 --verbose=::
 	Increase verbosity level, showing details about symbol table loading, etc.
+
+-q::
+--quiet::
+	Do not show any message.
tools/perf/builtin-kallsyms.c +6 -1
index 224bfc454b4a..45a8e50a7f21 100644
@@ -29,7 +29,8 @@ static int __cmd_kallsyms(int argc, const char **argv)
 		struct symbol *symbol = machine__find_kernel_function_by_name(machine, argv[i], &map);
 
 		if (symbol == NULL) {
-			printf("%s: not found\n", argv[i]);
+			if (!quiet)
+				printf("%s: not found\n", argv[i]);
 			continue;
 		}
 
@@ -47,6 +48,7 @@ int cmd_kallsyms(int argc, const char **argv, const char *prefix __maybe_unused)
 {
 	const struct option options[] = {
 	OPT_INCR('v', "verbose", &verbose, "be more verbose (show counter open errors, etc)"),
+	OPT_BOOLEAN('q', "quiet", &quiet, "Do not show any message"),
 	OPT_END()
 	};
 	const char * const kallsyms_usage[] = {
@@ -58,6 +60,9 @@ int cmd_kallsyms(int argc, const char **argv, const char *prefix __maybe_unused)
 	if (argc < 1)
 		usage_with_options(kallsyms_usage, options);
 
+	if (quiet)
+		perf_quiet_option();
+
 	symbol_conf.sort_by_name = true;
 	symbol_conf.try_vmlinux_path = (symbol_conf.vmlinux_name == NULL);
 	if (symbol__init(NULL) < 0)
Signature · 1 line
2.11.0
author maintainer
#18 lore raw

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

In reply to Namhyung Kim

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
---
 tools/perf/Documentation/perf-kmem.txt | 4 ++++
 tools/perf/builtin-kmem.c              | 4 ++++
 2 files changed, 8 insertions(+)
tools/perf/Documentation/perf-kmem.txt +4 -0
index 479fc3261a50..0731389501d4 100644
@@ -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
 
tools/perf/builtin-kmem.c +4 -0
index 6da8d083e4e5..7148137c3a3d 100644
@@ -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;
Signature · 1 line
2.11.0
author maintainer
#19 lore raw

PATCH 13/23 perf kvm: Add -q/--quiet option

In reply to Namhyung Kim

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.

---
 tools/perf/Documentation/perf-kvm.txt |  3 +++
 tools/perf/builtin-kvm.c              | 10 +++++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)
tools/perf/Documentation/perf-kvm.txt +3 -0
index 6a5bb2b17039..8eec9d13181c 100644
@@ -96,6 +96,9 @@ OPTIONS
 -v::
 --verbose::
 	Be more verbose (show counter open errors, etc).
+-q::
+--quiet::
+	Do not show any message.
 
 STAT REPORT OPTIONS
 -------------------
tools/perf/builtin-kvm.c +9 -1
index 08fa88f62a24..1d121bb0a14d 100644
@@ -1018,7 +1018,7 @@ static int kvm_live_open_events(struct perf_kvm_stat *kvm)
 
 	err = perf_evlist__open(evlist);
 	if (err < 0) {
-		printf("Couldn't create the events: %s\n",
+		pr_err("Couldn't create the events: %s\n",
 		       str_error_r(errno, sbuf, sizeof(sbuf)));
 		goto out;
 	}
@@ -1313,6 +1313,7 @@ static int kvm_events_live(struct perf_kvm_stat *kvm,
 			perf_evlist__parse_mmap_pages),
 		OPT_INCR('v', "verbose", &verbose,
 			"be more verbose (show counter open errors, etc)"),
+		OPT_BOOLEAN('q', "quiet", &quiet, "Do not show any message"),
 		OPT_BOOLEAN('a', "all-cpus", &kvm->opts.target.system_wide,
 			"system-wide collection from all CPUs"),
 		OPT_UINTEGER('d', "display", &kvm->display_time,
@@ -1372,6 +1373,9 @@ static int kvm_events_live(struct perf_kvm_stat *kvm,
 			usage_with_options(live_usage, live_options);
 	}
 
+	if (quiet)
+		perf_quiet_option();
+
 	kvm->duration *= NSEC_PER_USEC;   /* convert usec to nsec */
 
 	/*
@@ -1557,6 +1561,7 @@ int cmd_kvm(int argc, const char **argv, const char *prefix __maybe_unused)
 			   "file", "file saving guest os /proc/modules"),
 		OPT_INCR('v', "verbose", &verbose,
 			    "be more verbose (show counter open errors, etc)"),
+		OPT_BOOLEAN('q', "quiet", &quiet, "Do not show any message"),
 		OPT_END()
 	};
 
@@ -1572,6 +1577,9 @@ int cmd_kvm(int argc, const char **argv, const char *prefix __maybe_unused)
 	if (!argc)
 		usage_with_options(kvm_usage, kvm_options);
 
+	if (quiet)
+		perf_quiet_option();
+
 	if (!perf_host)
 		perf_guest = 1;
 
Signature · 1 line
2.11.0
author maintainer
#20 lore raw

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

In reply to Namhyung Kim

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.

---
 tools/perf/Documentation/perf-list.txt | 9 ++++++++-
 tools/perf/builtin-list.c              | 9 +++++++--
 2 files changed, 15 insertions(+), 3 deletions(-)
tools/perf/Documentation/perf-list.txt +8 -1
index 41857cce5e86..7964d0e9dc8a 100644
@@ -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
tools/perf/builtin-list.c +7 -2
index 3b9d98b5feef..b53b3597ee0f 100644
@@ -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,
Signature · 1 line
2.11.0
author maintainer
#21 lore raw

PATCH 15/23 perf lock: Add -q/--quiet option

In reply to Namhyung Kim

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.

Also move -f option to parent and link child options.

---
 tools/perf/Documentation/perf-lock.txt |  8 ++++++++
 tools/perf/builtin-lock.c              | 33 ++++++++++++++++++++-------------
 2 files changed, 28 insertions(+), 13 deletions(-)
tools/perf/Documentation/perf-lock.txt +8 -0
index ab25be28c9dc..1c4a548455ee 100644
@@ -42,6 +42,14 @@ COMMON OPTIONS
 --dump-raw-trace::
         Dump raw trace in ASCII.
 
+-q::
+--quiet::
+	Do not show any message.
+
+-f::
+--force::
+        Don't do ownership validation.
+
 REPORT OPTIONS
 --------------
 
tools/perf/builtin-lock.c +20 -13
index ce3bfb48b26f..8197e5672413 100644
@@ -947,30 +947,26 @@ static int __cmd_record(int argc, const char **argv)
 
 int cmd_lock(int argc, const char **argv, const char *prefix __maybe_unused)
 {
-	const struct option info_options[] = {
-	OPT_BOOLEAN('t', "threads", &info_threads,
-		    "dump thread list in perf.data"),
-	OPT_BOOLEAN('m', "map", &info_map,
-		    "map of lock instances (address:name table)"),
-	OPT_BOOLEAN('f', "force", &force, "don't complain, do it"),
-	OPT_END()
-	};
 	const struct option lock_options[] = {
 	OPT_STRING('i', "input", &input_name, "file", "input file name"),
 	OPT_INCR('v', "verbose", &verbose, "be more verbose (show symbol address, etc)"),
 	OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, "dump raw trace in ASCII"),
+	OPT_BOOLEAN('q', "quiet", &quiet, "Do not show any message"),
+	OPT_BOOLEAN('f', "force", &force, "don't complain, do it"),
 	OPT_END()
 	};
 	const struct option report_options[] = {
 	OPT_STRING('k', "key", &sort_key, "acquired",
 		    "key for sorting (acquired / contended / avg_wait / wait_total / wait_max / wait_min)"),
-	OPT_BOOLEAN('f', "force", &force, "don't complain, do it"),
 	/* TODO: type */
-	OPT_END()
+	OPT_PARENT(lock_options)
 	};
-	const char * const info_usage[] = {
-		"perf lock info [<options>]",
-		NULL
+	const struct option info_options[] = {
+	OPT_BOOLEAN('t', "threads", &info_threads,
+		    "dump thread list in perf.data"),
+	OPT_BOOLEAN('m', "map", &info_map,
+		    "map of lock instances (address:name table)"),
+	OPT_PARENT(lock_options)
 	};
 	const char *const lock_subcommands[] = { "record", "report", "script",
 						 "info", NULL };
@@ -982,6 +978,10 @@ int cmd_lock(int argc, const char **argv, const char *prefix __maybe_unused)
 		"perf lock report [<options>]",
 		NULL
 	};
+	const char * const info_usage[] = {
+		"perf lock info [<options>]",
+		NULL
+	};
 	unsigned int i;
 	int rc = 0;
 
@@ -993,6 +993,9 @@ int cmd_lock(int argc, const char **argv, const char *prefix __maybe_unused)
 	if (!argc)
 		usage_with_options(lock_usage, lock_options);
 
+	if (quiet)
+		perf_quiet_option();
+
 	if (!strncmp(argv[0], "rec", 3)) {
 		return __cmd_record(argc, argv);
 	} else if (!strncmp(argv[0], "report", 6)) {
@@ -1002,6 +1005,8 @@ int cmd_lock(int argc, const char **argv, const char *prefix __maybe_unused)
 					     report_options, report_usage, 0);
 			if (argc)
 				usage_with_options(report_usage, report_options);
+			if (quiet && verbose >= 0)
+				perf_quiet_option();
 		}
 		rc = __cmd_report(false);
 	} else if (!strcmp(argv[0], "script")) {
@@ -1013,6 +1018,8 @@ int cmd_lock(int argc, const char **argv, const char *prefix __maybe_unused)
 					     info_options, info_usage, 0);
 			if (argc)
 				usage_with_options(info_usage, info_options);
+			if (quiet && verbose >= 0)
+				perf_quiet_option();
 		}
 		/* recycling report_lock_ops */
 		trace_handler = &report_lock_ops;
Signature · 1 line
2.11.0
author maintainer
#22 lore raw

PATCH 16/23 perf mem: Add -q/--quiet option

In reply to Namhyung Kim

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.

---
 tools/perf/Documentation/perf-mem.txt | 8 ++++++++
 tools/perf/builtin-mem.c              | 6 +++++-
 2 files changed, 13 insertions(+), 1 deletion(-)
tools/perf/Documentation/perf-mem.txt +8 -0
index 73496320fca3..5ad90572299c 100644
@@ -59,6 +59,14 @@ OPTIONS
 --ldload::
 	Specify desired latency for loads event.
 
+-v::
+--verbose::
+        Be more verbose. (show debug messages, etc)
+
+-q::
+--quiet::
+	Do not show any message.  (Suppress -v)
+
 SEE ALSO
 --------
 linkperf:perf-record[1], linkperf:perf-report[1]
tools/perf/builtin-mem.c +5 -1
index 6114e07ca613..24d084327c1e 100644
@@ -70,6 +70,7 @@ static int __cmd_record(int argc, const char **argv, struct perf_mem *mem)
 	OPT_UINTEGER(0, "ldlat", &perf_mem_events__loads_ldlat, "mem-loads latency"),
 	OPT_INCR('v', "verbose", &verbose,
 		 "be more verbose (show counter open errors, etc)"),
+	OPT_BOOLEAN('q', "quiet", &quiet, "Do not show any message"),
 	OPT_BOOLEAN('U', "all-user", &all_user, "collect only user level data"),
 	OPT_BOOLEAN('K', "all-kernel", &all_kernel, "collect only kernel level data"),
 	OPT_END()
@@ -83,6 +84,9 @@ static int __cmd_record(int argc, const char **argv, struct perf_mem *mem)
 	if (!rec_argv)
 		return -1;
 
+	if (quiet)
+		perf_quiet_option();
+
 	rec_argv[i++] = "record";
 
 	if (mem->operation & MEM_OPERATION_LOAD)
@@ -144,7 +148,7 @@ dump_raw_samples(struct perf_tool *tool,
 	struct addr_location al;
 	const char *fmt;
 
-	if (machine__resolve(machine, &al, sample) < 0) {
+	if (machine__resolve(machine, &al, sample) < 0 && !quiet) {
 		fprintf(stderr, "problem processing %d event, skipping it.\n",
 				event->header.type);
 		return -1;
Signature · 1 line
2.11.0
#23 lore raw
In reply to Namhyung Kim
Quoted 18 lines · Namhyung Kim

Hello,

This patchset adds -q/--quiet option for most commands. I skipped commands missing -v/--verbose option. While the -q option in this patchset just suppresses warning messages, some command might want to mute other outputs too. I added a few obvious ones and if you have some thought, please let me know.

The patch 1, 4 and 5 are fixes and can be applied separately.

The code is available on the 'perf/quiet-v2' branche on my tree

git://git.kernel.org/pub/scm/linux/kernel/git/namhyung/linux-perf.git

Thanks,
Namhyung

Quoted 7 lines

Namhyung Kim (23):
perf report: Hide tip message when -q option is given perf buildid-cache: Add -q/--quiet option perf buildid-list: Add -q/--quiet option perf c2c: Fix help message of --stats option perf c2c: Fix display bug when using pipe perf c2c: Add -q/--quiet option

ACK for the c2c options

thanks,
jirka

author maintainer
#24 lore raw

PATCH 17/23 perf sched: Add -q/--quiet option

In reply to Namhyung Kim

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.

---
 tools/perf/Documentation/perf-sched.txt |  8 ++++++++
 tools/perf/builtin-sched.c              | 12 ++++++++++++
 2 files changed, 20 insertions(+)
tools/perf/Documentation/perf-sched.txt +8 -0
index d33deddb0146..7b5fbde0c8f9 100644
@@ -70,10 +70,18 @@ OPTIONS
 --verbose::
         Be more verbose. (show symbol address, etc)
 
+-q::
+--quiet::
+	Do not show any message.  (Suppress -v)
+
 -D::
 --dump-raw-trace=::
         Display verbose dump of the sched data.
 
+-f::
+--force::
+        Don't do ownership validation.
+
 OPTIONS for 'perf sched map'
 ----------------------------
 
tools/perf/builtin-sched.c +12 -0
index b94cf0de715a..9847b5bf081c 100644
@@ -3297,6 +3297,7 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused)
 	OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
 		    "dump raw trace in ASCII"),
 	OPT_BOOLEAN('f', "force", &sched.force, "don't complain, do it"),
+	OPT_BOOLEAN('q', "quiet", &quiet, "Do not show any message"),
 	OPT_END()
 	};
 	const struct option latency_options[] = {
@@ -3396,6 +3397,9 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused)
 	if (!argc)
 		usage_with_options(sched_usage, sched_options);
 
+	if (quiet)
+		perf_quiet_option();
+
 	/*
 	 * Aliased to 'perf script' for now:
 	 */
@@ -3410,6 +3414,8 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused)
 			argc = parse_options(argc, argv, latency_options, latency_usage, 0);
 			if (argc)
 				usage_with_options(latency_usage, latency_options);
+			if (quiet && verbose >= 0)
+				perf_quiet_option();
 		}
 		setup_sorting(&sched, latency_options, latency_usage);
 		return perf_sched__lat(&sched);
@@ -3418,6 +3424,8 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused)
 			argc = parse_options(argc, argv, map_options, map_usage, 0);
 			if (argc)
 				usage_with_options(map_usage, map_options);
+			if (quiet && verbose >= 0)
+				perf_quiet_option();
 		}
 		sched.tp_handler = &map_ops;
 		setup_sorting(&sched, latency_options, latency_usage);
@@ -3428,6 +3436,8 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused)
 			argc = parse_options(argc, argv, replay_options, replay_usage, 0);
 			if (argc)
 				usage_with_options(replay_usage, replay_options);
+			if (quiet && verbose >= 0)
+				perf_quiet_option();
 		}
 		return perf_sched__replay(&sched);
 	} else if (!strcmp(argv[0], "timehist")) {
@@ -3436,6 +3446,8 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused)
 					     timehist_usage, 0);
 			if (argc)
 				usage_with_options(timehist_usage, timehist_options);
+			if (quiet && verbose >= 0)
+				perf_quiet_option();
 		}
 		if (sched.show_wakeups && sched.summary_only) {
 			pr_err(" Error: -s and -w are mutually exclusive.\n");
Signature · 1 line
2.11.0
author maintainer
#25 lore raw

PATCH 18/23 perf script: Use pr_err() for error messages

In reply to Namhyung Kim

There are many open calls to fprintf() for error logging. use pr_err() instead so that they can be treated at once (e.g. with -q option).

Also convert perror() to pr_err() + str_error_r().

---
 tools/perf/builtin-script.c | 41 +++++++++++++++++++++--------------------
 1 file changed, 21 insertions(+), 20 deletions(-)
tools/perf/builtin-script.c +21 -20
index c0783b4f7b6c..d1c95f0b8a0f 100644
@@ -1394,14 +1394,14 @@ static int parse_scriptname(const struct option *opt __maybe_unused,
 	if (script) {
 		len = script - str;
 		if (len >= PATH_MAX) {
-			fprintf(stderr, "invalid language specifier");
+			pr_err("invalid language specifier");
 			return -1;
 		}
 		strncpy(spec, str, len);
 		spec[len] = '\0';
 		scripting_ops = script_spec__lookup(spec);
 		if (!scripting_ops) {
-			fprintf(stderr, "invalid language specifier");
+			pr_err("invalid language specifier");
 			return -1;
 		}
 		script++;
@@ -1409,12 +1409,12 @@ static int parse_scriptname(const struct option *opt __maybe_unused,
 		script = str;
 		ext = strrchr(script, '.');
 		if (!ext) {
-			fprintf(stderr, "invalid script extension");
+			pr_err("invalid script extension");
 			return -1;
 		}
 		scripting_ops = script_spec__lookup(++ext);
 		if (!scripting_ops) {
-			fprintf(stderr, "invalid script extension");
+			pr_err("invalid script extension");
 			return -1;
 		}
 	}
@@ -1472,8 +1472,7 @@ static int parse_output_fields(const struct option *opt __maybe_unused,
 	} else {
 		tok = str;
 		if (strlen(str) == 0) {
-			fprintf(stderr,
-				"Cannot set fields to 'none' for all event types.\n");
+			pr_err("Cannot set fields to 'none' for all event types.\n");
 			rc = -EINVAL;
 			goto out;
 		}
@@ -1498,7 +1497,7 @@ static int parse_output_fields(const struct option *opt __maybe_unused,
 			continue;
 		}
 		if (i == imax) {
-			fprintf(stderr, "Invalid field requested.\n");
+			pr_err("Invalid field requested.\n");
 			rc = -EINVAL;
 			goto out;
 		}
@@ -1516,7 +1515,7 @@ static int parse_output_fields(const struct option *opt __maybe_unused,
 			}
 		} else {
 			if (output[type].invalid_fields & all_output_options[i].field) {
-				fprintf(stderr, "\'%s\' not valid for %s events.\n",
+				pr_err("\'%s\' not valid for %s events.\n",
 					 all_output_options[i].str, event_type(type));
 
 				rc = -EINVAL;
@@ -1722,8 +1721,7 @@ static int list_available_scripts(const struct option *opt __maybe_unused,
 
 	scripts_dir = opendir(scripts_path);
 	if (!scripts_dir) {
-		fprintf(stdout,
-			"open(%s) failed.\n"
+		pr_err("open(%s) failed.\n"
 			"Check \"PERF_EXEC_PATH\" env to set scripts dir.\n",
 			scripts_path);
 		exit(-1);
@@ -2205,6 +2203,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
 		"perf script [<options>] <top-script> [script-args]",
 		NULL
 	};
+	char errbuf[STRERR_BUFSIZE];
 
 	setup_scripting();
 
@@ -2223,8 +2222,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
 	if (argc > 1 && !strncmp(argv[0], "rep", strlen("rep"))) {
 		rep_script_path = get_script_path(argv[1], REPORT_SUFFIX);
 		if (!rep_script_path) {
-			fprintf(stderr,
-				"Please specify a valid report script"
+			pr_err("Please specify a valid report script"
 				"(see 'perf script -l' for listing)\n");
 			return -1;
 		}
@@ -2267,13 +2265,15 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
 		}
 
 		if (pipe(live_pipe) < 0) {
-			perror("failed to create pipe");
+			pr_err("failed to create pipe: %s\n",
+			       str_error_r(errno, errbuf, sizeof(errbuf)));
 			return -1;
 		}
 
 		pid = fork();
 		if (pid < 0) {
-			perror("failed to fork");
+			pr_err("failed to fork: %s\n",
+			       str_error_r(errno, errbuf, sizeof(errbuf)));
 			return -1;
 		}
 
@@ -2424,8 +2424,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
 		int input;
 
 		if (output_set_by_user()) {
-			fprintf(stderr,
-				"custom fields not supported for generated scripts");
+			pr_err("custom fields not supported for generated scripts");
 			err = -EINVAL;
 			goto out_delete;
 		}
@@ -2433,24 +2432,26 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
 		input = open(file.path, O_RDONLY);	/* input_name */
 		if (input < 0) {
 			err = -errno;
-			perror("failed to open file");
+			pr_err("failed to open file: %s\n",
+			       str_error_r(errno, errbuf, sizeof(errbuf)));
 			goto out_delete;
 		}
 
 		err = fstat(input, &perf_stat);
 		if (err < 0) {
-			perror("failed to stat file");
+			pr_err("failed to stat file: %s\n",
+			       str_error_r(errno, errbuf, sizeof(errbuf)));
 			goto out_delete;
 		}
 
 		if (!perf_stat.st_size) {
-			fprintf(stderr, "zero-sized file, nothing to do!\n");
+			pr_err("zero-sized file, nothing to do!\n");
 			goto out_delete;
 		}
 
 		scripting_ops = script_spec__lookup(generate_script_lang);
 		if (!scripting_ops) {
-			fprintf(stderr, "invalid language specifier");
+			pr_err("invalid language specifier");
 			err = -ENOENT;
 			goto out_delete;
 		}
Signature · 1 line
2.11.0
author maintainer
#26 lore raw

PATCH 19/23 perf script: Add -q/--quiet option

In reply to Namhyung Kim

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.

---
 tools/perf/Documentation/perf-script.txt | 8 ++++++++
 tools/perf/builtin-script.c              | 4 ++++
 2 files changed, 12 insertions(+)
tools/perf/Documentation/perf-script.txt +8 -0
index 4ed5f239ba7d..24f7e36a4fe8 100644
@@ -75,6 +75,14 @@ OPTIONS
 <command>...::
 	Any command you can specify in a shell.
 
+-v::
+--verbose::
+        Be more verbose. (show debug messages, etc)
+
+-q::
+--quiet::
+	Do not show any message.  (Suppress -v)
+
 -D::
 --dump-raw-trace=::
         Display verbose dump of the trace data.
tools/perf/builtin-script.c +4 -0
index d1c95f0b8a0f..f46498f2e73a 100644
@@ -2122,6 +2122,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
 		    "dump raw trace in ASCII"),
 	OPT_INCR('v', "verbose", &verbose,
 		 "be more verbose (show symbol address, etc)"),
+	OPT_BOOLEAN('q', "quiet", &quiet, "Do not show any message"),
 	OPT_BOOLEAN('L', "Latency", &latency_format,
 		    "show latency attributes (irqs/preemption disabled, etc)"),
 	OPT_CALLBACK_NOOPT('l', "list", NULL, NULL, "list available scripts",
@@ -2210,6 +2211,9 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
 	argc = parse_options_subcommand(argc, argv, options, script_subcommands, script_usage,
 			     PARSE_OPT_STOP_AT_NON_OPTION);
 
+	if (quiet)
+		perf_quiet_option();
+
 	file.path = input_name;
 	file.force = symbol_conf.force;
 
Signature · 1 line
2.11.0
#27 lore raw
In reply to Namhyung Kim

Em Wed, Mar 08, 2017 at 12:08:28AM +0900, Namhyung Kim escreveu:

Quoted 9 lines

Hello,

This patchset adds -q/--quiet option for most commands. I skipped commands missing -v/--verbose option. While the -q option in this patchset just suppresses warning messages, some command might want to mute other outputs too. I added a few obvious ones and if you have some thought, please let me know.

The patch 1, 4 and 5 are fixes and can be applied separately.

Applied those.

- Arnaldo

author maintainer
#28 lore raw

PATCH 20/23 perf stat: Use pr_err() for error messages

In reply to Namhyung Kim

There are many open calls to fprintf() for error logging. use pr_err() instead so that they can be treated at once (e.g. with -q option).

Also convert perror() to pr_err() + str_error_r().

---
 tools/perf/builtin-stat.c | 52 ++++++++++++++++++++++++++++-------------------
 1 file changed, 31 insertions(+), 21 deletions(-)
tools/perf/builtin-stat.c +31 -21
index f53f449d864d..ee7190da9b6e 100644
@@ -555,7 +555,8 @@ static int __run_perf_stat(int argc, const char **argv)
 	if (forks) {
 		if (perf_evlist__prepare_workload(evsel_list, &target, argv, is_pipe,
 						  workload_exec_failed_signal) < 0) {
-			perror("failed to prepare workload");
+			pr_err("failed to prepare workload: %s\n",
+			       str_error_r(errno, msg, sizeof(msg)));
 			return -1;
 		}
 		child_pid = evsel_list->workload.pid;
@@ -608,14 +609,14 @@ static int __run_perf_stat(int argc, const char **argv)
 	}
 
 	if (perf_evlist__apply_filters(evsel_list, &counter)) {
-		error("failed to set filter \"%s\" on event %s with %d (%s)\n",
+		pr_err("failed to set filter \"%s\" on event %s with %d (%s)\n",
 			counter->filter, perf_evsel__name(counter), errno,
 			str_error_r(errno, msg, sizeof(msg)));
 		return -1;
 	}
 
 	if (perf_evlist__apply_drv_configs(evsel_list, &counter, &err_term)) {
-		error("failed to set config \"%s\" on event %s with %d (%s)\n",
+		pr_err("failed to set config \"%s\" on event %s with %d (%s)\n",
 		      err_term->val.drv_cfg, perf_evsel__name(counter), errno,
 		      str_error_r(errno, msg, sizeof(msg)));
 		return -1;
@@ -1725,18 +1726,21 @@ static int perf_stat__get_core_cached(struct cpu_map *map, int idx)
 static int perf_stat_init_aggr_mode(void)
 {
 	int nr;
+	char errbuf[STRERR_BUFSIZE];
 
 	switch (stat_config.aggr_mode) {
 	case AGGR_SOCKET:
 		if (cpu_map__build_socket_map(evsel_list->cpus, &aggr_map)) {
-			perror("cannot build socket map");
+			pr_err("cannot build socket map: %s\n",
+			       str_error_r(errno, errbuf, sizeof(errbuf)));
 			return -1;
 		}
 		aggr_get_id = perf_stat__get_socket_cached;
 		break;
 	case AGGR_CORE:
 		if (cpu_map__build_core_map(evsel_list->cpus, &aggr_map)) {
-			perror("cannot build core map");
+			pr_err("cannot build core map: %s\n",
+			       str_error_r(errno, errbuf, sizeof(errbuf)));
 			return -1;
 		}
 		aggr_get_id = perf_stat__get_core_cached;
@@ -1835,18 +1839,21 @@ static int perf_stat__get_core_file(struct cpu_map *map, int idx)
 static int perf_stat_init_aggr_mode_file(struct perf_stat *st)
 {
 	struct perf_env *env = &st->session->header.env;
+	char errbuf[STRERR_BUFSIZE];
 
 	switch (stat_config.aggr_mode) {
 	case AGGR_SOCKET:
 		if (perf_env__build_socket_map(env, evsel_list->cpus, &aggr_map)) {
-			perror("cannot build socket map");
+			pr_err("cannot build socket map: %s\n",
+			       str_error_r(errno, errbuf, sizeof(errbuf)));
 			return -1;
 		}
 		aggr_get_id = perf_stat__get_socket_file;
 		break;
 	case AGGR_CORE:
 		if (perf_env__build_core_map(env, evsel_list->cpus, &aggr_map)) {
-			perror("cannot build core map");
+			pr_err("cannot build core map: %s\n",
+			       str_error_r(errno, errbuf, sizeof(errbuf)));
 			return -1;
 		}
 		aggr_get_id = perf_stat__get_core_file;
@@ -2042,7 +2049,7 @@ static int add_default_attributes(void)
 		else
 			err = parse_events(evsel_list, transaction_limited_attrs, NULL);
 		if (err) {
-			fprintf(stderr, "Cannot set up transaction events\n");
+			pr_err("Cannot set up transaction events\n");
 			return -1;
 		}
 		return 0;
@@ -2075,14 +2082,13 @@ static int add_default_attributes(void)
 				arch_topdown_group_warn();
 			err = parse_events(evsel_list, str, NULL);
 			if (err) {
-				fprintf(stderr,
-					"Cannot set up top down events %s: %d\n",
+				pr_err("Cannot set up top down events %s: %d\n",
 					str, err);
 				free(str);
 				return -1;
 			}
 		} else {
-			fprintf(stderr, "System does not support topdown\n");
+			pr_err("System does not support topdown\n");
 			return -1;
 		}
 		free(str);
@@ -2390,6 +2396,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
 	FILE *output = stderr;
 	unsigned int interval;
 	const char * const stat_subcommands[] = { "record", "report" };
+	char errbuf[STRERR_BUFSIZE];
 
 	setlocale(LC_ALL, "");
 
@@ -2426,24 +2433,24 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
 		output = NULL;
 
 	if (output_name && output_fd) {
-		fprintf(stderr, "cannot use both --output and --log-fd\n");
+		pr_err("cannot use both --output and --log-fd\n");
 		parse_options_usage(stat_usage, stat_options, "o", 1);
 		parse_options_usage(NULL, stat_options, "log-fd", 0);
 		goto out;
 	}
 
 	if (metric_only && stat_config.aggr_mode == AGGR_THREAD) {
-		fprintf(stderr, "--metric-only is not supported with --per-thread\n");
+		pr_err("--metric-only is not supported with --per-thread\n");
 		goto out;
 	}
 
 	if (metric_only && run_count > 1) {
-		fprintf(stderr, "--metric-only is not supported with -r\n");
+		pr_err("--metric-only is not supported with -r\n");
 		goto out;
 	}
 
 	if (output_fd < 0) {
-		fprintf(stderr, "argument to --log-fd must be a > 0\n");
+		pr_err("argument to --log-fd must be a > 0\n");
 		parse_options_usage(stat_usage, stat_options, "log-fd", 0);
 		goto out;
 	}
@@ -2454,7 +2461,8 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
 
 		output = fopen(output_name, mode);
 		if (!output) {
-			perror("failed to create output file");
+			pr_err("failed to create output file: %s\n",
+			       str_error_r(errno, errbuf, sizeof(errbuf)));
 			return -1;
 		}
 		clock_gettime(CLOCK_REALTIME, &tm);
@@ -2463,7 +2471,8 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
 		mode = append_file ? "a" : "w";
 		output = fdopen(output_fd, mode);
 		if (!output) {
-			perror("Failed opening logfd");
+			pr_err("Failed opening logfd: %s\n",
+			       str_error_r(errno, errbuf, sizeof(errbuf)));
 			return -errno;
 		}
 	}
@@ -2476,7 +2485,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
 	if (csv_output) {
 		/* User explicitly passed -B? */
 		if (big_num_opt == 1) {
-			fprintf(stderr, "-B option not supported with -x\n");
+			pr_err("-B option not supported with -x\n");
 			parse_options_usage(stat_usage, stat_options, "B", 1);
 			parse_options_usage(NULL, stat_options, "x", 1);
 			goto out;
@@ -2497,7 +2506,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
 	}
 
 	if ((stat_config.aggr_mode == AGGR_THREAD) && !target__has_task(&target)) {
-		fprintf(stderr, "The --per-thread option is only available "
+		pr_err("The --per-thread option is only available "
 			"when monitoring via -p -t options.\n");
 		parse_options_usage(NULL, stat_options, "p", 1);
 		parse_options_usage(NULL, stat_options, "t", 1);
@@ -2511,7 +2520,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
 	if (((stat_config.aggr_mode != AGGR_GLOBAL &&
 	      stat_config.aggr_mode != AGGR_THREAD) || nr_cgroups) &&
 	    !target__has_cpu(&target)) {
-		fprintf(stderr, "both cgroup and no-aggregation "
+		pr_err("both cgroup and no-aggregation "
 			"modes only available in system-wide mode\n");
 
 		parse_options_usage(stat_usage, stat_options, "G", 1);
@@ -2531,7 +2540,8 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
 			parse_options_usage(stat_usage, stat_options, "p", 1);
 			parse_options_usage(NULL, stat_options, "t", 1);
 		} else if (target__has_cpu(&target)) {
-			perror("failed to parse CPUs map");
+			pr_err("failed to parse CPUs map: %s\n",
+			       str_error_r(errno, errbuf, sizeof(errbuf)));
 			parse_options_usage(stat_usage, stat_options, "C", 1);
 			parse_options_usage(NULL, stat_options, "a", 1);
 		}
Signature · 1 line
2.11.0
author maintainer
#29 lore raw

PATCH 21/23 perf stat: Add -q/--quiet option

In reply to Namhyung Kim

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.

---
 tools/perf/Documentation/perf-stat.txt | 4 ++++
 tools/perf/builtin-stat.c              | 7 +++++++
 2 files changed, 11 insertions(+)
tools/perf/Documentation/perf-stat.txt +4 -0
index aecf2a87e7d6..94482b8a597b 100644
@@ -105,6 +105,10 @@ This option is only valid in system-wide mode.
 --verbose::
         be more verbose (show counter open errors, etc)
 
+-q::
+--quiet::
+	Do not show any message.  (Suppress -v)
+
 -x SEP::
 --field-separator SEP::
 print counts using a CSV-style output to make it easy to import directly into
tools/perf/builtin-stat.c +7 -0
index ee7190da9b6e..9dbb08c038e1 100644
@@ -1630,6 +1630,7 @@ static const struct option stat_options[] = {
 	OPT_BOOLEAN('c', "scale", &stat_config.scale, "scale/normalize counters"),
 	OPT_INCR('v', "verbose", &verbose,
 		    "be more verbose (show counter open errors, etc)"),
+	OPT_BOOLEAN('q', "quiet", &quiet, "Do not show any message"),
 	OPT_INTEGER('r', "repeat", &run_count,
 		    "repeat command and print average + stddev (max: 100, forever: 0)"),
 	OPT_BOOLEAN('n', "null", &null_run,
@@ -2163,6 +2164,9 @@ static int __cmd_record(int argc, const char **argv)
 	argc = parse_options(argc, argv, stat_options, stat_record_usage,
 			     PARSE_OPT_STOP_AT_NON_OPTION);
 
+	if (quiet)
+		perf_quiet_option();
+
 	if (output_name)
 		file->path = output_name;
 
@@ -2410,6 +2414,9 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
 					PARSE_OPT_STOP_AT_NON_OPTION);
 	perf_stat__init_shadow_stats();
 
+	if (quiet)
+		perf_quiet_option();
+
 	if (csv_sep) {
 		csv_output = true;
 		if (!strcmp(csv_sep, "\\t"))
Signature · 1 line
2.11.0
author maintainer
#30 lore raw

PATCH 22/23 perf top: Add -q/--quiet option

In reply to Namhyung Kim

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.

---
 tools/perf/Documentation/perf-top.txt | 4 ++++
 tools/perf/builtin-top.c              | 6 +++++-
 2 files changed, 9 insertions(+), 1 deletion(-)
tools/perf/Documentation/perf-top.txt +4 -0
index e71d63843f45..eda5b58b1cd4 100644
@@ -109,6 +109,10 @@ Default is to monitor all CPUS.
 --verbose::
 	Be more verbose (show counter open errors, etc).
 
+-q::
+--quiet::
+	Do not show any message.  (Suppress -v)
+
 -z::
 --zero::
 	Zero history across display updates.
tools/perf/builtin-top.c +5 -1
index ab9077915763..18b68c8495d6 100644
@@ -372,7 +372,7 @@ static void perf_top__prompt_symbol(struct perf_top *top, const char *msg)
 	}
 
 	if (!found) {
-		fprintf(stderr, "Sorry, %s is not active.\n", buf);
+		pr_err("Sorry, %s is not active.\n", buf);
 		sleep(1);
 	} else
 		perf_top__parse_source(top, found);
@@ -1142,6 +1142,7 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)
 	OPT_BOOLEAN(0, "stdio", &top.use_stdio, "Use the stdio interface"),
 	OPT_INCR('v', "verbose", &verbose,
 		    "be more verbose (show counter open errors, etc)"),
+	OPT_BOOLEAN('q', "quiet", &quiet, "Do not show any message"),
 	OPT_STRING('s', "sort", &sort_order, "key[,key2...]",
 		   "sort by key(s): pid, comm, dso, symbol, parent, cpu, srcline, ..."
 		   " Please refer the man page for the complete list."),
@@ -1224,6 +1225,9 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)
 	if (argc)
 		usage_with_options(top_usage, options);
 
+	if (quiet)
+		perf_quiet_option();
+
 	if (!top.evlist->nr_entries &&
 	    perf_evlist__add_default(top.evlist) < 0) {
 		pr_err("Not enough memory for event selector list\n");
Signature · 1 line
2.11.0
author maintainer
#31 lore raw

PATCH 23/23 perf trace: Add -q/--quiet option

In reply to Namhyung Kim

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.

Also check the quiet variable when printing error messages.

---
 tools/perf/Documentation/perf-trace.txt |  4 ++++
 tools/perf/builtin-trace.c              | 33 ++++++++++++++++++++++-----------
 2 files changed, 26 insertions(+), 11 deletions(-)
tools/perf/Documentation/perf-trace.txt +4 -0
index afd728672b6f..4ac21b6194e7 100644
@@ -70,6 +70,10 @@ filter out the startup phase of the program, which is often very different.
 --verbose=::
         Verbosity level.
 
+-q::
+--quiet::
+	Do not show any message.  (Suppress -v)
+
 --no-inherit::
 	Child tasks do not inherit counters.
 
tools/perf/builtin-trace.c +22 -11
index 256f1fac6f7e..00e1349c73bf 100644
@@ -1242,7 +1242,7 @@ static int trace__validate_ev_qualifier(struct trace *trace)
 	trace->ev_qualifier_ids.entries = malloc(trace->ev_qualifier_ids.nr *
 						 sizeof(trace->ev_qualifier_ids.entries[0]));
 
-	if (trace->ev_qualifier_ids.entries == NULL) {
+	if (trace->ev_qualifier_ids.entries == NULL && !quiet) {
 		fputs("Error:\tNot enough memory for allocating events qualifier ids\n",
 		       trace->output);
 		err = -EINVAL;
@@ -1257,7 +1257,8 @@ static int trace__validate_ev_qualifier(struct trace *trace)
 
 		if (id < 0) {
 			if (err == 0) {
-				fputs("Error:\tInvalid syscall ", trace->output);
+				if (!quiet)
+					fputs("Error:\tInvalid syscall ", trace->output);
 				err = -EINVAL;
 			} else {
 				fputs(", ", trace->output);
@@ -1270,8 +1271,10 @@ static int trace__validate_ev_qualifier(struct trace *trace)
 	}
 
 	if (err < 0) {
-		fputs("\nHint:\ttry 'perf list syscalls:sys_enter_*'"
-		      "\nHint:\tand: 'man syscalls'\n", trace->output);
+		if (verbose >= 0) {
+			fputs("\nHint:\ttry 'perf list syscalls:sys_enter_*'"
+			      "\nHint:\tand: 'man syscalls'\n", trace->output);
+		}
 		zfree(&trace->ev_qualifier_ids.entries);
 		trace->ev_qualifier_ids.nr = 0;
 	}
@@ -2604,7 +2607,7 @@ static size_t trace__fprintf_thread_summary(struct trace *trace, FILE *fp)
 	size_t printed = trace__fprintf_threads_header(fp);
 	struct rb_node *nd;
 
-	if (threads == NULL) {
+	if (threads == NULL && !quiet) {
 		fprintf(fp, "%s", "Error sorting output by nr_events!\n");
 		return 0;
 	}
@@ -2761,7 +2764,7 @@ static int trace__parse_events_option(const struct option *opt, const char *str,
 		};
 
 		trace->ev_qualifier = strlist__new(lists[1], &slist_config);
-		if (trace->ev_qualifier == NULL) {
+		if (trace->ev_qualifier == NULL && !quiet) {
 			fputs("Not enough memory to parse event qualifier", trace->output);
 			goto out;
 		}
@@ -2849,6 +2852,7 @@ int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused)
 		     trace__set_duration),
 	OPT_BOOLEAN(0, "sched", &trace.sched, "show blocking scheduler events"),
 	OPT_INCR('v', "verbose", &verbose, "be more verbose"),
+	OPT_BOOLEAN('q', "quiet", &quiet, "Do not show any message"),
 	OPT_BOOLEAN('T', "time", &trace.full_time,
 		    "Show full timestamp, not time relative to first start"),
 	OPT_BOOLEAN('s', "summary", &trace.summary_only,
@@ -2898,6 +2902,8 @@ int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused)
 
 	argc = parse_options_subcommand(argc, argv, trace_options, trace_subcommands,
 				 trace_usage, PARSE_OPT_STOP_AT_NON_OPTION);
+	if (quiet)
+		perf_quiet_option();
 
 	err = bpf__setup_stdout(trace.evlist);
 	if (err) {
@@ -2957,7 +2963,8 @@ int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused)
 	if (output_name != NULL) {
 		err = trace__open_output(&trace, output_name);
 		if (err < 0) {
-			perror("failed to create output file");
+			pr_err("failed to create output file: %s\n",
+			       str_error_r(errno, bf, sizeof(bf)));
 			goto out;
 		}
 	}
@@ -2966,15 +2973,19 @@ int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused)
 
 	err = target__validate(&trace.opts.target);
 	if (err) {
-		target__strerror(&trace.opts.target, err, bf, sizeof(bf));
-		fprintf(trace.output, "%s", bf);
+		if (!quiet) {
+			target__strerror(&trace.opts.target, err, bf, sizeof(bf));
+			fprintf(trace.output, "%s", bf);
+		}
 		goto out_close;
 	}
 
 	err = target__parse_uid(&trace.opts.target);
 	if (err) {
-		target__strerror(&trace.opts.target, err, bf, sizeof(bf));
-		fprintf(trace.output, "%s", bf);
+		if (!quiet) {
+			target__strerror(&trace.opts.target, err, bf, sizeof(bf));
+			fprintf(trace.output, "%s", bf);
+		}
 		goto out_close;
 	}
 
Signature · 1 line
2.11.0