perf script: Show proper message when failed list scripts
PATCH 1/2 perf script: Show proper message when failed list scripts
Perf shows the usage message when perf scripts folder failed to open, which misleads users to let them think the command is mistyped. This patch shows proper message and guide the users to check PERF_EXEC_PATH environment in that case.
Before:
$ perf script --list
Usage: perf script [<options>]
or: perf script [<options>] record <script> [<record-options>] <command>
or: perf script [<options>] report <script> [script-args]
or: perf script [<options>] <script> [<record-options>] <command>
or: perf script [<options>] <top-script> [script-args]
-l, --list list available scripts
After:
$ perf script --list open(/home/user/perf-core/scripts) failed. Check for "PERF_EXEC_PATH" env to set scripts dir.
--- tools/perf/builtin-script.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
tools/perf/builtin-script.c +7 -2
@@ -1690,8 +1690,13 @@ static int list_available_scripts(const struct option *opt __maybe_unused,snprintf (scripts_path,MAXPATHLEN ,"%s/scripts" ,get_argv_exec_path ()); scripts_dir =opendir (scripts_path); -if (!scripts_dir) -return -1 ; +if (!scripts_dir) { +fprintf (stdout, +"open(%s) failed.\n" +"Check \"PERF_EXEC_PATH\" env to set scripts dir.\n" , + scripts_path); +exit (-1 ); + }for_each_lang (scripts_path, scripts_dir, lang_dirent) { snprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path,
Signature · 1 line
1.8.5.2
PATCH 2/2 perf script: Don't disable use_callchain if input is pipe
Because perf data from pipe do not have a header with evsel attr, we should not check that and disable symbol_conf.use_callchain. Otherwise, perf script won't show callchains even if the data stream contains callchain.
Before:
$ perf record -g -o - uname |perf script Linux [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.000 MB - ] uname 1828 182630.186578: 250000 cpu-clock: ..b9499 setup_arg_pages uname 1828 182630.186850: 250000 cpu-clock: ..83b20 ___might_sleep uname 1828 182630.187153: 250000 cpu-clock: ..4b6be file_map_prot_ch ...
After:
$ perf record -g -o - uname |perf script
Linux
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.000 MB - ]
uname 1833 182675.927099: 250000 cpu-clock:
ba5520 _raw_spin_lock+0xfe200040 ([kernel.kallsyms])
389dd4 expand_downwards+0xfe200154 ([kernel.kallsyms])
389f34 expand_stack+0xfe200024 ([kernel.kallsyms])
3b957e setup_arg_pages+0xfe20019e ([kernel.kallsyms])
40c80f load_elf_binary+0xfe20042f ([kernel.kallsyms])
...--- tools/perf/builtin-script.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
tools/perf/builtin-script.c +3 -1
@@ -371,14 +371,16 @@ static int perf_session__check_output_opt(struct perf_session *session)if (!no_callchain) {bool use_callchain = false; +bool not_pipe = false;evlist__for_each_entry (session->evlist, evsel) { + not_pipe = true;if (evsel->attr.sample_type &PERF_SAMPLE_CALLCHAIN ) { use_callchain = true;break ; } } -if (!use_callchain) +if (not_pipe && !use_callchain) symbol_conf.use_callchain = false; }
Signature · 1 line
1.8.5.2
Re: [PATCH 2/2] perf script: Don't disable use_callchain if input is pipe
ping.
Quoted 55 lines · He Kuang
Because perf data from pipe do not have a header with evsel attr, we should not check that and disable symbol_conf.use_callchain. Otherwise, perf script won't show callchains even if the data stream contains callchain.
Before:
$ perf record -g -o - uname |perf script Linux [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.000 MB - ] uname 1828 182630.186578: 250000 cpu-clock: ..b9499 setup_arg_pages uname 1828 182630.186850: 250000 cpu-clock: ..83b20 ___might_sleep uname 1828 182630.187153: 250000 cpu-clock: ..4b6be file_map_prot_ch ...After:
$ perf record -g -o - uname |perf script Linux [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.000 MB - ] uname 1833 182675.927099: 250000 cpu-clock: ba5520 _raw_spin_lock+0xfe200040 ([kernel.kallsyms]) 389dd4 expand_downwards+0xfe200154 ([kernel.kallsyms]) 389f34 expand_stack+0xfe200024 ([kernel.kallsyms]) 3b957e setup_arg_pages+0xfe20019e ([kernel.kallsyms]) 40c80f load_elf_binary+0xfe20042f ([kernel.kallsyms]) ...Signed-off-by He Kuang <[email protected]>--- tools/perf/builtin-script.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)tools/perf/builtin-script.c +3
-1@@ -371,14 +371,16 @@ static int perf_session__check_output_opt(struct perf_session *session)if (!no_callchain) {bool use_callchain = false; +bool not_pipe = false;evlist__for_each_entry (session->evlist, evsel) { + not_pipe = true;if (evsel->attr.sample_type &PERF_SAMPLE_CALLCHAIN ) { use_callchain = true;break ; } } -if (!use_callchain) +if (not_pipe && !use_callchain) symbol_conf.use_callchain = false; }
Arnaldo Carvalho de Melo
maintainerRe: [PATCH 2/2] perf script: Don't disable use_callchain if input is pipe
Em Mon, Aug 15, 2016 at 06:25:15PM +0800, Hekuang escreveu:
Quoted 1 line
ping.
Thanks, tested and applied both patches.
- Arnaldo
Quoted 54 lines · He Kuang
Quoted 52 lines
Because perf data from pipe do not have a header with evsel attr, we should not check that and disable symbol_conf.use_callchain. Otherwise, perf script won't show callchains even if the data stream contains callchain.
Before:
$ perf record -g -o - uname |perf script Linux [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.000 MB - ] uname 1828 182630.186578: 250000 cpu-clock: ..b9499 setup_arg_pages uname 1828 182630.186850: 250000 cpu-clock: ..83b20 ___might_sleep uname 1828 182630.187153: 250000 cpu-clock: ..4b6be file_map_prot_ch ...After:
$ perf record -g -o - uname |perf script Linux [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.000 MB - ] uname 1833 182675.927099: 250000 cpu-clock: ba5520 _raw_spin_lock+0xfe200040 ([kernel.kallsyms]) 389dd4 expand_downwards+0xfe200154 ([kernel.kallsyms]) 389f34 expand_stack+0xfe200024 ([kernel.kallsyms]) 3b957e setup_arg_pages+0xfe20019e ([kernel.kallsyms]) 40c80f load_elf_binary+0xfe20042f ([kernel.kallsyms]) ...Signed-off-by He Kuang <[email protected]>--- tools/perf/builtin-script.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)tools/perf/builtin-script.c +3
-1@@ -371,14 +371,16 @@ static int perf_session__check_output_opt(struct perf_session *session)if (!no_callchain) {bool use_callchain = false; +bool not_pipe = false;evlist__for_each_entry (session->evlist, evsel) { + not_pipe = true;if (evsel->attr.sample_type &PERF_SAMPLE_CALLCHAIN ) { use_callchain = true;break ; } } -if (!use_callchain) +if (not_pipe && !use_callchain) symbol_conf.use_callchain = false; }
tip-bot for He Kuang
merge bot[tip:perf/urgent] perf script: Don't disable use_callchain if input is pipe
In reply to He Kuangperf script: Don't disable use_callchain if input is pipe
Commit-ID: 71ac899b5ed7edfd8fa2a4e075194380b1de2d7f Gitweb: http://git.kernel.org/tip/71ac899b5ed7edfd8fa2a4e075194380b1de2d7f Author: He Kuang <[email protected]> AuthorDate: Thu, 4 Aug 2016 11:25:43 +0000 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 15 Aug 2016 13:23:49 -0300
perf script: Don't disable use_callchain if input is pipe
Because perf data from pipe do not have a header with evsel attr, we should not check that and disable symbol_conf.use_callchain. Otherwise, perf script won't show callchains even if the data stream contains callchain.
Before:
$ perf record -g -o - uname |perf script Linux [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.000 MB - ] uname 1828 182630.186578: 250000 cpu-clock: ..b9499 setup_arg_pages uname 1828 182630.186850: 250000 cpu-clock: ..83b20 ___might_sleep uname 1828 182630.187153: 250000 cpu-clock: ..4b6be file_map_prot_ch ...
After:
$ perf record -g -o - uname |perf script
Linux
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.000 MB - ]
uname 1833 182675.927099: 250000 cpu-clock:
ba5520 _raw_spin_lock+0xfe200040 ([kernel.kallsyms])
389dd4 expand_downwards+0xfe200154 ([kernel.kallsyms])
389f34 expand_stack+0xfe200024 ([kernel.kallsyms])
3b957e setup_arg_pages+0xfe20019e ([kernel.kallsyms])
40c80f load_elf_binary+0xfe20042f ([kernel.kallsyms])
...--- tools/perf/builtin-script.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
tools/perf/builtin-script.c +3 -1
@@ -371,14 +371,16 @@ static int perf_session__check_output_opt(struct perf_session *session)if (!no_callchain) {bool use_callchain = false; +bool not_pipe = false;evlist__for_each_entry (session->evlist, evsel) { + not_pipe = true;if (evsel->attr.sample_type &PERF_SAMPLE_CALLCHAIN ) { use_callchain = true;break ; } } -if (!use_callchain) +if (not_pipe && !use_callchain) symbol_conf.use_callchain = false; }
tip-bot for He Kuang
merge botperf script: Show proper message when failed list scripts
Commit-ID: 88ded4d8d94a550624e1827478e13fecf97a7b0a Gitweb: http://git.kernel.org/tip/88ded4d8d94a550624e1827478e13fecf97a7b0a Author: He Kuang <[email protected]> AuthorDate: Thu, 4 Aug 2016 11:25:42 +0000 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 15 Aug 2016 13:17:10 -0300
perf script: Show proper message when failed list scripts
Perf shows the usage message when perf scripts folder failed to open, which misleads users to let them think the command is being mistyped.
This patch shows a proper message and guides users to check the PERF_EXEC_PATH environment variable in that case.
Before:
$ perf script --list
Usage: perf script [<options>]
or: perf script [<options>] record <script> [<record-options>] <command>
or: perf script [<options>] report <script> [script-args]
or: perf script [<options>] <script> [<record-options>] <command>
or: perf script [<options>] <top-script> [script-args]
-l, --list list available scripts
After:
$ perf script --list open(/home/user/perf-core/scripts) failed. Check for "PERF_EXEC_PATH" env to set scripts dir.
--- tools/perf/builtin-script.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
tools/perf/builtin-script.c +7 -2
@@ -1690,8 +1690,13 @@ static int list_available_scripts(const struct option *opt __maybe_unused,snprintf (scripts_path,MAXPATHLEN ,"%s/scripts" ,get_argv_exec_path ()); scripts_dir =opendir (scripts_path); -if (!scripts_dir) -return -1 ; +if (!scripts_dir) { +fprintf (stdout, +"open(%s) failed.\n" +"Check \"PERF_EXEC_PATH\" env to set scripts dir.\n" , + scripts_path); +exit (-1 ); + }for_each_lang (scripts_path, scripts_dir, lang_dirent) { snprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path,