Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1209703 > unrolled thread

[PATCH v1 4/4] perf script: enable printing of branch stack

Started byStephane Eranian <eranian@google.com>
First post2015-08-19 10:40 +0200
Last post2015-08-20 01:40 +0200
Articles 4 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH v1 4/4] perf script: enable printing of branch stack Stephane Eranian <eranian@google.com> - 2015-08-19 10:40 +0200
    Re: [PATCH v1 4/4] perf script: enable printing of branch stack Andi Kleen <ak@linux.intel.com> - 2015-08-20 00:20 +0200
      Re: [PATCH v1 4/4] perf script: enable printing of branch stack Stephane Eranian <eranian@google.com> - 2015-08-20 00:30 +0200
        Re: [PATCH v1 4/4] perf script: enable printing of branch stack Andi Kleen <ak@linux.intel.com> - 2015-08-20 01:40 +0200

#1209703 — [PATCH v1 4/4] perf script: enable printing of branch stack

FromStephane Eranian <eranian@google.com>
Date2015-08-19 10:40 +0200
Subject[PATCH v1 4/4] perf script: enable printing of branch stack
Message-ID<pZ74B-C4-5@gated-at.bofh.it>
This patch improves perf script by enabling printing of the
branch stack via the 'brstack' argument to the field selection
option -F. The option is off by default and operates only if the
perf.data file has branch stack content.

The branches are printed in to/from pairs. the most recent branch
is printed first. The number of branch entries vary based on the
underlying hardware are filtering used.

Signed-off-by: Stephane Eranian <eranian@google.com>
---
 tools/perf/Documentation/perf-script.txt |  2 +-
 tools/perf/builtin-script.c              | 23 ++++++++++++++++++++++-
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt
index 4b0acf4..fd95384 100644
--- a/tools/perf/Documentation/perf-script.txt
+++ b/tools/perf/Documentation/perf-script.txt
@@ -116,7 +116,7 @@ OPTIONS
 --fields::
         Comma separated list of fields to print. Options are:
         comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, symoff,
-	srcline, period, iregs, flags.
+	srcline, period, iregs, brstack, flags.
         Field list can be prepended with the type, trace, sw or hw,
         to indicate to which event type the field list applies.
         e.g., -f sw:comm,tid,time,ip,sym  and -f trace:time,cpu,trace
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 3fed110..9ac7140 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -48,6 +48,7 @@ enum perf_output_field {
 	PERF_OUTPUT_SRCLINE         = 1U << 12,
 	PERF_OUTPUT_PERIOD          = 1U << 13,
 	PERF_OUTPUT_IREGS	    = 1U << 14,
+	PERF_OUTPUT_BRSTACK	    = 1U << 15,
 };
 
 struct output_option {
@@ -69,6 +70,7 @@ struct output_option {
 	{.str = "srcline", .field = PERF_OUTPUT_SRCLINE},
 	{.str = "period", .field = PERF_OUTPUT_PERIOD},
 	{.str = "iregs", .field = PERF_OUTPUT_IREGS},
+	{.str = "brstack", .field = PERF_OUTPUT_BRSTACK},
 };
 
 /* default set to maintain compatibility with current format */
@@ -419,6 +421,22 @@ static void print_sample_start(struct perf_sample *sample,
 	}
 }
 
+static void print_sample_brstack(union perf_event *event __maybe_unused,
+			  struct perf_sample *sample,
+			  struct thread *thread __maybe_unused,
+			  struct perf_event_attr *attr __maybe_unused)
+{
+	struct branch_stack *br = sample->branch_stack;
+	u64 i;
+
+	if (!(br && br->nr))
+		return;
+
+	for (i = 0; i < br->nr; i++) {
+		printf(" 0x%"PRIx64"/0x%"PRIx64" ", br->entries[i].from, br->entries[i].to);
+	}
+}
+
 static void print_sample_addr(union perf_event *event,
 			  struct perf_sample *sample,
 			  struct thread *thread,
@@ -554,6 +572,9 @@ static void process_event(union perf_event *event, struct perf_sample *sample,
 	if (PRINT_FIELD(IREGS))
 		print_sample_iregs(event, sample, thread, attr);
 
+	if (PRINT_FIELD(BRSTACK))
+		print_sample_brstack(event, sample, thread, attr);
+
 	printf("\n");
 }
 
@@ -1656,7 +1677,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
 		     "comma separated output fields prepend with 'type:'. "
 		     "Valid types: hw,sw,trace,raw. "
 		     "Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso,"
-		     "addr,symoff,period,iregs,flags", parse_output_fields),
+		     "addr,symoff,period,iregs,brstack,flags", parse_output_fields),
 	OPT_BOOLEAN('a', "all-cpus", &system_wide,
 		    "system-wide collection from all CPUs"),
 	OPT_STRING('S', "symbols", &symbol_conf.sym_list_str, "symbol[,symbol...]",
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1210055

FromAndi Kleen <ak@linux.intel.com>
Date2015-08-20 00:20 +0200
Message-ID<pZjSa-2jo-19@gated-at.bofh.it>
In reply to#1209703
On Wed, Aug 19, 2015 at 10:38:26AM +0200, Stephane Eranian wrote:
> This patch improves perf script by enabling printing of the
> branch stack via the 'brstack' argument to the field selection
> option -F. The option is off by default and operates only if the
> perf.data file has branch stack content.

Thanks that's very useful. I wanted that several times.
> 
> +static void print_sample_brstack(union perf_event *event __maybe_unused,
> +			  struct perf_sample *sample,
> +			  struct thread *thread __maybe_unused,
> +			  struct perf_event_attr *attr __maybe_unused)
> +{
> +	struct branch_stack *br = sample->branch_stack;
> +	u64 i;
> +
> +	if (!(br && br->nr))
> +		return;
> +
> +	for (i = 0; i < br->nr; i++) {
> +		printf(" 0x%"PRIx64"/0x%"PRIx64" ", br->entries[i].from, br->entries[i].to);

Should print the various flags too. Also tip just added cycles information.

Also it would be good to resolve the addresses to symbol + offset 
(and perhaps have support for srcline too).


-Andi
-- 
ak@linux.intel.com -- Speaking for myself only
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1210057

FromStephane Eranian <eranian@google.com>
Date2015-08-20 00:30 +0200
Message-ID<pZk1Q-2v8-15@gated-at.bofh.it>
In reply to#1210055
On Wed, Aug 19, 2015 at 3:11 PM, Andi Kleen <ak@linux.intel.com> wrote:
> On Wed, Aug 19, 2015 at 10:38:26AM +0200, Stephane Eranian wrote:
>> This patch improves perf script by enabling printing of the
>> branch stack via the 'brstack' argument to the field selection
>> option -F. The option is off by default and operates only if the
>> perf.data file has branch stack content.
>
> Thanks that's very useful. I wanted that several times.
>>
>> +static void print_sample_brstack(union perf_event *event __maybe_unused,
>> +                       struct perf_sample *sample,
>> +                       struct thread *thread __maybe_unused,
>> +                       struct perf_event_attr *attr __maybe_unused)
>> +{
>> +     struct branch_stack *br = sample->branch_stack;
>> +     u64 i;
>> +
>> +     if (!(br && br->nr))
>> +             return;
>> +
>> +     for (i = 0; i < br->nr; i++) {
>> +             printf(" 0x%"PRIx64"/0x%"PRIx64" ", br->entries[i].from, br->entries[i].to);
>
> Should print the various flags too. Also tip just added cycles information.
>
Ok, I will add that in v2.

> Also it would be good to resolve the addresses to symbol + offset

But then, that becomes harder to post-process or even read with long
C++ signatures.

> (and perhaps have support for srcline too).
>
>
> -Andi
> --
> ak@linux.intel.com -- Speaking for myself only
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1210084

FromAndi Kleen <ak@linux.intel.com>
Date2015-08-20 01:40 +0200
Message-ID<pZl7A-41B-5@gated-at.bofh.it>
In reply to#1210057
> > Also it would be good to resolve the addresses to symbol + offset
> 
> But then, that becomes harder to post-process or even read with long
> C++ signatures.

Ok. Maybe make it optional? 

For many usages resolved addresses will be much more useful than raw.
Normall call stacks also do that.

-Andi

-- 
ak@linux.intel.com -- Speaking for myself only
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web