mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Stephane Eranian <eranian@google.com>
To: linux-kernel@vger.kernel.org
Cc: acme@redhat.com, peterz@infradead.org, mingo@elte.hu,
	ak@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org,
	kan.liang@intel.com, dsahern@gmail.com, adrian.hunter@intel.com
Subject: [PATCH v1 4/4] perf script: enable printing of branch stack
Date: Wed, 19 Aug 2015 10:38:26 +0200	[thread overview]
Message-ID: <1439973506-2166-5-git-send-email-eranian@google.com> (raw)
In-Reply-To: <1439973506-2166-1-git-send-email-eranian@google.com>

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


  parent reply	other threads:[~2015-08-19  8:39 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-19  8:38 [PATCH v1 0/4] perf: improve script and record for iregs and brstack Stephane Eranian
2015-08-19  8:38 ` [PATCH v1 1/4] perf script: enable printing of interrupted machine state Stephane Eranian
2015-08-19  8:38 ` [PATCH v1 2/4] perf/x86: add list of register names Stephane Eranian
2015-08-19  8:38 ` [PATCH v1 3/4] perf record: add ability to name registers to record Stephane Eranian
2015-08-20 11:18   ` Jiri Olsa
2015-08-20 20:02     ` Stephane Eranian
2015-08-19  8:38 ` Stephane Eranian [this message]
2015-08-19 22:11   ` [PATCH v1 4/4] perf script: enable printing of branch stack Andi Kleen
2015-08-19 22:20     ` Stephane Eranian
2015-08-19 23:32       ` Andi Kleen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1439973506-2166-5-git-send-email-eranian@google.com \
    --to=eranian@google.com \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=ak@linux.intel.com \
    --cc=dsahern@gmail.com \
    --cc=jolsa@redhat.com \
    --cc=kan.liang@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome