Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Adrian Hunter and committed by
Arnaldo Carvalho de Melo
400ea6d3 0f0aa5e0

+39 -6
+8 -1
tools/perf/Documentation/perf-script.txt
··· 115 115 -f:: 116 116 --fields:: 117 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 120 Field list can be prepended with the type, trace, sw or hw, 120 121 to indicate to which event type the field list applies. 121 122 e.g., -f sw:comm,tid,time,ip,sym and -f trace:time,cpu,trace ··· 165 164 'trace' not valid for software events. 166 165 167 166 At this point usage is displayed, and perf-script exits. 167 + 168 + The flags field is synthesized and may have a value when Instruction 169 + Trace decoding. The flags are "bcrosyiABEx" which stand for branch, 170 + call, return, conditional, system, asynchronous, interrupt, 171 + transaction abort, trace begin, trace end, and in transaction, 172 + respectively. 168 173 169 174 Finally, a user may not set fields to none for all event types. 170 175 i.e., -f "" is not allowed.
+29 -5
tools/perf/builtin-script.c
··· 27 27 static bool no_callchain; 28 28 static bool latency_format; 29 29 static bool system_wide; 30 + static bool print_flags; 30 31 static const char *cpu_list; 31 32 static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS); 32 33 ··· 447 446 printf("\n"); 448 447 } 449 448 449 + static void print_sample_flags(u32 flags) 450 + { 451 + const char *chars = PERF_IP_FLAG_CHARS; 452 + const int n = strlen(PERF_IP_FLAG_CHARS); 453 + char str[33]; 454 + int i, pos = 0; 455 + 456 + for (i = 0; i < n; i++, flags >>= 1) { 457 + if (flags & 1) 458 + str[pos++] = chars[i]; 459 + } 460 + for (; i < 32; i++, flags >>= 1) { 461 + if (flags & 1) 462 + str[pos++] = '?'; 463 + } 464 + str[pos] = 0; 465 + printf(" %-4s ", str); 466 + } 467 + 450 468 static void process_event(union perf_event *event, struct perf_sample *sample, 451 469 struct perf_evsel *evsel, struct addr_location *al) 452 470 { ··· 484 464 const char *evname = perf_evsel__name(evsel); 485 465 printf("%s: ", evname ? evname : "[unknown]"); 486 466 } 467 + 468 + if (print_flags) 469 + print_sample_flags(sample->flags); 487 470 488 471 if (is_bts_event(attr)) { 489 472 print_sample_bts(event, sample, evsel, thread, al); ··· 1023 1000 } 1024 1001 } 1025 1002 1026 - tok = strtok(tok, ","); 1027 - while (tok) { 1003 + for (tok = strtok(tok, ","); tok; tok = strtok(NULL, ",")) { 1028 1004 for (i = 0; i < imax; ++i) { 1029 1005 if (strcmp(tok, all_output_options[i].str) == 0) 1030 1006 break; 1007 + } 1008 + if (i == imax && strcmp(tok, "flags") == 0) { 1009 + print_flags = true; 1010 + continue; 1031 1011 } 1032 1012 if (i == imax) { 1033 1013 fprintf(stderr, "Invalid field requested.\n"); ··· 1059 1033 } 1060 1034 output[type].fields |= all_output_options[i].field; 1061 1035 } 1062 - 1063 - tok = strtok(NULL, ","); 1064 1036 } 1065 1037 1066 1038 if (type >= 0) { ··· 1579 1555 "comma separated output fields prepend with 'type:'. " 1580 1556 "Valid types: hw,sw,trace,raw. " 1581 1557 "Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso," 1582 - "addr,symoff,period", parse_output_fields), 1558 + "addr,symoff,period,flags", parse_output_fields), 1583 1559 OPT_BOOLEAN('a', "all-cpus", &system_wide, 1584 1560 "system-wide collection from all CPUs"), 1585 1561 OPT_STRING('S', "symbols", &symbol_conf.sym_list_str, "symbol[,symbol...]",
+2
tools/perf/util/event.h
··· 157 157 PERF_IP_FLAG_IN_TX = 1ULL << 10, 158 158 }; 159 159 160 + #define PERF_IP_FLAG_CHARS "bcrosyiABEx" 161 + 160 162 #define PERF_BRANCH_MASK (\ 161 163 PERF_IP_FLAG_BRANCH |\ 162 164 PERF_IP_FLAG_CALL |\