[PATCH 18/21] perf script: Add support to display user data ID

Jiri Olsa
2018-01-24T11:52:33Z

Assing new -F option user_data_id field argument
to display column with user data id for sample.

The new column displays the USER_DATA_ID or N/A
if the sample does not have user data attached
(PERF_RECORD_MISC_USER_DATA bit set)

$ perf script -F+user_data_id ...
perf 29014 ... cycles:ppp: N/A ffffffff870d013d __upda...
sched-messaging 29014 ... cycles:ppp: 8 ffffffff8741d15a flex_a...
new column _________/

Link: http://lkml.kernel.org/n/tip-ujjq7auvaw49slr57sarh0cu@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
tools/perf/Documentation/perf-script.txt | 2 +-
tools/perf/builtin-script.c | 9 +++++++++
2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt
index 7730c1d2b5d3..0d1db8c7d2d1 100644
--- a/tools/perf/Documentation/perf-script.txt
+++ b/tools/perf/Documentation/perf-script.txt
@@ -117,7 +117,7 @@ OPTIONS
Comma separated list of fields to print. Options are:
comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, symoff,
srcline, period, iregs, uregs, brstack, brstacksym, flags, bpf-output, brstackinsn,
- brstackoff, callindent, insn, insnlen, synth, phys_addr, metric, misc.
+ brstackoff, callindent, insn, insnlen, synth, phys_addr, metric, misc, user_data_id.
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 2b8231292fe2..7baa2e5d7f9e 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -95,6 +95,7 @@ enum perf_output_field {
PERF_OUTPUT_UREGS = 1U << 27,
PERF_OUTPUT_METRIC = 1U << 28,
PERF_OUTPUT_MISC = 1U << 29,
+ PERF_OUTPUT_USER_DATA_ID = 1U << 30,
};

struct output_option {
@@ -131,6 +132,7 @@ struct output_option {
{.str = "phys_addr", .field = PERF_OUTPUT_PHYS_ADDR},
{.str = "metric", .field = PERF_OUTPUT_METRIC},
{.str = "misc", .field = PERF_OUTPUT_MISC},
+ {.str = "user_data_id", .field = PERF_OUTPUT_USER_DATA_ID},
};

enum {
@@ -1670,6 +1672,13 @@ static void process_event(struct perf_script *script,
if (PRINT_FIELD(WEIGHT))
fprintf(fp, "%16" PRIu64, sample->weight);

+ if (PRINT_FIELD(USER_DATA_ID)) {
+ if (sample->misc & PERF_RECORD_MISC_USER_DATA)
+ fprintf(fp, "%16" PRIu64, sample->user_data_id);
+ else
+ fprintf(fp, "%16s", "N/A");
+ }
+
if (PRINT_FIELD(IP)) {
struct callchain_cursor *cursor = NULL;

--
2.13.6