[PATCH v3 5/5] perf/script: add support for skid ip

From: Stephane Eranian
Date: Wed Nov 08 2017 - 02:57:01 EST


This patch adds a skid_ip field to perf script
to dump the raw value of the PERF_SAMPLE_SKID_IP
field in each sample.

$ perf script -F +ip,+skid_ip ......

The field is not enabled by default.

Signed-off-by: Stephane Eranian <eranian@xxxxxxxxxx>
---
tools/perf/Documentation/perf-script.txt | 2 +-
tools/perf/builtin-script.c | 10 ++++++++--
tools/perf/util/session.c | 2 +-
3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt
index 2811fcf684cb..96871bd3a576 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.
+ brstackoff, callindent, insn, insnlen, synth, phys_addr, skid_ip.
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 68f36dc0344f..f00fc8c50f68 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -90,6 +90,7 @@ enum perf_output_field {
PERF_OUTPUT_SYNTH = 1U << 25,
PERF_OUTPUT_PHYS_ADDR = 1U << 26,
PERF_OUTPUT_UREGS = 1U << 27,
+ PERF_OUTPUT_SKID_IP = 1U << 28,
};

struct output_option {
@@ -124,6 +125,7 @@ struct output_option {
{.str = "brstackoff", .field = PERF_OUTPUT_BRSTACKOFF},
{.str = "synth", .field = PERF_OUTPUT_SYNTH},
{.str = "phys_addr", .field = PERF_OUTPUT_PHYS_ADDR},
+ {.str = "skid_ip", .field = PERF_OUTPUT_SKID_IP},
};

enum {
@@ -1563,7 +1565,11 @@ static void process_event(struct perf_script *script,

if (PRINT_FIELD(PHYS_ADDR))
fprintf(fp, "%16" PRIx64, sample->phys_addr);
- fprintf(fp, "\n");
+
+ if (PRINT_FIELD(SKID_IP))
+ printf(" %"PRIx64" ", sample->skid_ip);
+
+ printf("\n");
}

static struct scripting_ops *scripting_ops;
@@ -2915,7 +2921,7 @@ int cmd_script(int argc, const char **argv)
"Valid types: hw,sw,trace,raw,synth. "
"Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso,"
"addr,symoff,period,iregs,uregs,brstack,brstacksym,flags,"
- "bpf-output,callindent,insn,insnlen,brstackinsn,synth,phys_addr",
+ "bpf-output,callindent,insn,insnlen,brstackinsn,synth,phys_addr,skid_ip",
parse_output_fields),
OPT_BOOLEAN('a', "all-cpus", &system_wide,
"system-wide collection from all CPUs"),
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 223165055d41..ee8fb635f694 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -1133,7 +1133,7 @@ static void dump_sample(struct perf_evsel *evsel, union perf_event *event,
sample_read__printf(sample, evsel->attr.read_format);

if (sample_type & PERF_SAMPLE_SKID_IP)
- printf("... skid_ip: %" PRIu64 "\n", sample->skid_ip);
+ printf("... skid_ip: 0x%" PRIx64 "\n", sample->skid_ip);
}

static void dump_read(struct perf_evsel *evsel, union perf_event *event)
--
2.7.4