linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] perf script: Fix --call-trace for Intel PT
@ 2020-05-27 18:02 Adrian Hunter
  2020-05-28 14:32 ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 2+ messages in thread
From: Adrian Hunter @ 2020-05-27 18:02 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo; +Cc: Jiri Olsa, linux-kernel

Make process_attr() respect -F-ip, noting also that the condition in
process_attr() (callchain_param.record_mode != CALLCHAIN_NONE) is always
true so test the sample type directly.

Example:

  Before:

    $ perf record -e intel_pt//u uname
    Linux
    [ perf record: Woken up 1 times to write data ]
    [ perf record: Captured and wrote 0.033 MB perf.data ]
    $ perf script --call-trace | head -5
           uname 30992 [006] 41758.313696574:  cbr: 42 freq: 4219 MHz (156%)                    0 [unknown] ([unknown]                                         )
           uname 30992 [006] 41758.313696907: _start                               7f71792c4100 _start+0x0 (/usr/lib/x86_64-linux-gnu/ld-2.31.so              )
           uname 30992 [006] 41758.313699574:     _dl_start                        7f71792c4103 _start+0x3 (/usr/lib/x86_64-linux-gnu/ld-2.31.so              )
           uname 30992 [006] 41758.313699907:     _dl_start                        7f71792c4e18 _dl_start+0x28 (/usr/lib/x86_64-linux-gnu/ld-2.31.so              )
           uname 30992 [006] 41758.313701574:     _dl_start                        7f71792c5128 _dl_start+0x338 (/usr/lib/x86_64-linux-gnu/ld-2.31.so              )

  After:

    $ perf script --call-trace | head -5
           uname 30992 [006] 41758.313696574:  cbr: 42 freq: 4219 MHz (156%)
           uname 30992 [006] 41758.313696907: (/usr/lib/x86_64-linux-gnu/ld-2.31.so              )      _start
           uname 30992 [006] 41758.313699574: (/usr/lib/x86_64-linux-gnu/ld-2.31.so              )          _dl_start
           uname 30992 [006] 41758.313699907: (/usr/lib/x86_64-linux-gnu/ld-2.31.so              )          _dl_start
           uname 30992 [006] 41758.313701574: (/usr/lib/x86_64-linux-gnu/ld-2.31.so              )          _dl_start

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Fixes: f288e8e1aa4f ("perf script: Enable IP fields for callchains")
---
 tools/perf/builtin-script.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 5bdd1a393399..3249ead2deef 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -167,6 +167,7 @@ static struct {
 	u64 fields;
 	u64 invalid_fields;
 	u64 user_set_fields;
+	u64 user_unset_fields;
 } output[OUTPUT_TYPE_MAX] = {
 
 	[PERF_TYPE_HARDWARE] = {
@@ -2132,10 +2133,18 @@ static int process_attr(struct perf_tool *tool, union perf_event *event,
 	sample_type = perf_evlist__combined_sample_type(evlist);
 	callchain_param_setup(sample_type);
 
-	/* Enable fields for callchain entries, if it got enabled. */
-	if (callchain_param.record_mode != CALLCHAIN_NONE) {
-		output[output_type(evsel->core.attr.type)].fields |= PERF_OUTPUT_IP |
-								     PERF_OUTPUT_SYM;
+	/* Enable fields for callchain entries */
+	if (symbol_conf.use_callchain &&
+	    (sample_type & PERF_SAMPLE_CALLCHAIN ||
+	     sample_type & PERF_SAMPLE_BRANCH_STACK ||
+	     (sample_type & PERF_SAMPLE_REGS_USER &&
+	      sample_type & PERF_SAMPLE_STACK_USER))) {
+		int type = output_type(evsel->core.attr.type);
+
+		if (!(output[type].user_unset_fields & PERF_OUTPUT_IP))
+			output[type].fields |= PERF_OUTPUT_IP;
+		if (!(output[type].user_unset_fields & PERF_OUTPUT_SYM))
+			output[type].fields |= PERF_OUTPUT_SYM;
 	}
 	set_print_ip_opts(&evsel->core.attr);
 	return 0;
@@ -2704,9 +2713,11 @@ static int parse_output_fields(const struct option *opt __maybe_unused,
 					if (change == REMOVE) {
 						output[j].fields &= ~all_output_options[i].field;
 						output[j].user_set_fields &= ~all_output_options[i].field;
+						output[j].user_unset_fields |= all_output_options[i].field;
 					} else {
 						output[j].fields |= all_output_options[i].field;
 						output[j].user_set_fields |= all_output_options[i].field;
+						output[j].user_unset_fields &= ~all_output_options[i].field;
 					}
 					output[j].user_set = true;
 					output[j].wildcard_set = true;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] perf script: Fix --call-trace for Intel PT
  2020-05-27 18:02 [PATCH] perf script: Fix --call-trace for Intel PT Adrian Hunter
@ 2020-05-28 14:32 ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 2+ messages in thread
From: Arnaldo Carvalho de Melo @ 2020-05-28 14:32 UTC (permalink / raw)
  To: Adrian Hunter; +Cc: Jiri Olsa, linux-kernel

Em Wed, May 27, 2020 at 09:02:50PM +0300, Adrian Hunter escreveu:
> Make process_attr() respect -F-ip, noting also that the condition in
> process_attr() (callchain_param.record_mode != CALLCHAIN_NONE) is always
> true so test the sample type directly.
> 
> Example:
> 
>   Before:
> 
>     $ perf record -e intel_pt//u uname
>     Linux
>     [ perf record: Woken up 1 times to write data ]
>     [ perf record: Captured and wrote 0.033 MB perf.data ]
>     $ perf script --call-trace | head -5
>            uname 30992 [006] 41758.313696574:  cbr: 42 freq: 4219 MHz (156%)                    0 [unknown] ([unknown]                                         )
>            uname 30992 [006] 41758.313696907: _start                               7f71792c4100 _start+0x0 (/usr/lib/x86_64-linux-gnu/ld-2.31.so              )
>            uname 30992 [006] 41758.313699574:     _dl_start                        7f71792c4103 _start+0x3 (/usr/lib/x86_64-linux-gnu/ld-2.31.so              )
>            uname 30992 [006] 41758.313699907:     _dl_start                        7f71792c4e18 _dl_start+0x28 (/usr/lib/x86_64-linux-gnu/ld-2.31.so              )
>            uname 30992 [006] 41758.313701574:     _dl_start                        7f71792c5128 _dl_start+0x338 (/usr/lib/x86_64-linux-gnu/ld-2.31.so              )
> 
>   After:
> 
>     $ perf script --call-trace | head -5
>            uname 30992 [006] 41758.313696574:  cbr: 42 freq: 4219 MHz (156%)
>            uname 30992 [006] 41758.313696907: (/usr/lib/x86_64-linux-gnu/ld-2.31.so              )      _start
>            uname 30992 [006] 41758.313699574: (/usr/lib/x86_64-linux-gnu/ld-2.31.so              )          _dl_start
>            uname 30992 [006] 41758.313699907: (/usr/lib/x86_64-linux-gnu/ld-2.31.so              )          _dl_start
>            uname 30992 [006] 41758.313701574: (/usr/lib/x86_64-linux-gnu/ld-2.31.so              )          _dl_start

Thanks, tested and applied.

- Arnaldo
 
> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
> Fixes: f288e8e1aa4f ("perf script: Enable IP fields for callchains")
> ---
>  tools/perf/builtin-script.c | 19 +++++++++++++++----
>  1 file changed, 15 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
> index 5bdd1a393399..3249ead2deef 100644
> --- a/tools/perf/builtin-script.c
> +++ b/tools/perf/builtin-script.c
> @@ -167,6 +167,7 @@ static struct {
>  	u64 fields;
>  	u64 invalid_fields;
>  	u64 user_set_fields;
> +	u64 user_unset_fields;
>  } output[OUTPUT_TYPE_MAX] = {
>  
>  	[PERF_TYPE_HARDWARE] = {
> @@ -2132,10 +2133,18 @@ static int process_attr(struct perf_tool *tool, union perf_event *event,
>  	sample_type = perf_evlist__combined_sample_type(evlist);
>  	callchain_param_setup(sample_type);
>  
> -	/* Enable fields for callchain entries, if it got enabled. */
> -	if (callchain_param.record_mode != CALLCHAIN_NONE) {
> -		output[output_type(evsel->core.attr.type)].fields |= PERF_OUTPUT_IP |
> -								     PERF_OUTPUT_SYM;
> +	/* Enable fields for callchain entries */
> +	if (symbol_conf.use_callchain &&
> +	    (sample_type & PERF_SAMPLE_CALLCHAIN ||
> +	     sample_type & PERF_SAMPLE_BRANCH_STACK ||
> +	     (sample_type & PERF_SAMPLE_REGS_USER &&
> +	      sample_type & PERF_SAMPLE_STACK_USER))) {
> +		int type = output_type(evsel->core.attr.type);
> +
> +		if (!(output[type].user_unset_fields & PERF_OUTPUT_IP))
> +			output[type].fields |= PERF_OUTPUT_IP;
> +		if (!(output[type].user_unset_fields & PERF_OUTPUT_SYM))
> +			output[type].fields |= PERF_OUTPUT_SYM;
>  	}
>  	set_print_ip_opts(&evsel->core.attr);
>  	return 0;
> @@ -2704,9 +2713,11 @@ static int parse_output_fields(const struct option *opt __maybe_unused,
>  					if (change == REMOVE) {
>  						output[j].fields &= ~all_output_options[i].field;
>  						output[j].user_set_fields &= ~all_output_options[i].field;
> +						output[j].user_unset_fields |= all_output_options[i].field;
>  					} else {
>  						output[j].fields |= all_output_options[i].field;
>  						output[j].user_set_fields |= all_output_options[i].field;
> +						output[j].user_unset_fields &= ~all_output_options[i].field;
>  					}
>  					output[j].user_set = true;
>  					output[j].wildcard_set = true;
> -- 
> 2.17.1
> 

-- 

- Arnaldo

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-05-28 14:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-27 18:02 [PATCH] perf script: Fix --call-trace for Intel PT Adrian Hunter
2020-05-28 14:32 ` Arnaldo Carvalho de Melo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).