aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdrian Hunter <adrian.hunter@intel.com>2015-04-09 11:54:05 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2015-04-29 09:37:57 -0400
commit400ea6d327ff43311c73dd4a000eb064ae20140c (patch)
tree74c1ccad00af3ff502015e725abef19727603bda
parent0f0aa5e0693ce4000a7657cc47ce4f32b86b91ba (diff)
perf script: Add field option 'flags' to print sample flags
Instruction tracing will typically have access to information about the instruction being executed for a particular ip sample. Some of that information will be available in the 'flags' member of struct perf_sample. With the addition of transactions events synthesis to Instruction Tracing options, there is a need to be able easily to see the flags because they show whether the ip is at the start, commit or abort of a tranasaction. Consequently add an option to display the flags. The flags are "bcrosyiABEx" which stand for branch, call, return, conditional, system, asynchronous, interrupt, transaction abort, trace begin, trace end, and in transaction, respectively. Example using Intel PT: perf script -fip,time,event,sym,addr,flags ... 1288.721584105: branches:u: bo 401146 main => 401152 main 1288.721584105: transactions: x 0 401164 main 1288.721584105: branches:u: bx 40117c main => 40119b main 1288.721584105: branches:u: box 4011a4 main => 40117e main 1288.721584105: branches:u: bcx 401187 main => 401094 g ... 1288.721591645: branches:u: bx 4010c4 g => 4010cb g 1288.721591645: branches:u: brx 4010cc g => 401189 main 1288.721591645: transactions: 0 4011a6 main 1288.721593199: branches:u: b 4011a9 main => 4011af main 1288.721593199: branches:u: bo 4011bc main => 40113e main 1288.721593199: branches:u: b 401150 main => 40115a main 1288.721593199: transactions: x 0 401164 main 1288.721593199: branches:u: bx 40117c main => 40119b main 1288.721593199: branches:u: box 4011a4 main => 40117e main 1288.721593199: branches:u: bcx 401187 main => 40105e f ... 1288.722284747: branches:u: brx 401093 f => 401189 main 1288.722284747: branches:u: box 4011a4 main => 40117e main 1288.722284747: branches:u: bcx 401187 main => 40105e f 1288.722285883: transactions: bA 0 401071 f 1288.722285883: branches:u: bA 401071 f => 40116a main 1288.722285883: branches:u: bE 40116a main => 0 [unknown] 1288.722297174: branches:u: bB 0 [unknown] => 40116a main ... Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Namhyung Kim <namhyung@gmail.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/r/1428594864-29309-26-git-send-email-adrian.hunter@intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/Documentation/perf-script.txt9
-rw-r--r--tools/perf/builtin-script.c34
-rw-r--r--tools/perf/util/event.h2
3 files changed, 39 insertions, 6 deletions
diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt
index 05df64804def..b29cd2f17d13 100644
--- a/tools/perf/Documentation/perf-script.txt
+++ b/tools/perf/Documentation/perf-script.txt
@@ -115,7 +115,8 @@ OPTIONS
115-f:: 115-f::
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, srcline, period. 118 comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, symoff,
119 srcline, period, flags.
119 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,
120 to indicate to which event type the field list applies. 121 to indicate to which event type the field list applies.
121 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
@@ -165,6 +166,12 @@ OPTIONS
165 166
166 At this point usage is displayed, and perf-script exits. 167 At this point usage is displayed, and perf-script exits.
167 168
169 The flags field is synthesized and may have a value when Instruction
170 Trace decoding. The flags are "bcrosyiABEx" which stand for branch,
171 call, return, conditional, system, asynchronous, interrupt,
172 transaction abort, trace begin, trace end, and in transaction,
173 respectively.
174
168 Finally, a user may not set fields to none for all event types. 175 Finally, a user may not set fields to none for all event types.
169 i.e., -f "" is not allowed. 176 i.e., -f "" is not allowed.
170 177
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 7682665456fe..cd2f38bf7573 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -27,6 +27,7 @@ static u64 nr_unordered;
27static bool no_callchain; 27static bool no_callchain;
28static bool latency_format; 28static bool latency_format;
29static bool system_wide; 29static bool system_wide;
30static bool print_flags;
30static const char *cpu_list; 31static const char *cpu_list;
31static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS); 32static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
32 33
@@ -446,6 +447,25 @@ static void print_sample_bts(union perf_event *event,
446 printf("\n"); 447 printf("\n");
447} 448}
448 449
450static void print_sample_flags(u32 flags)
451{
452 const char *chars = PERF_IP_FLAG_CHARS;
453 const int n = strlen(PERF_IP_FLAG_CHARS);
454 char str[33];
455 int i, pos = 0;
456
457 for (i = 0; i < n; i++, flags >>= 1) {
458 if (flags & 1)
459 str[pos++] = chars[i];
460 }
461 for (; i < 32; i++, flags >>= 1) {
462 if (flags & 1)
463 str[pos++] = '?';
464 }
465 str[pos] = 0;
466 printf(" %-4s ", str);
467}
468
449static void process_event(union perf_event *event, struct perf_sample *sample, 469static void process_event(union perf_event *event, struct perf_sample *sample,
450 struct perf_evsel *evsel, struct addr_location *al) 470 struct perf_evsel *evsel, struct addr_location *al)
451{ 471{
@@ -465,6 +485,9 @@ static void process_event(union perf_event *event, struct perf_sample *sample,
465 printf("%s: ", evname ? evname : "[unknown]"); 485 printf("%s: ", evname ? evname : "[unknown]");
466 } 486 }
467 487
488 if (print_flags)
489 print_sample_flags(sample->flags);
490
468 if (is_bts_event(attr)) { 491 if (is_bts_event(attr)) {
469 print_sample_bts(event, sample, evsel, thread, al); 492 print_sample_bts(event, sample, evsel, thread, al);
470 return; 493 return;
@@ -1000,12 +1023,15 @@ static int parse_output_fields(const struct option *opt __maybe_unused,
1000 } 1023 }
1001 } 1024 }
1002 1025
1003 tok = strtok(tok, ","); 1026 for (tok = strtok(tok, ","); tok; tok = strtok(NULL, ",")) {
1004 while (tok) {
1005 for (i = 0; i < imax; ++i) { 1027 for (i = 0; i < imax; ++i) {
1006 if (strcmp(tok, all_output_options[i].str) == 0) 1028 if (strcmp(tok, all_output_options[i].str) == 0)
1007 break; 1029 break;
1008 } 1030 }
1031 if (i == imax && strcmp(tok, "flags") == 0) {
1032 print_flags = true;
1033 continue;
1034 }
1009 if (i == imax) { 1035 if (i == imax) {
1010 fprintf(stderr, "Invalid field requested.\n"); 1036 fprintf(stderr, "Invalid field requested.\n");
1011 rc = -EINVAL; 1037 rc = -EINVAL;
@@ -1033,8 +1059,6 @@ static int parse_output_fields(const struct option *opt __maybe_unused,
1033 } 1059 }
1034 output[type].fields |= all_output_options[i].field; 1060 output[type].fields |= all_output_options[i].field;
1035 } 1061 }
1036
1037 tok = strtok(NULL, ",");
1038 } 1062 }
1039 1063
1040 if (type >= 0) { 1064 if (type >= 0) {
@@ -1555,7 +1579,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
1555 "comma separated output fields prepend with 'type:'. " 1579 "comma separated output fields prepend with 'type:'. "
1556 "Valid types: hw,sw,trace,raw. " 1580 "Valid types: hw,sw,trace,raw. "
1557 "Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso," 1581 "Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso,"
1558 "addr,symoff,period", parse_output_fields), 1582 "addr,symoff,period,flags", parse_output_fields),
1559 OPT_BOOLEAN('a', "all-cpus", &system_wide, 1583 OPT_BOOLEAN('a', "all-cpus", &system_wide,
1560 "system-wide collection from all CPUs"), 1584 "system-wide collection from all CPUs"),
1561 OPT_STRING('S', "symbols", &symbol_conf.sym_list_str, "symbol[,symbol...]", 1585 OPT_STRING('S', "symbols", &symbol_conf.sym_list_str, "symbol[,symbol...]",
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
index 8ef37251a7a9..80e9f5969a39 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -157,6 +157,8 @@ enum {
157 PERF_IP_FLAG_IN_TX = 1ULL << 10, 157 PERF_IP_FLAG_IN_TX = 1ULL << 10,
158}; 158};
159 159
160#define PERF_IP_FLAG_CHARS "bcrosyiABEx"
161
160#define PERF_BRANCH_MASK (\ 162#define PERF_BRANCH_MASK (\
161 PERF_IP_FLAG_BRANCH |\ 163 PERF_IP_FLAG_BRANCH |\
162 PERF_IP_FLAG_CALL |\ 164 PERF_IP_FLAG_CALL |\