aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephane Eranian <eranian@google.com>2015-08-31 12:41:10 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2015-08-31 16:51:07 -0400
commitfc36f9485aee3a62b22be1f561543a31bce6d48e (patch)
treeb110b85374ec74f5f05ed9e58b8105793cc951fc
parentd988d5ee647861706bc7a391ddbc29429b50f00e (diff)
perf script: Enable printing of interrupted machine state
This patch adds the output of the interrupted machine state (iregs) to perf script. It presents them as NAME:VALUE so this is easy to parse during post processing. To capture the interrupted machine state: $ perf record -I .... to display iregs, use the -F option: $ perf script -F ip,iregs 40afc2 AX:0x6c5770 BX:0x1e CX:0x5f4d80a DX:0x101010101010101 SI:0x1 Signed-off-by: Stephane Eranian <eranian@google.com> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Kan Liang <kan.liang@intel.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/1441039273-16260-2-git-send-email-eranian@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/Documentation/perf-script.txt2
-rw-r--r--tools/perf/builtin-script.c31
2 files changed, 31 insertions, 2 deletions
diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt
index 614b2c7b0293..dc3ec783b7bd 100644
--- a/tools/perf/Documentation/perf-script.txt
+++ b/tools/perf/Documentation/perf-script.txt
@@ -116,7 +116,7 @@ OPTIONS
116--fields:: 116--fields::
117 Comma separated list of fields to print. Options are: 117 Comma separated list of fields to print. Options are:
118 comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, symoff, 118 comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, symoff,
119 srcline, period, flags. 119 srcline, period, iregs, flags.
120 Field list can be prepended with the type, trace, sw or hw, 120 Field list can be prepended with the type, trace, sw or hw,
121 to indicate to which event type the field list applies. 121 to indicate to which event type the field list applies.
122 e.g., -f sw:comm,tid,time,ip,sym and -f trace:time,cpu,trace 122 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 4430340292c0..eb51325e8ad9 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -6,6 +6,7 @@
6#include "util/exec_cmd.h" 6#include "util/exec_cmd.h"
7#include "util/header.h" 7#include "util/header.h"
8#include "util/parse-options.h" 8#include "util/parse-options.h"
9#include "util/perf_regs.h"
9#include "util/session.h" 10#include "util/session.h"
10#include "util/tool.h" 11#include "util/tool.h"
11#include "util/symbol.h" 12#include "util/symbol.h"
@@ -46,6 +47,7 @@ enum perf_output_field {
46 PERF_OUTPUT_SYMOFFSET = 1U << 11, 47 PERF_OUTPUT_SYMOFFSET = 1U << 11,
47 PERF_OUTPUT_SRCLINE = 1U << 12, 48 PERF_OUTPUT_SRCLINE = 1U << 12,
48 PERF_OUTPUT_PERIOD = 1U << 13, 49 PERF_OUTPUT_PERIOD = 1U << 13,
50 PERF_OUTPUT_IREGS = 1U << 14,
49}; 51};
50 52
51struct output_option { 53struct output_option {
@@ -66,6 +68,7 @@ struct output_option {
66 {.str = "symoff", .field = PERF_OUTPUT_SYMOFFSET}, 68 {.str = "symoff", .field = PERF_OUTPUT_SYMOFFSET},
67 {.str = "srcline", .field = PERF_OUTPUT_SRCLINE}, 69 {.str = "srcline", .field = PERF_OUTPUT_SRCLINE},
68 {.str = "period", .field = PERF_OUTPUT_PERIOD}, 70 {.str = "period", .field = PERF_OUTPUT_PERIOD},
71 {.str = "iregs", .field = PERF_OUTPUT_IREGS},
69}; 72};
70 73
71/* default set to maintain compatibility with current format */ 74/* default set to maintain compatibility with current format */
@@ -255,6 +258,11 @@ static int perf_evsel__check_attr(struct perf_evsel *evsel,
255 PERF_OUTPUT_PERIOD)) 258 PERF_OUTPUT_PERIOD))
256 return -EINVAL; 259 return -EINVAL;
257 260
261 if (PRINT_FIELD(IREGS) &&
262 perf_evsel__check_stype(evsel, PERF_SAMPLE_REGS_INTR, "IREGS",
263 PERF_OUTPUT_IREGS))
264 return -EINVAL;
265
258 return 0; 266 return 0;
259} 267}
260 268
@@ -352,6 +360,24 @@ out:
352 return 0; 360 return 0;
353} 361}
354 362
363static void print_sample_iregs(union perf_event *event __maybe_unused,
364 struct perf_sample *sample,
365 struct thread *thread __maybe_unused,
366 struct perf_event_attr *attr)
367{
368 struct regs_dump *regs = &sample->intr_regs;
369 uint64_t mask = attr->sample_regs_intr;
370 unsigned i = 0, r;
371
372 if (!regs)
373 return;
374
375 for_each_set_bit(r, (unsigned long *) &mask, sizeof(mask) * 8) {
376 u64 val = regs->regs[i++];
377 printf("%5s:0x%"PRIx64" ", perf_reg_name(r), val);
378 }
379}
380
355static void print_sample_start(struct perf_sample *sample, 381static void print_sample_start(struct perf_sample *sample,
356 struct thread *thread, 382 struct thread *thread,
357 struct perf_evsel *evsel) 383 struct perf_evsel *evsel)
@@ -525,6 +551,9 @@ static void process_event(union perf_event *event, struct perf_sample *sample,
525 PERF_MAX_STACK_DEPTH); 551 PERF_MAX_STACK_DEPTH);
526 } 552 }
527 553
554 if (PRINT_FIELD(IREGS))
555 print_sample_iregs(event, sample, thread, attr);
556
528 printf("\n"); 557 printf("\n");
529} 558}
530 559
@@ -1643,7 +1672,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
1643 "comma separated output fields prepend with 'type:'. " 1672 "comma separated output fields prepend with 'type:'. "
1644 "Valid types: hw,sw,trace,raw. " 1673 "Valid types: hw,sw,trace,raw. "
1645 "Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso," 1674 "Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso,"
1646 "addr,symoff,period,flags", parse_output_fields), 1675 "addr,symoff,period,iregs,flags", parse_output_fields),
1647 OPT_BOOLEAN('a', "all-cpus", &system_wide, 1676 OPT_BOOLEAN('a', "all-cpus", &system_wide,
1648 "system-wide collection from all CPUs"), 1677 "system-wide collection from all CPUs"),
1649 OPT_STRING('S', "symbols", &symbol_conf.sym_list_str, "symbol[,symbol...]", 1678 OPT_STRING('S', "symbols", &symbol_conf.sym_list_str, "symbol[,symbol...]",