perf script: Have consistent output for symbol address
v4 cover perf script: Have consistent output for symbol address
The goal of this change is to achieve consistent output for symbol address. Before this, the raw ip is printed for non-callchain and dso offset for callchain. Mostly what we expect is the raw ip.
This patch does two changes:
- Always print raw ip for resolved symbols.
- Add a new 'dsoff' field if we really need the dso offset, and the offset is appended to dso name.
v4:
o also print 'dsoff' for brstack,brstacksym,brstackoff,etc.
v3:
o 'dsoff' implys 'dso' field. (Namhyung)
v2:
o split into two patches. (Adrian)
o do not print offset for unresolved symbols. (Adrian)
Changbin Du (2):
perf script: print raw ip instead of binary offset for callchain
perf: script: add new output field 'dsoff' to print dso offset
tools/perf/Documentation/perf-script.txt | 2 +- tools/perf/builtin-script.c | 25 +++++++++++++++++++++++- tools/perf/util/evsel_fprintf.c | 15 +++++++------- tools/perf/util/evsel_fprintf.h | 1 + 4 files changed, 34 insertions(+), 9 deletions(-)
Signature · 1 line
2.25.1
PATCH v4 1/2 perf script: print raw ip instead of binary offset for callchain
Before this, the raw ip is printed for non-callchain and dso offset for callchain. This inconsistent output for address may confuse people. And mostly what we expect is the raw ip.
'dso offset' is printed in callchain:
$ perf script
...
ls 1341034 2739463.008343: 2162417 cycles:
ffffffff99d657a7 [unknown] ([unknown])
ffffffff99e00b67 [unknown] ([unknown])
235d3 memset+0x53 (/usr/lib/x86_64-linux-gnu/ld-2.31.so) # dso offset
a61b _dl_map_object+0x1bb (/usr/lib/x86_64-linux-gnu/ld-2.31.so)raw ip is printed for non-callchain:
$ perf script -G
...
ls 1341034 2739463.008876: 2053304 cycles: ffffffffc1596923 [unknown] ([unknown])
ls 1341034 2739463.009381: 1917049 cycles: 14def8e149e6 __strcoll_l+0xd96 (/usr/lib/x86_64-linux-gnu/libc-2.31.so) # raw ipLet's have consistent output for it. Later I'll add a new field 'dsoff' to print dso offset.
--- tools/perf/util/evsel_fprintf.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
tools/perf/util/evsel_fprintf.c +2 -7
@@ -153,13 +153,8 @@ int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment,if (map) addr = map->map_ip (map, node->ip); -if (print_ip) { -/* Show binary offset for userspace addr */ -if (map && !map->dso->kernel) - printed +=fprintf (fp,"%c%16" PRIx64, s, addr); -else - printed +=fprintf (fp,"%c%16" PRIx64, s, node->ip); - } +if (print_ip) + printed +=fprintf (fp,"%c%16" PRIx64, s, node->ip);if (print_sym) { printed +=fprintf (fp," " );
Signature · 1 line
2.25.1
PATCH v4 2/2 perf: script: add new output field 'dsoff' to print dso offset
In reply to Changbin DuThis adds a new 'dsoff' field to print dso offset for resolved symbols, and the offset is appended to dso name.
Default output:
$ perf script
ls 2695501 3011030.487017: 500000 cycles: 152cc73ef4b5 get_common_indices.constprop.0+0x155 (/usr/lib/x86_64-linux-gnu/ld-2.31.so)
ls 2695501 3011030.487018: 500000 cycles: ffffffff99045b3e [unknown] ([unknown])
ls 2695501 3011030.487018: 500000 cycles: ffffffff9968e107 [unknown] ([unknown])
ls 2695501 3011030.487018: 500000 cycles: ffffffffc1f54afb [unknown] ([unknown])
ls 2695501 3011030.487018: 500000 cycles: ffffffff9968382f [unknown] ([unknown])
ls 2695501 3011030.487019: 500000 cycles: ffffffff99e00094 [unknown] ([unknown])
ls 2695501 3011030.487019: 500000 cycles: 152cc718a8d0 __errno_location@plt+0x0 (/usr/lib/x86_64-linux-gnu/libselinux.so.1)Display 'dsoff' field:
$ perf script -F +dsoff
ls 2695501 3011030.487017: 500000 cycles: 152cc73ef4b5 get_common_indices.constprop.0+0x155 (/usr/lib/x86_64-linux-gnu/ld-2.31.so+0x1c4b5)
ls 2695501 3011030.487018: 500000 cycles: ffffffff99045b3e [unknown] ([unknown])
ls 2695501 3011030.487018: 500000 cycles: ffffffff9968e107 [unknown] ([unknown])
ls 2695501 3011030.487018: 500000 cycles: ffffffffc1f54afb [unknown] ([unknown])
ls 2695501 3011030.487018: 500000 cycles: ffffffff9968382f [unknown] ([unknown])
ls 2695501 3011030.487019: 500000 cycles: ffffffff99e00094 [unknown] ([unknown])
ls 2695501 3011030.487019: 500000 cycles: 152cc718a8d0 __errno_location@plt+0x0 (/usr/lib/x86_64-linux-gnu/libselinux.so.1+0x68d0)
ls 2695501 3011030.487019: 500000 cycles: ffffffff992a6db0 [unknown] ([unknown])--- tools/perf/Documentation/perf-script.txt | 2 +- tools/perf/builtin-script.c | 25 +++++++++++++++++++++++- tools/perf/util/evsel_fprintf.c | 6 ++++++ tools/perf/util/evsel_fprintf.h | 1 + 4 files changed, 32 insertions(+), 2 deletions(-)
tools/perf/Documentation/perf-script.txt +1 -1
@@ -130,7 +130,7 @@ OPTIONS -F:: --fields:: Comma separated list of fields to print. Options are: - comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, symoff, + comm, tid, pid, time, cpu, event, trace, ip, sym, dso, dsoff, addr, symoff, srcline, period, iregs, uregs, brstack, brstacksym, flags, bpf-output, brstackinsn, brstackinsnlen, brstackoff, callindent, insn, insnlen, synth, phys_addr, metric, misc, srccode, ipc, data_page_size, code_page_size, ins_lat,
tools/perf/builtin-script.c +24 -1
@@ -130,6 +130,7 @@ enum perf_output_field {PERF_OUTPUT_BRSTACKINSNLEN =1ULL <<36 ,PERF_OUTPUT_MACHINE_PID =1ULL <<37 ,PERF_OUTPUT_VCPU =1ULL <<38 , + PERF_OUTPUT_DSOFF = 1ULL << 39, }; struct perf_script {
@@ -171,6 +172,7 @@ struct output_option { {.str = "ip", .field = PERF_OUTPUT_IP}, {.str = "sym", .field = PERF_OUTPUT_SYM}, {.str = "dso", .field = PERF_OUTPUT_DSO}, + {.str = "dsoff", .field = PERF_OUTPUT_DSOFF}, {.str = "addr", .field = PERF_OUTPUT_ADDR}, {.str = "symoff", .field = PERF_OUTPUT_SYMOFFSET}, {.str = "srcline", .field = PERF_OUTPUT_SRCLINE},
@@ -559,6 +561,9 @@ static void set_print_ip_opts(struct perf_event_attr *attr)if (PRINT_FIELD (DSO )) output[type].print_ip_opts |=EVSEL__PRINT_DSO ; +if (PRINT_FIELD (DSOFF )) + output[type].print_ip_opts |=EVSEL__PRINT_DSOFF ; +if (PRINT_FIELD (SYMOFFSET )) output[type].print_ip_opts |=EVSEL__PRINT_SYMOFFSET ;
@@ -612,6 +617,10 @@ static int perf_session__check_output_opt(struct perf_session *session)if (evsel ==NULL )continue ; +/* 'dsoff' implys 'dso' field */ +if (output[j].fields &PERF_OUTPUT_DSOFF ) + output[j].fields |=PERF_OUTPUT_DSO ; +set_print_ip_opts (&evsel->core.attr); tod |= output[j].fields &PERF_OUTPUT_TOD ; }
@@ -916,6 +925,8 @@ static int perf_sample__fprintf_brstack(struct perf_sample *sample,if (PRINT_FIELD (DSO )) { printed +=fprintf (fp,"(" ); printed +=map__fprintf_dsoname (alf.map, fp); +if (PRINT_FIELD (DSOFF ) && alf.map && alf.map->dso) + printed +=fprintf (fp,"+0x%lx" , alf.addr); printed +=fprintf (fp,")" ); }
@@ -923,6 +934,8 @@ static int perf_sample__fprintf_brstack(struct perf_sample *sample,if (PRINT_FIELD (DSO )) { printed +=fprintf (fp,"(" ); printed +=map__fprintf_dsoname (alt.map, fp); +if (PRINT_FIELD (DSOFF ) && alt.map && alt.map->dso) + printed +=fprintf (fp,"+0x%lx" , alt.addr); printed +=fprintf (fp,")" ); }
@@ -959,6 +972,8 @@ static int perf_sample__fprintf_brstacksym(struct perf_sample *sample,if (PRINT_FIELD (DSO )) { printed +=fprintf (fp,"(" ); printed +=map__fprintf_dsoname (alf.map, fp); +if (PRINT_FIELD (DSOFF ) && alf.map && alf.map->dso) + printed +=fprintf (fp,"+0x%lx" , alf.addr); printed +=fprintf (fp,")" ); } printed +=fprintf (fp,"%c" ,'/' );
@@ -966,6 +981,8 @@ static int perf_sample__fprintf_brstacksym(struct perf_sample *sample,if (PRINT_FIELD (DSO )) { printed +=fprintf (fp,"(" ); printed +=map__fprintf_dsoname (alt.map, fp); +if (PRINT_FIELD (DSOFF ) && alt.map && alt.map->dso) + printed +=fprintf (fp,"+0x%lx" , alt.addr); printed +=fprintf (fp,")" ); } printed +=print_bstack_flags (fp, entries + i);
@@ -1006,12 +1023,16 @@ static int perf_sample__fprintf_brstackoff(struct perf_sample *sample,if (PRINT_FIELD (DSO )) { printed +=fprintf (fp,"(" ); printed +=map__fprintf_dsoname (alf.map, fp); +if (PRINT_FIELD (DSOFF ) && alf.map && alf.map->dso) + printed +=fprintf (fp,"+0x%lx" , alf.addr); printed +=fprintf (fp,")" ); } printed +=fprintf (fp,"/0x%" PRIx64, to);if (PRINT_FIELD (DSO )) { printed +=fprintf (fp,"(" ); printed +=map__fprintf_dsoname (alt.map, fp); +if (PRINT_FIELD (DSOFF ) && alt.map && alt.map->dso) + printed +=fprintf (fp,"+0x%lx" , alt.addr); printed +=fprintf (fp,")" ); } printed +=print_bstack_flags (fp, entries + i);
@@ -1378,6 +1399,8 @@ static int perf_sample__fprintf_addr(struct perf_sample *sample,if (PRINT_FIELD (DSO )) { printed +=fprintf (fp," (" ); printed +=map__fprintf_dsoname (al.map, fp); +if (PRINT_FIELD (DSOFF ) && al.map && al.map->dso) + printed +=fprintf (fp,"+0x%lx" , al.addr); printed +=fprintf (fp,")" ); } out:
@@ -3851,7 +3874,7 @@ int cmd_script(int argc, const char **argv)"comma separated output fields prepend with 'type:'. " "+field to add and -field to remove." "Valid types: hw,sw,trace,raw,synth. " -"Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso," +"Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso,dsoff" "addr,symoff,srcline,period,iregs,uregs,brstack," "brstacksym,flags,data_src,weight,bpf-output,brstackinsn," "brstackinsnlen,brstackoff,callindent,insn,insnlen,synth,"
tools/perf/util/evsel_fprintf.c +6 -0
@@ -116,6 +116,7 @@ int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment,int print_ip = print_opts &EVSEL__PRINT_IP ;int print_sym = print_opts &EVSEL__PRINT_SYM ;int print_dso = print_opts &EVSEL__PRINT_DSO ; +int print_dsoff = print_opts &EVSEL__PRINT_DSOFF ;int print_symoffset = print_opts &EVSEL__PRINT_SYMOFFSET ;int print_oneline = print_opts &EVSEL__PRINT_ONELINE ;int print_srcline = print_opts &EVSEL__PRINT_SRCLINE ;
@@ -174,6 +175,8 @@ int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment,if (print_dso && (!sym || !sym->inlined)) { printed +=fprintf (fp," (" ); printed +=map__fprintf_dsoname (map, fp); +if (print_dsoff && map && map->dso) + printed +=fprintf (fp,"+0x%lx" , addr); printed +=fprintf (fp,")" ); }
@@ -209,6 +212,7 @@ int sample__fprintf_sym(struct perf_sample *sample, struct addr_location *al,int print_ip = print_opts &EVSEL__PRINT_IP ;int print_sym = print_opts &EVSEL__PRINT_SYM ;int print_dso = print_opts &EVSEL__PRINT_DSO ; +int print_dsoff = print_opts &EVSEL__PRINT_DSOFF ;int print_symoffset = print_opts &EVSEL__PRINT_SYMOFFSET ;int print_srcline = print_opts &EVSEL__PRINT_SRCLINE ;int print_unknown_as_addr = print_opts &EVSEL__PRINT_UNKNOWN_AS_ADDR ;
@@ -237,6 +241,8 @@ int sample__fprintf_sym(struct perf_sample *sample, struct addr_location *al,if (print_dso) { printed +=fprintf (fp," (" ); printed +=map__fprintf_dsoname (al->map, fp); +if (print_dsoff && al->map && al->map->dso) + printed +=fprintf (fp,"+0x%lx" , al->addr); printed +=fprintf (fp,")" ); }
tools/perf/util/evsel_fprintf.h +1 -0
@@ -26,6 +26,7 @@ int evsel__fprintf(struct evsel *evsel, struct perf_attr_details *details, FILE#define EVSEL__PRINT_UNKNOWN_AS_ADDR (1<<6)#define EVSEL__PRINT_CALLCHAIN_ARROW (1<<7)#define EVSEL__PRINT_SKIP_IGNORED (1<<8) +#define EVSEL__PRINT_DSOFF (1<<9)struct addr_location ;struct perf_event_attr ;
Signature · 1 line
2.25.1
Adrian Hunter
reviewerRe: [PATCH v4 2/2] perf: script: add new output field 'dsoff' to print dso offset
Quoted 24 lines · Changbin Du
This adds a new 'dsoff' field to print dso offset for resolved symbols, and the offset is appended to dso name.
Default output:
$ perf script ls 2695501 3011030.487017: 500000 cycles: 152cc73ef4b5 get_common_indices.constprop.0+0x155 (/usr/lib/x86_64-linux-gnu/ld-2.31.so) ls 2695501 3011030.487018: 500000 cycles: ffffffff99045b3e [unknown] ([unknown]) ls 2695501 3011030.487018: 500000 cycles: ffffffff9968e107 [unknown] ([unknown]) ls 2695501 3011030.487018: 500000 cycles: ffffffffc1f54afb [unknown] ([unknown]) ls 2695501 3011030.487018: 500000 cycles: ffffffff9968382f [unknown] ([unknown]) ls 2695501 3011030.487019: 500000 cycles: ffffffff99e00094 [unknown] ([unknown]) ls 2695501 3011030.487019: 500000 cycles: 152cc718a8d0 __errno_location@plt+0x0 (/usr/lib/x86_64-linux-gnu/libselinux.so.1)Display 'dsoff' field:
$ perf script -F +dsoff ls 2695501 3011030.487017: 500000 cycles: 152cc73ef4b5 get_common_indices.constprop.0+0x155 (/usr/lib/x86_64-linux-gnu/ld-2.31.so+0x1c4b5) ls 2695501 3011030.487018: 500000 cycles: ffffffff99045b3e [unknown] ([unknown]) ls 2695501 3011030.487018: 500000 cycles: ffffffff9968e107 [unknown] ([unknown]) ls 2695501 3011030.487018: 500000 cycles: ffffffffc1f54afb [unknown] ([unknown]) ls 2695501 3011030.487018: 500000 cycles: ffffffff9968382f [unknown] ([unknown]) ls 2695501 3011030.487019: 500000 cycles: ffffffff99e00094 [unknown] ([unknown]) ls 2695501 3011030.487019: 500000 cycles: 152cc718a8d0 __errno_location@plt+0x0 (/usr/lib/x86_64-linux-gnu/libselinux.so.1+0x68d0) ls 2695501 3011030.487019: 500000 cycles: ffffffff992a6db0 [unknown] ([unknown])
Quoted 1 line
Signed-off-by Changbin Du <[email protected]>
Looks good, but patches do not apply to:
git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git perf-tools-next
Note the use of map__dso(map) now.
Also the repeated dso printing code:
printed += fprintf(fp, "(");
printed += map__fprintf_dsoname(map, fp);
if (PRINT_FIELD(DSOFF) && map && map__dso(map))
printed += fprintf(fp, "+0x%" PRIx64, alf.addr);
printed += fprintf(fp, ")");is begging to be replaced by a helper function e.g.
if (PRINT_FIELD(DSO)) map__fprintf_dsoname_dsoff(map, PRINT_FIELD(DSOFF), addr, fp);
Perhaps another patch for that.
Also see comment further below.
Quoted 62 lines
--- tools/perf/Documentation/perf-script.txt | 2 +- tools/perf/builtin-script.c | 25 +++++++++++++++++++++++- tools/perf/util/evsel_fprintf.c | 6 ++++++ tools/perf/util/evsel_fprintf.h | 1 + 4 files changed, 32 insertions(+), 2 deletions(-)tools/perf/Documentation/perf-script.txt +1
-1@@ -130,7 +130,7 @@ OPTIONS -F:: --fields:: Comma separated list of fields to print. Options are: - comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, symoff, + comm, tid, pid, time, cpu, event, trace, ip, sym, dso, dsoff, addr, symoff, srcline, period, iregs, uregs, brstack, brstacksym, flags, bpf-output, brstackinsn, brstackinsnlen, brstackoff, callindent, insn, insnlen, synth, phys_addr, metric, misc, srccode, ipc, data_page_size, code_page_size, ins_lat,tools/perf/builtin-script.c +9
-0@@ -130,6 +130,7 @@ enum perf_output_field {PERF_OUTPUT_BRSTACKINSNLEN =1ULL <<36 ,PERF_OUTPUT_MACHINE_PID =1ULL <<37 ,PERF_OUTPUT_VCPU =1ULL <<38 , + PERF_OUTPUT_DSOFF = 1ULL << 39, }; struct perf_script {@@ -171,6 +172,7 @@ struct output_option { {.str = "ip", .field = PERF_OUTPUT_IP}, {.str = "sym", .field = PERF_OUTPUT_SYM}, {.str = "dso", .field = PERF_OUTPUT_DSO}, + {.str = "dsoff", .field = PERF_OUTPUT_DSOFF}, {.str = "addr", .field = PERF_OUTPUT_ADDR}, {.str = "symoff", .field = PERF_OUTPUT_SYMOFFSET}, {.str = "srcline", .field = PERF_OUTPUT_SRCLINE},@@ -559,6 +561,9 @@ static void set_print_ip_opts(struct perf_event_attr *attr)if (PRINT_FIELD (DSO )) output[type].print_ip_opts |=EVSEL__PRINT_DSO ; +if (PRINT_FIELD (DSOFF )) + output[type].print_ip_opts |=EVSEL__PRINT_DSOFF ; +if (PRINT_FIELD (SYMOFFSET )) output[type].print_ip_opts |=EVSEL__PRINT_SYMOFFSET ;@@ -612,6 +617,10 @@ static int perf_session__check_output_opt(struct perf_session *session)if (evsel ==NULL )continue ; +/* 'dsoff' implys 'dso' field */ +if (output[j].fields &PERF_OUTPUT_DSOFF ) + output[j].fields |=PERF_OUTPUT_DSO ; +set_print_ip_opts (&evsel->core.attr); tod |= output[j].fields &PERF_OUTPUT_TOD ; }
tools/perf/builtin-script.c static int perf_sample__fprintf_brstack(struct perf_sample *sample, · line 929
Quoted 5 lines
tools/perf/builtin-script.c +2
-0@@ -916,6 +925,8 @@ static int perf_sample__fprintf_brstack(struct perf_sample *sample,if (PRINT_FIELD (DSO )) { printed +=fprintf (fp,"(" ); printed +=map__fprintf_dsoname (alf.map, fp); +if (PRINT_FIELD (DSOFF ) && alf.map && alf.map->dso) + printed +=fprintf (fp,"+0x%lx" , alf.addr);
Here and elsewhere, addr is a u64 so you
need to use PRIx64 e.g.
printed += fprintf(fp, "+0x%" PRIx64, alf.addr);
Quoted 115 lines
tools/perf/builtin-script.c +13
-1printed +=fprintf (fp,")" ); }@@ -923,6 +934,8 @@ static int perf_sample__fprintf_brstack(struct perf_sample *sample,if (PRINT_FIELD (DSO )) { printed +=fprintf (fp,"(" ); printed +=map__fprintf_dsoname (alt.map, fp); +if (PRINT_FIELD (DSOFF ) && alt.map && alt.map->dso) + printed +=fprintf (fp,"+0x%lx" , alt.addr); printed +=fprintf (fp,")" ); }@@ -959,6 +972,8 @@ static int perf_sample__fprintf_brstacksym(struct perf_sample *sample,if (PRINT_FIELD (DSO )) { printed +=fprintf (fp,"(" ); printed +=map__fprintf_dsoname (alf.map, fp); +if (PRINT_FIELD (DSOFF ) && alf.map && alf.map->dso) + printed +=fprintf (fp,"+0x%lx" , alf.addr); printed +=fprintf (fp,")" ); } printed +=fprintf (fp,"%c" ,'/' );@@ -966,6 +981,8 @@ static int perf_sample__fprintf_brstacksym(struct perf_sample *sample,if (PRINT_FIELD (DSO )) { printed +=fprintf (fp,"(" ); printed +=map__fprintf_dsoname (alt.map, fp); +if (PRINT_FIELD (DSOFF ) && alt.map && alt.map->dso) + printed +=fprintf (fp,"+0x%lx" , alt.addr); printed +=fprintf (fp,")" ); } printed +=print_bstack_flags (fp, entries + i);@@ -1006,12 +1023,16 @@ static int perf_sample__fprintf_brstackoff(struct perf_sample *sample,if (PRINT_FIELD (DSO )) { printed +=fprintf (fp,"(" ); printed +=map__fprintf_dsoname (alf.map, fp); +if (PRINT_FIELD (DSOFF ) && alf.map && alf.map->dso) + printed +=fprintf (fp,"+0x%lx" , alf.addr); printed +=fprintf (fp,")" ); } printed +=fprintf (fp,"/0x%" PRIx64, to);if (PRINT_FIELD (DSO )) { printed +=fprintf (fp,"(" ); printed +=map__fprintf_dsoname (alt.map, fp); +if (PRINT_FIELD (DSOFF ) && alt.map && alt.map->dso) + printed +=fprintf (fp,"+0x%lx" , alt.addr); printed +=fprintf (fp,")" ); } printed +=print_bstack_flags (fp, entries + i);@@ -1378,6 +1399,8 @@ static int perf_sample__fprintf_addr(struct perf_sample *sample,if (PRINT_FIELD (DSO )) { printed +=fprintf (fp," (" ); printed +=map__fprintf_dsoname (al.map, fp); +if (PRINT_FIELD (DSOFF ) && al.map && al.map->dso) + printed +=fprintf (fp,"+0x%lx" , al.addr); printed +=fprintf (fp,")" ); } out:@@ -3851,7 +3874,7 @@ int cmd_script(int argc, const char **argv)"comma separated output fields prepend with 'type:'. " "+field to add and -field to remove." "Valid types: hw,sw,trace,raw,synth. " -"Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso," +"Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso,dsoff" "addr,symoff,srcline,period,iregs,uregs,brstack," "brstacksym,flags,data_src,weight,bpf-output,brstackinsn," "brstackinsnlen,brstackoff,callindent,insn,insnlen,synth," tools/perf/util/evsel_fprintf.c +6
-0@@ -116,6 +116,7 @@ int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment,int print_ip = print_opts &EVSEL__PRINT_IP ;int print_sym = print_opts &EVSEL__PRINT_SYM ;int print_dso = print_opts &EVSEL__PRINT_DSO ; +int print_dsoff = print_opts &EVSEL__PRINT_DSOFF ;int print_symoffset = print_opts &EVSEL__PRINT_SYMOFFSET ;int print_oneline = print_opts &EVSEL__PRINT_ONELINE ;int print_srcline = print_opts &EVSEL__PRINT_SRCLINE ;@@ -174,6 +175,8 @@ int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment,if (print_dso && (!sym || !sym->inlined)) { printed +=fprintf (fp," (" ); printed +=map__fprintf_dsoname (map, fp); +if (print_dsoff && map && map->dso) + printed +=fprintf (fp,"+0x%lx" , addr); printed +=fprintf (fp,")" ); }@@ -209,6 +212,7 @@ int sample__fprintf_sym(struct perf_sample *sample, struct addr_location *al,int print_ip = print_opts &EVSEL__PRINT_IP ;int print_sym = print_opts &EVSEL__PRINT_SYM ;int print_dso = print_opts &EVSEL__PRINT_DSO ; +int print_dsoff = print_opts &EVSEL__PRINT_DSOFF ;int print_symoffset = print_opts &EVSEL__PRINT_SYMOFFSET ;int print_srcline = print_opts &EVSEL__PRINT_SRCLINE ;int print_unknown_as_addr = print_opts &EVSEL__PRINT_UNKNOWN_AS_ADDR ;@@ -237,6 +241,8 @@ int sample__fprintf_sym(struct perf_sample *sample, struct addr_location *al,if (print_dso) { printed +=fprintf (fp," (" ); printed +=map__fprintf_dsoname (al->map, fp); +if (print_dsoff && al->map && al->map->dso) + printed +=fprintf (fp,"+0x%lx" , al->addr); printed +=fprintf (fp,")" ); }tools/perf/util/evsel_fprintf.h +1
-0@@ -26,6 +26,7 @@ int evsel__fprintf(struct evsel *evsel, struct perf_attr_details *details, FILE#define EVSEL__PRINT_UNKNOWN_AS_ADDR (1<<6)#define EVSEL__PRINT_CALLCHAIN_ARROW (1<<7)#define EVSEL__PRINT_SKIP_IGNORED (1<<8) +#define EVSEL__PRINT_DSOFF (1<<9)struct addr_location ;struct perf_event_attr ;
Re: [PATCH v4 2/2] perf: script: add new output field 'dsoff' to print dso offset
Quoted 25 lines · Adrian Hunter
Quoted 24 lines · Changbin Du
This adds a new 'dsoff' field to print dso offset for resolved symbols, and the offset is appended to dso name.
Default output:
$ perf script ls 2695501 3011030.487017: 500000 cycles: 152cc73ef4b5 get_common_indices.constprop.0+0x155 (/usr/lib/x86_64-linux-gnu/ld-2.31.so) ls 2695501 3011030.487018: 500000 cycles: ffffffff99045b3e [unknown] ([unknown]) ls 2695501 3011030.487018: 500000 cycles: ffffffff9968e107 [unknown] ([unknown]) ls 2695501 3011030.487018: 500000 cycles: ffffffffc1f54afb [unknown] ([unknown]) ls 2695501 3011030.487018: 500000 cycles: ffffffff9968382f [unknown] ([unknown]) ls 2695501 3011030.487019: 500000 cycles: ffffffff99e00094 [unknown] ([unknown]) ls 2695501 3011030.487019: 500000 cycles: 152cc718a8d0 __errno_location@plt+0x0 (/usr/lib/x86_64-linux-gnu/libselinux.so.1)Display 'dsoff' field:
$ perf script -F +dsoff ls 2695501 3011030.487017: 500000 cycles: 152cc73ef4b5 get_common_indices.constprop.0+0x155 (/usr/lib/x86_64-linux-gnu/ld-2.31.so+0x1c4b5) ls 2695501 3011030.487018: 500000 cycles: ffffffff99045b3e [unknown] ([unknown]) ls 2695501 3011030.487018: 500000 cycles: ffffffff9968e107 [unknown] ([unknown]) ls 2695501 3011030.487018: 500000 cycles: ffffffffc1f54afb [unknown] ([unknown]) ls 2695501 3011030.487018: 500000 cycles: ffffffff9968382f [unknown] ([unknown]) ls 2695501 3011030.487019: 500000 cycles: ffffffff99e00094 [unknown] ([unknown]) ls 2695501 3011030.487019: 500000 cycles: 152cc718a8d0 __errno_location@plt+0x0 (/usr/lib/x86_64-linux-gnu/libselinux.so.1+0x68d0) ls 2695501 3011030.487019: 500000 cycles: ffffffff992a6db0 [unknown] ([unknown])
Quoted 8 lines
Quoted 1 line
Signed-off-by Changbin Du <[email protected]>Looks good, but patches do not apply to:
git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.gitperf-tools-nextNote the use of
map__dso(map)now.
I will rebase to perf-tools-next.
Quoted 8 lines
Also the repeated dso printing code:
printed += fprintf(fp, "("); printed += map__fprintf_dsoname(map, fp); if (PRINT_FIELD(DSOFF) && map && map__dso(map)) printed += fprintf(fp, "+0x%" PRIx64, alf.addr); printed += fprintf(fp, ")");
Quoted 7 lines
is begging to be replaced by a helper function e.g.
if (PRINT_FIELD(DSO)) map__fprintf_dsoname_dsoff(map, PRINT_FIELD(DSOFF), addr, fp);Perhaps another patch for that.
ok, will add another patch for this helper function.
Quoted 56 lines
Also see comment further below.
Quoted 54 lines
--- tools/perf/Documentation/perf-script.txt | 2 +- tools/perf/builtin-script.c | 25 +++++++++++++++++++++++- tools/perf/util/evsel_fprintf.c | 6 ++++++ tools/perf/util/evsel_fprintf.h | 1 + 4 files changed, 32 insertions(+), 2 deletions(-)tools/perf/Documentation/perf-script.txt +1
-1@@ -130,7 +130,7 @@ OPTIONS -F:: --fields:: Comma separated list of fields to print. Options are: - comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, symoff, + comm, tid, pid, time, cpu, event, trace, ip, sym, dso, dsoff, addr, symoff, srcline, period, iregs, uregs, brstack, brstacksym, flags, bpf-output, brstackinsn, brstackinsnlen, brstackoff, callindent, insn, insnlen, synth, phys_addr, metric, misc, srccode, ipc, data_page_size, code_page_size, ins_lat,tools/perf/builtin-script.c +5
-0@@ -130,6 +130,7 @@ enum perf_output_field {PERF_OUTPUT_BRSTACKINSNLEN =1ULL <<36 ,PERF_OUTPUT_MACHINE_PID =1ULL <<37 ,PERF_OUTPUT_VCPU =1ULL <<38 , + PERF_OUTPUT_DSOFF = 1ULL << 39, }; struct perf_script {@@ -171,6 +172,7 @@ struct output_option { {.str = "ip", .field = PERF_OUTPUT_IP}, {.str = "sym", .field = PERF_OUTPUT_SYM}, {.str = "dso", .field = PERF_OUTPUT_DSO}, + {.str = "dsoff", .field = PERF_OUTPUT_DSOFF}, {.str = "addr", .field = PERF_OUTPUT_ADDR}, {.str = "symoff", .field = PERF_OUTPUT_SYMOFFSET}, {.str = "srcline", .field = PERF_OUTPUT_SRCLINE},@@ -559,6 +561,9 @@ static void set_print_ip_opts(struct perf_event_attr *attr)if (PRINT_FIELD (DSO )) output[type].print_ip_opts |=EVSEL__PRINT_DSO ; +if (PRINT_FIELD (DSOFF )) + output[type].print_ip_opts |=EVSEL__PRINT_DSOFF ; +if (PRINT_FIELD (SYMOFFSET )) output[type].print_ip_opts |=EVSEL__PRINT_SYMOFFSET ;@@ -612,6 +617,10 @@ static int perf_session__check_output_opt(struct perf_session *session)if (evsel ==NULL )continue ;
Quoted 17 lines
tools/perf/builtin-script.c static int perf_sample__fprintf_brstack(struct perf_sample *sample, · line 929
Quoted 13 lines
tools/perf/builtin-script.c +6
-0+/* 'dsoff' implys 'dso' field */ +if (output[j].fields &PERF_OUTPUT_DSOFF ) + output[j].fields |=PERF_OUTPUT_DSO ; +set_print_ip_opts (&evsel->core.attr); tod |= output[j].fields &PERF_OUTPUT_TOD ; }@@ -916,6 +925,8 @@ static int perf_sample__fprintf_brstack(struct perf_sample *sample,if (PRINT_FIELD (DSO )) { printed +=fprintf (fp,"(" ); printed +=map__fprintf_dsoname (alf.map, fp); +if (PRINT_FIELD (DSOFF ) && alf.map && alf.map->dso) + printed +=fprintf (fp,"+0x%lx" , alf.addr);Here and elsewhere, addr is a u64 so you
need to use PRIx64 e.g.
fixed, thanks!
Quoted 118 lines
printed += fprintf(fp, "+0x%" PRIx64, alf.addr);Quoted 115 lines
tools/perf/builtin-script.c +13
-1printed +=fprintf (fp,")" ); }@@ -923,6 +934,8 @@ static int perf_sample__fprintf_brstack(struct perf_sample *sample,if (PRINT_FIELD (DSO )) { printed +=fprintf (fp,"(" ); printed +=map__fprintf_dsoname (alt.map, fp); +if (PRINT_FIELD (DSOFF ) && alt.map && alt.map->dso) + printed +=fprintf (fp,"+0x%lx" , alt.addr); printed +=fprintf (fp,")" ); }@@ -959,6 +972,8 @@ static int perf_sample__fprintf_brstacksym(struct perf_sample *sample,if (PRINT_FIELD (DSO )) { printed +=fprintf (fp,"(" ); printed +=map__fprintf_dsoname (alf.map, fp); +if (PRINT_FIELD (DSOFF ) && alf.map && alf.map->dso) + printed +=fprintf (fp,"+0x%lx" , alf.addr); printed +=fprintf (fp,")" ); } printed +=fprintf (fp,"%c" ,'/' );@@ -966,6 +981,8 @@ static int perf_sample__fprintf_brstacksym(struct perf_sample *sample,if (PRINT_FIELD (DSO )) { printed +=fprintf (fp,"(" ); printed +=map__fprintf_dsoname (alt.map, fp); +if (PRINT_FIELD (DSOFF ) && alt.map && alt.map->dso) + printed +=fprintf (fp,"+0x%lx" , alt.addr); printed +=fprintf (fp,")" ); } printed +=print_bstack_flags (fp, entries + i);@@ -1006,12 +1023,16 @@ static int perf_sample__fprintf_brstackoff(struct perf_sample *sample,if (PRINT_FIELD (DSO )) { printed +=fprintf (fp,"(" ); printed +=map__fprintf_dsoname (alf.map, fp); +if (PRINT_FIELD (DSOFF ) && alf.map && alf.map->dso) + printed +=fprintf (fp,"+0x%lx" , alf.addr); printed +=fprintf (fp,")" ); } printed +=fprintf (fp,"/0x%" PRIx64, to);if (PRINT_FIELD (DSO )) { printed +=fprintf (fp,"(" ); printed +=map__fprintf_dsoname (alt.map, fp); +if (PRINT_FIELD (DSOFF ) && alt.map && alt.map->dso) + printed +=fprintf (fp,"+0x%lx" , alt.addr); printed +=fprintf (fp,")" ); } printed +=print_bstack_flags (fp, entries + i);@@ -1378,6 +1399,8 @@ static int perf_sample__fprintf_addr(struct perf_sample *sample,if (PRINT_FIELD (DSO )) { printed +=fprintf (fp," (" ); printed +=map__fprintf_dsoname (al.map, fp); +if (PRINT_FIELD (DSOFF ) && al.map && al.map->dso) + printed +=fprintf (fp,"+0x%lx" , al.addr); printed +=fprintf (fp,")" ); } out:@@ -3851,7 +3874,7 @@ int cmd_script(int argc, const char **argv)"comma separated output fields prepend with 'type:'. " "+field to add and -field to remove." "Valid types: hw,sw,trace,raw,synth. " -"Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso," +"Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso,dsoff" "addr,symoff,srcline,period,iregs,uregs,brstack," "brstacksym,flags,data_src,weight,bpf-output,brstackinsn," "brstackinsnlen,brstackoff,callindent,insn,insnlen,synth," tools/perf/util/evsel_fprintf.c +6
-0@@ -116,6 +116,7 @@ int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment,int print_ip = print_opts &EVSEL__PRINT_IP ;int print_sym = print_opts &EVSEL__PRINT_SYM ;int print_dso = print_opts &EVSEL__PRINT_DSO ; +int print_dsoff = print_opts &EVSEL__PRINT_DSOFF ;int print_symoffset = print_opts &EVSEL__PRINT_SYMOFFSET ;int print_oneline = print_opts &EVSEL__PRINT_ONELINE ;int print_srcline = print_opts &EVSEL__PRINT_SRCLINE ;@@ -174,6 +175,8 @@ int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment,if (print_dso && (!sym || !sym->inlined)) { printed +=fprintf (fp," (" ); printed +=map__fprintf_dsoname (map, fp); +if (print_dsoff && map && map->dso) + printed +=fprintf (fp,"+0x%lx" , addr); printed +=fprintf (fp,")" ); }@@ -209,6 +212,7 @@ int sample__fprintf_sym(struct perf_sample *sample, struct addr_location *al,int print_ip = print_opts &EVSEL__PRINT_IP ;int print_sym = print_opts &EVSEL__PRINT_SYM ;int print_dso = print_opts &EVSEL__PRINT_DSO ; +int print_dsoff = print_opts &EVSEL__PRINT_DSOFF ;int print_symoffset = print_opts &EVSEL__PRINT_SYMOFFSET ;int print_srcline = print_opts &EVSEL__PRINT_SRCLINE ;int print_unknown_as_addr = print_opts &EVSEL__PRINT_UNKNOWN_AS_ADDR ;@@ -237,6 +241,8 @@ int sample__fprintf_sym(struct perf_sample *sample, struct addr_location *al,if (print_dso) { printed +=fprintf (fp," (" ); printed +=map__fprintf_dsoname (al->map, fp); +if (print_dsoff && al->map && al->map->dso) + printed +=fprintf (fp,"+0x%lx" , al->addr); printed +=fprintf (fp,")" ); }tools/perf/util/evsel_fprintf.h +1
-0@@ -26,6 +26,7 @@ int evsel__fprintf(struct evsel *evsel, struct perf_attr_details *details, FILE#define EVSEL__PRINT_UNKNOWN_AS_ADDR (1<<6)#define EVSEL__PRINT_CALLCHAIN_ARROW (1<<7)#define EVSEL__PRINT_SKIP_IGNORED (1<<8) +#define EVSEL__PRINT_DSOFF (1<<9)struct addr_location ;struct perf_event_attr ;
Signature · 2 lines
Cheers, Changbin Du