perf: script: add new output field 'dsoip'
PATCH 1/1 perf: script: add new output field 'dsoip'
The goal of this change is to achieve consistent output for address. Before this, the raw ip is printed for non-callchain and binary offset for callchain. Mostly what we expect is the raw ip.
This patch does two changes:
- Always print raw ip for symbols.
- Add a new 'dsoip' field if we really need the binary offset, and the offset is appended to dso name.
Default output now:
$ perf script
perf-exec 171459 5380927.621499: 1 cycles: ffffffff8c66e1b8 [unknown] ([unknown])
perf-exec 171459 5380927.621524: 1 cycles: ffffffff8c66e1b8 [unknown] ([unknown])
perf-exec 171459 5380927.621527: 2 cycles: ffffffff8c66e1b8 [unknown] ([unknown])
perf-exec 171459 5380927.621530: 17 cycles: ffffffff8c66e1b8 [unknown] ([unknown])
perf-exec 171459 5380927.621533: 194 cycles: ffffffff8c66e1bf [unknown] ([unknown])
perf-exec 171459 5380927.621536: 2153 cycles: ffffffff8c6375fe [unknown] ([unknown])
perf-exec 171459 5380927.621540: 23135 cycles: ffffffff8d001ac4 [unknown] ([unknown])
perf-exec 171459 5380927.621555: 224703 cycles: ffffffff8c7a5153 [unknown] ([unknown])
ls 171459 5380927.621686: 587397 cycles: ffffffff8c7c43de [unknown] ([unknown])
ls 171459 5380927.622016: 653693 cycles: 7fe1e47278c7 _dl_map_object_deps+0x307 (/lib/x86_64-linux-gnu/ld-2.27.so)
ls 171459 5380927.622382: 633896 cycles: 7fe1e41bd0d0 __wmemchr_ifunc+0x0 (/lib/x86_64-linux-gnu/libc-2.27.so)
ls 171459 5380927.622737: 608856 cycles: 7fe1e4194594 _int_malloc+0x264 (/lib/x86_64-linux-gnu/libc-2.27.so)
ls 171459 5380927.623078: 586376 cycles: 55ff5293d27c [unknown] (/bin/ls)
ls 171459 5380927.623405: 566812 cycles: 55ff5293b202 [unknown] (/bin/ls)
ls 171459 5380927.623723: 549960 cycles: ffffffff8c82b138 [unknown] ([unknown])Display 'dsoip' field:
$ perf script -F +dsoip
perf-exec 171459 5380927.621499: 1 cycles: ffffffff8c66e1b8 [unknown] ([unknown]+0x0)
perf-exec 171459 5380927.621524: 1 cycles: ffffffff8c66e1b8 [unknown] ([unknown]+0x0)
perf-exec 171459 5380927.621527: 2 cycles: ffffffff8c66e1b8 [unknown] ([unknown]+0x0)
perf-exec 171459 5380927.621530: 17 cycles: ffffffff8c66e1b8 [unknown] ([unknown]+0x0)
perf-exec 171459 5380927.621533: 194 cycles: ffffffff8c66e1bf [unknown] ([unknown]+0x0)
perf-exec 171459 5380927.621536: 2153 cycles: ffffffff8c6375fe [unknown] ([unknown]+0x0)
perf-exec 171459 5380927.621540: 23135 cycles: ffffffff8d001ac4 [unknown] ([unknown]+0x0)
perf-exec 171459 5380927.621555: 224703 cycles: ffffffff8c7a5153 [unknown] ([unknown]+0x0)
ls 171459 5380927.621686: 587397 cycles: ffffffff8c7c43de [unknown] ([unknown]+0x0)
ls 171459 5380927.622016: 653693 cycles: 7fe1e47278c7 _dl_map_object_deps+0x307 (/lib/x86_64-linux-gnu/ld-2.27.so+0xe8c7)
ls 171459 5380927.622382: 633896 cycles: 7fe1e41bd0d0 __wmemchr_ifunc+0x0 (/lib/x86_64-linux-gnu/libc-2.27.so+0xbd0d0)
ls 171459 5380927.622737: 608856 cycles: 7fe1e4194594 _int_malloc+0x264 (/lib/x86_64-linux-gnu/libc-2.27.so+0x94594)
ls 171459 5380927.623078: 586376 cycles: 55ff5293d27c [unknown] (/bin/ls+0x1227c)
ls 171459 5380927.623405: 566812 cycles: 55ff5293b202 [unknown] (/bin/ls+0x10202)
ls 171459 5380927.623723: 549960 cycles: ffffffff8c82b138 [unknown] ([unknown]+0x0)--- tools/perf/Documentation/perf-script.txt | 2 +- tools/perf/builtin-script.c | 5 +++++ tools/perf/util/evsel_fprintf.c | 26 ++++++++++++------------ tools/perf/util/evsel_fprintf.h | 13 ++++++------ 4 files changed, 26 insertions(+), 20 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, dsoip, 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
@@ -133,6 +133,7 @@ enum perf_output_field {PERF_OUTPUT_VCPU =1ULL <<38 ,PERF_OUTPUT_CGROUP =1ULL <<39 ,PERF_OUTPUT_RETIRE_LAT =1ULL <<40 , + PERF_OUTPUT_DSOIP = 1ULL << 41, }; struct perf_script {
@@ -174,6 +175,7 @@ struct output_option { {.str = "ip", .field = PERF_OUTPUT_IP}, {.str = "sym", .field = PERF_OUTPUT_SYM}, {.str = "dso", .field = PERF_OUTPUT_DSO}, + {.str = "dsoip", .field = PERF_OUTPUT_DSOIP}, {.str = "addr", .field = PERF_OUTPUT_ADDR}, {.str = "symoff", .field = PERF_OUTPUT_SYMOFFSET}, {.str = "srcline", .field = PERF_OUTPUT_SRCLINE},
@@ -574,6 +576,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 (DSOIP )) + output[type].print_ip_opts |=EVSEL__PRINT_DSOIP ; +if (PRINT_FIELD (SYMOFFSET )) output[type].print_ip_opts |=EVSEL__PRINT_SYMOFFSET ;
tools/perf/util/evsel_fprintf.c +13 -13
@@ -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_dsoip = print_opts &EVSEL__PRINT_DSOIP ;int print_symoffset = print_opts &EVSEL__PRINT_SYMOFFSET ;int print_oneline = print_opts &EVSEL__PRINT_ONELINE ;int print_srcline = print_opts &EVSEL__PRINT_SRCLINE ;
@@ -133,7 +134,7 @@ int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment,while (1 ) {struct symbol *sym;struct map *map; -u64 addr =0 ; +u64 dso_ip =0 ; node =callchain_cursor_current (cursor);if (!node)
@@ -141,6 +142,8 @@ int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment, sym = node->ms.sym; map = node->ms.map; +if (map) + dso_ip = map->map_ip (map, node->ip);if (sym && sym->ignore && print_skip_ignored) goto next;
@@ -150,20 +153,12 @@ int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment,if (print_arrow && !first) printed +=fprintf (fp," <-" ); -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," " ); - node_al.addr = addr; + node_al.addr = dso_ip; node_al.map = map;if (print_symoffset) {
@@ -179,11 +174,13 @@ 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_dsoip) + printed +=fprintf (fp,"+0x%lx" , (map && map->dso) ? dso_ip :0 ); printed +=fprintf (fp,")" ); }if (print_srcline) - printed +=map__fprintf_srcline (map, addr,"\n " , fp); + printed +=map__fprintf_srcline (map, dso_ip,"\n " , fp);if (sym && sym->inlined) printed +=fprintf (fp," (inlined)" );
@@ -214,6 +211,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_dsoip = print_opts &EVSEL__PRINT_DSOIP ;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 ;
@@ -242,6 +240,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_dsoip) + printed +=fprintf (fp,"+0x%lx" , (al->map && al->map->dso) ? al->addr :0 ); printed +=fprintf (fp,")" ); }
tools/perf/util/evsel_fprintf.h +7 -6
@@ -20,12 +20,13 @@ int evsel__fprintf(struct evsel *evsel, struct perf_attr_details *details, FILE#define EVSEL__PRINT_IP (1<<0)#define EVSEL__PRINT_SYM (1<<1)#define EVSEL__PRINT_DSO (1<<2) -#define EVSEL__PRINT_SYMOFFSET (1<<3) -#define EVSEL__PRINT_ONELINE (1<<4) -#define EVSEL__PRINT_SRCLINE (1<<5) -#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_DSOIP (1<<3) +#define EVSEL__PRINT_SYMOFFSET (1<<4) +#define EVSEL__PRINT_ONELINE (1<<5) +#define EVSEL__PRINT_SRCLINE (1<<6) +#define EVSEL__PRINT_UNKNOWN_AS_ADDR (1<<7) +#define EVSEL__PRINT_CALLCHAIN_ARROW (1<<8) +#define EVSEL__PRINT_SKIP_IGNORED (1<<9)struct addr_location ;struct perf_event_attr ;
Signature · 1 line
2.25.1
Adrian Hunter
reviewerQuoted 7 lines · Changbin Du
The goal of this change is to achieve consistent output for address. Before this, the raw ip is printed for non-callchain and binary offset for callchain. Mostly what we expect is the raw ip.
This patch does two changes:
- Always print raw ip for symbols.
- Add a new 'dsoip' field if we really need the binary offset, and the
IP stands for instruction pointer, which is always a memory address, so 'dsoip' does not seem like a good name. What about 'dso_offset'?
Quoted 102 lines
offset is appended to dso name.
Default output now:
$ perf script perf-exec 171459 5380927.621499: 1 cycles: ffffffff8c66e1b8 [unknown] ([unknown]) perf-exec 171459 5380927.621524: 1 cycles: ffffffff8c66e1b8 [unknown] ([unknown]) perf-exec 171459 5380927.621527: 2 cycles: ffffffff8c66e1b8 [unknown] ([unknown]) perf-exec 171459 5380927.621530: 17 cycles: ffffffff8c66e1b8 [unknown] ([unknown]) perf-exec 171459 5380927.621533: 194 cycles: ffffffff8c66e1bf [unknown] ([unknown]) perf-exec 171459 5380927.621536: 2153 cycles: ffffffff8c6375fe [unknown] ([unknown]) perf-exec 171459 5380927.621540: 23135 cycles: ffffffff8d001ac4 [unknown] ([unknown]) perf-exec 171459 5380927.621555: 224703 cycles: ffffffff8c7a5153 [unknown] ([unknown]) ls 171459 5380927.621686: 587397 cycles: ffffffff8c7c43de [unknown] ([unknown]) ls 171459 5380927.622016: 653693 cycles: 7fe1e47278c7 _dl_map_object_deps+0x307 (/lib/x86_64-linux-gnu/ld-2.27.so) ls 171459 5380927.622382: 633896 cycles: 7fe1e41bd0d0 __wmemchr_ifunc+0x0 (/lib/x86_64-linux-gnu/libc-2.27.so) ls 171459 5380927.622737: 608856 cycles: 7fe1e4194594 _int_malloc+0x264 (/lib/x86_64-linux-gnu/libc-2.27.so) ls 171459 5380927.623078: 586376 cycles: 55ff5293d27c [unknown] (/bin/ls) ls 171459 5380927.623405: 566812 cycles: 55ff5293b202 [unknown] (/bin/ls) ls 171459 5380927.623723: 549960 cycles: ffffffff8c82b138 [unknown] ([unknown])Display 'dsoip' field:
$ perf script -F +dsoip perf-exec 171459 5380927.621499: 1 cycles: ffffffff8c66e1b8 [unknown] ([unknown]+0x0) perf-exec 171459 5380927.621524: 1 cycles: ffffffff8c66e1b8 [unknown] ([unknown]+0x0) perf-exec 171459 5380927.621527: 2 cycles: ffffffff8c66e1b8 [unknown] ([unknown]+0x0) perf-exec 171459 5380927.621530: 17 cycles: ffffffff8c66e1b8 [unknown] ([unknown]+0x0) perf-exec 171459 5380927.621533: 194 cycles: ffffffff8c66e1bf [unknown] ([unknown]+0x0) perf-exec 171459 5380927.621536: 2153 cycles: ffffffff8c6375fe [unknown] ([unknown]+0x0) perf-exec 171459 5380927.621540: 23135 cycles: ffffffff8d001ac4 [unknown] ([unknown]+0x0) perf-exec 171459 5380927.621555: 224703 cycles: ffffffff8c7a5153 [unknown] ([unknown]+0x0) ls 171459 5380927.621686: 587397 cycles: ffffffff8c7c43de [unknown] ([unknown]+0x0) ls 171459 5380927.622016: 653693 cycles: 7fe1e47278c7 _dl_map_object_deps+0x307 (/lib/x86_64-linux-gnu/ld-2.27.so+0xe8c7) ls 171459 5380927.622382: 633896 cycles: 7fe1e41bd0d0 __wmemchr_ifunc+0x0 (/lib/x86_64-linux-gnu/libc-2.27.so+0xbd0d0) ls 171459 5380927.622737: 608856 cycles: 7fe1e4194594 _int_malloc+0x264 (/lib/x86_64-linux-gnu/libc-2.27.so+0x94594) ls 171459 5380927.623078: 586376 cycles: 55ff5293d27c [unknown] (/bin/ls+0x1227c) ls 171459 5380927.623405: 566812 cycles: 55ff5293b202 [unknown] (/bin/ls+0x10202) ls 171459 5380927.623723: 549960 cycles: ffffffff8c82b138 [unknown] ([unknown]+0x0)Signed-off-by Changbin Du <[email protected]>--- tools/perf/Documentation/perf-script.txt | 2 +- tools/perf/builtin-script.c | 5 +++++ tools/perf/util/evsel_fprintf.c | 26 ++++++++++++------------ tools/perf/util/evsel_fprintf.h | 13 ++++++------ 4 files changed, 26 insertions(+), 20 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, dsoip, 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@@ -133,6 +133,7 @@ enum perf_output_field {PERF_OUTPUT_VCPU =1ULL <<38 ,PERF_OUTPUT_CGROUP =1ULL <<39 ,PERF_OUTPUT_RETIRE_LAT =1ULL <<40 , + PERF_OUTPUT_DSOIP = 1ULL << 41, }; struct perf_script {@@ -174,6 +175,7 @@ struct output_option { {.str = "ip", .field = PERF_OUTPUT_IP}, {.str = "sym", .field = PERF_OUTPUT_SYM}, {.str = "dso", .field = PERF_OUTPUT_DSO}, + {.str = "dsoip", .field = PERF_OUTPUT_DSOIP}, {.str = "addr", .field = PERF_OUTPUT_ADDR}, {.str = "symoff", .field = PERF_OUTPUT_SYMOFFSET}, {.str = "srcline", .field = PERF_OUTPUT_SRCLINE},@@ -574,6 +576,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 (DSOIP )) + output[type].print_ip_opts |=EVSEL__PRINT_DSOIP ; +if (PRINT_FIELD (SYMOFFSET )) output[type].print_ip_opts |=EVSEL__PRINT_SYMOFFSET ;tools/perf/util/evsel_fprintf.c +1
-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_dsoip = print_opts &EVSEL__PRINT_DSOIP ;int print_symoffset = print_opts &EVSEL__PRINT_SYMOFFSET ;int print_oneline = print_opts &EVSEL__PRINT_ONELINE ;int print_srcline = print_opts &EVSEL__PRINT_SRCLINE ;
tools/perf/util/evsel_fprintf.c int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment, · line 137
Quoted 5 lines
tools/perf/util/evsel_fprintf.c +1
-1@@ -133,7 +134,7 @@ int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment,while (1 ) {struct symbol *sym;struct map *map; -u64 addr =0 ; +u64 dso_ip =0 ;
Renaming 'addr' just makes the patch more complicated. Just leave it as 'addr'
tools/perf/util/evsel_fprintf.c int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment, · line 146
Quoted 9 lines
tools/perf/util/evsel_fprintf.c +2
-0node =callchain_cursor_current (cursor);if (!node)@@ -141,6 +142,8 @@ int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment, sym = node->ms.sym; map = node->ms.map; +if (map) + dso_ip = map->map_ip (map, node->ip);
There does not seem to be any reason to move these lines of code.
tools/perf/util/evsel_fprintf.c int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment, · line 158
Quoted 13 lines
tools/perf/util/evsel_fprintf.c +0
-6if (sym && sym->ignore && print_skip_ignored) goto next;@@ -150,20 +153,12 @@ int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment,if (print_arrow && !first) printed +=fprintf (fp," <-" ); -if (map) - addr = map->map_ip (map, node->ip); - -if (print_ip) { -/* Show binary offset for userspace addr */ -if (map && !map->dso->kernel)
I would have expected to keep existing functionality unchanged i.e.
- if (map && !map->dso->kernel)
+ if (!print_dsoip && map && !map->dso->kernel)
Quoted 15 lines
tools/perf/util/evsel_fprintf.c +3
-5- 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," " ); - node_al.addr = addr; + node_al.addr = dso_ip; node_al.map = map;if (print_symoffset) {
tools/perf/util/evsel_fprintf.c int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment, · line 177
Quoted 4 lines
tools/perf/util/evsel_fprintf.c +1
-0@@ -179,11 +174,13 @@ 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_dsoip)
Better to avoid '[unknown]+0x0' i.e.
if (print_dsoip && map && map->dso)
Quoted 19 lines
tools/perf/util/evsel_fprintf.c +3
-1+ printed +=fprintf (fp,"+0x%lx" , (map && map->dso) ? dso_ip :0 ); printed +=fprintf (fp,")" ); }if (print_srcline) - printed +=map__fprintf_srcline (map, addr,"\n " , fp); + printed +=map__fprintf_srcline (map, dso_ip,"\n " , fp);if (sym && sym->inlined) printed +=fprintf (fp," (inlined)" );@@ -214,6 +211,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_dsoip = print_opts &EVSEL__PRINT_DSOIP ;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 ;
tools/perf/util/evsel_fprintf.c int sample__fprintf_sym(struct perf_sample *sample, struct addr_location *al, · line 243
Quoted 4 lines
tools/perf/util/evsel_fprintf.c +1
-0@@ -242,6 +240,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_dsoip)
Better to avoid '[unknown]+0x0' i.e.
if (print_dsoip && al->map && al->map->dso)
Quoted 28 lines
tools/perf/util/evsel_fprintf.c +1
-0+ printed +=fprintf (fp,"+0x%lx" , (al->map && al->map->dso) ? al->addr :0 ); printed +=fprintf (fp,")" ); }tools/perf/util/evsel_fprintf.h +7
-6@@ -20,12 +20,13 @@ int evsel__fprintf(struct evsel *evsel, struct perf_attr_details *details, FILE#define EVSEL__PRINT_IP (1<<0)#define EVSEL__PRINT_SYM (1<<1)#define EVSEL__PRINT_DSO (1<<2) -#define EVSEL__PRINT_SYMOFFSET (1<<3) -#define EVSEL__PRINT_ONELINE (1<<4) -#define EVSEL__PRINT_SRCLINE (1<<5) -#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_DSOIP (1<<3) +#define EVSEL__PRINT_SYMOFFSET (1<<4) +#define EVSEL__PRINT_ONELINE (1<<5) +#define EVSEL__PRINT_SRCLINE (1<<6) +#define EVSEL__PRINT_UNKNOWN_AS_ADDR (1<<7) +#define EVSEL__PRINT_CALLCHAIN_ARROW (1<<8) +#define EVSEL__PRINT_SKIP_IGNORED (1<<9)struct addr_location ;struct perf_event_attr ;
Adrian Hunter
reviewerQuoted 224 lines · Adrian Hunter
Quoted 7 lines · Changbin Du
The goal of this change is to achieve consistent output for address. Before this, the raw ip is printed for non-callchain and binary offset for callchain. Mostly what we expect is the raw ip.
This patch does two changes:
- Always print raw ip for symbols.
- Add a new 'dsoip' field if we really need the binary offset, and theIP stands for instruction pointer, which is always a memory address, so 'dsoip' does not seem like a good name. What about '
dso_offset'?Quoted 102 lines
offset is appended to dso name.
Default output now:
$ perf script perf-exec 171459 5380927.621499: 1 cycles: ffffffff8c66e1b8 [unknown] ([unknown]) perf-exec 171459 5380927.621524: 1 cycles: ffffffff8c66e1b8 [unknown] ([unknown]) perf-exec 171459 5380927.621527: 2 cycles: ffffffff8c66e1b8 [unknown] ([unknown]) perf-exec 171459 5380927.621530: 17 cycles: ffffffff8c66e1b8 [unknown] ([unknown]) perf-exec 171459 5380927.621533: 194 cycles: ffffffff8c66e1bf [unknown] ([unknown]) perf-exec 171459 5380927.621536: 2153 cycles: ffffffff8c6375fe [unknown] ([unknown]) perf-exec 171459 5380927.621540: 23135 cycles: ffffffff8d001ac4 [unknown] ([unknown]) perf-exec 171459 5380927.621555: 224703 cycles: ffffffff8c7a5153 [unknown] ([unknown]) ls 171459 5380927.621686: 587397 cycles: ffffffff8c7c43de [unknown] ([unknown]) ls 171459 5380927.622016: 653693 cycles: 7fe1e47278c7 _dl_map_object_deps+0x307 (/lib/x86_64-linux-gnu/ld-2.27.so) ls 171459 5380927.622382: 633896 cycles: 7fe1e41bd0d0 __wmemchr_ifunc+0x0 (/lib/x86_64-linux-gnu/libc-2.27.so) ls 171459 5380927.622737: 608856 cycles: 7fe1e4194594 _int_malloc+0x264 (/lib/x86_64-linux-gnu/libc-2.27.so) ls 171459 5380927.623078: 586376 cycles: 55ff5293d27c [unknown] (/bin/ls) ls 171459 5380927.623405: 566812 cycles: 55ff5293b202 [unknown] (/bin/ls) ls 171459 5380927.623723: 549960 cycles: ffffffff8c82b138 [unknown] ([unknown])Display 'dsoip' field:
$ perf script -F +dsoip perf-exec 171459 5380927.621499: 1 cycles: ffffffff8c66e1b8 [unknown] ([unknown]+0x0) perf-exec 171459 5380927.621524: 1 cycles: ffffffff8c66e1b8 [unknown] ([unknown]+0x0) perf-exec 171459 5380927.621527: 2 cycles: ffffffff8c66e1b8 [unknown] ([unknown]+0x0) perf-exec 171459 5380927.621530: 17 cycles: ffffffff8c66e1b8 [unknown] ([unknown]+0x0) perf-exec 171459 5380927.621533: 194 cycles: ffffffff8c66e1bf [unknown] ([unknown]+0x0) perf-exec 171459 5380927.621536: 2153 cycles: ffffffff8c6375fe [unknown] ([unknown]+0x0) perf-exec 171459 5380927.621540: 23135 cycles: ffffffff8d001ac4 [unknown] ([unknown]+0x0) perf-exec 171459 5380927.621555: 224703 cycles: ffffffff8c7a5153 [unknown] ([unknown]+0x0) ls 171459 5380927.621686: 587397 cycles: ffffffff8c7c43de [unknown] ([unknown]+0x0) ls 171459 5380927.622016: 653693 cycles: 7fe1e47278c7 _dl_map_object_deps+0x307 (/lib/x86_64-linux-gnu/ld-2.27.so+0xe8c7) ls 171459 5380927.622382: 633896 cycles: 7fe1e41bd0d0 __wmemchr_ifunc+0x0 (/lib/x86_64-linux-gnu/libc-2.27.so+0xbd0d0) ls 171459 5380927.622737: 608856 cycles: 7fe1e4194594 _int_malloc+0x264 (/lib/x86_64-linux-gnu/libc-2.27.so+0x94594) ls 171459 5380927.623078: 586376 cycles: 55ff5293d27c [unknown] (/bin/ls+0x1227c) ls 171459 5380927.623405: 566812 cycles: 55ff5293b202 [unknown] (/bin/ls+0x10202) ls 171459 5380927.623723: 549960 cycles: ffffffff8c82b138 [unknown] ([unknown]+0x0)Signed-off-by Changbin Du <[email protected]>--- tools/perf/Documentation/perf-script.txt | 2 +- tools/perf/builtin-script.c | 5 +++++ tools/perf/util/evsel_fprintf.c | 26 ++++++++++++------------ tools/perf/util/evsel_fprintf.h | 13 ++++++------ 4 files changed, 26 insertions(+), 20 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, dsoip, 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@@ -133,6 +133,7 @@ enum perf_output_field {PERF_OUTPUT_VCPU =1ULL <<38 ,PERF_OUTPUT_CGROUP =1ULL <<39 ,PERF_OUTPUT_RETIRE_LAT =1ULL <<40 , + PERF_OUTPUT_DSOIP = 1ULL << 41, }; struct perf_script {@@ -174,6 +175,7 @@ struct output_option { {.str = "ip", .field = PERF_OUTPUT_IP}, {.str = "sym", .field = PERF_OUTPUT_SYM}, {.str = "dso", .field = PERF_OUTPUT_DSO}, + {.str = "dsoip", .field = PERF_OUTPUT_DSOIP}, {.str = "addr", .field = PERF_OUTPUT_ADDR}, {.str = "symoff", .field = PERF_OUTPUT_SYMOFFSET}, {.str = "srcline", .field = PERF_OUTPUT_SRCLINE},@@ -574,6 +576,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 (DSOIP )) + output[type].print_ip_opts |=EVSEL__PRINT_DSOIP ; +if (PRINT_FIELD (SYMOFFSET )) output[type].print_ip_opts |=EVSEL__PRINT_SYMOFFSET ;tools/perf/util/evsel_fprintf.c +1
-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_dsoip = print_opts &EVSEL__PRINT_DSOIP ;int print_symoffset = print_opts &EVSEL__PRINT_SYMOFFSET ;int print_oneline = print_opts &EVSEL__PRINT_ONELINE ;int print_srcline = print_opts &EVSEL__PRINT_SRCLINE ;tools/perf/util/evsel_fprintf.c int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment, · line 137
Quoted 5 lines
tools/perf/util/evsel_fprintf.c +1
-1@@ -133,7 +134,7 @@ int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment,while (1 ) {struct symbol *sym;struct map *map; -u64 addr =0 ; +u64 dso_ip =0 ;Renaming 'addr' just makes the patch more complicated. Just leave it as 'addr'
tools/perf/util/evsel_fprintf.c int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment, · line 146
Quoted 9 lines
tools/perf/util/evsel_fprintf.c +2
-0node =callchain_cursor_current (cursor);if (!node)@@ -141,6 +142,8 @@ int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment, sym = node->ms.sym; map = node->ms.map; +if (map) + dso_ip = map->map_ip (map, node->ip);There does not seem to be any reason to move these lines of code.
tools/perf/util/evsel_fprintf.c int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment, · line 158
Quoted 13 lines
tools/perf/util/evsel_fprintf.c +0
-6if (sym && sym->ignore && print_skip_ignored) goto next;@@ -150,20 +153,12 @@ int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment,if (print_arrow && !first) printed +=fprintf (fp," <-" ); -if (map) - addr = map->map_ip (map, node->ip); - -if (print_ip) { -/* Show binary offset for userspace addr */ -if (map && !map->dso->kernel)I would have expected to keep existing functionality unchanged i.e.
(quoted diff) +1
-1- if (map && !map->dso->kernel) + if (!print_dsoip && map && !map->dso->kernel)Quoted 16 lines
tools/perf/util/evsel_fprintf.c +3
-5- 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," " ); - node_al.addr = addr; + node_al.addr = dso_ip; node_al.map = map;if (print_symoffset) {tools/perf/util/evsel_fprintf.c int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment, · line 177
Quoted 4 lines
tools/perf/util/evsel_fprintf.c +1
-0@@ -179,11 +174,13 @@ 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_dsoip)Better to avoid '[unknown]+0x0' i.e.
if (print_dsoip && map && map->dso)Quoted 19 lines
tools/perf/util/evsel_fprintf.c +3
-1+ printed +=fprintf (fp,"+0x%lx" , (map && map->dso) ? dso_ip :0 ); printed +=fprintf (fp,")" ); }if (print_srcline) - printed +=map__fprintf_srcline (map, addr,"\n " , fp); + printed +=map__fprintf_srcline (map, dso_ip,"\n " , fp);if (sym && sym->inlined) printed +=fprintf (fp," (inlined)" );@@ -214,6 +211,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_dsoip = print_opts &EVSEL__PRINT_DSOIP ;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 ;tools/perf/util/evsel_fprintf.c int sample__fprintf_sym(struct perf_sample *sample, struct addr_location *al, · line 243
Quoted 4 lines
tools/perf/util/evsel_fprintf.c +1
-0@@ -242,6 +240,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_dsoip)Better to avoid '[unknown]+0x0' i.e.
if (print_dsoip && al->map && al->map->dso)Quoted 17 lines
tools/perf/util/evsel_fprintf.c +1
-0+ printed +=fprintf (fp,"+0x%lx" , (al->map && al->map->dso) ? al->addr :0 ); printed +=fprintf (fp,")" ); }tools/perf/util/evsel_fprintf.h +0
-5@@ -20,12 +20,13 @@ int evsel__fprintf(struct evsel *evsel, struct perf_attr_details *details, FILE#define EVSEL__PRINT_IP (1<<0)#define EVSEL__PRINT_SYM (1<<1)#define EVSEL__PRINT_DSO (1<<2) -#define EVSEL__PRINT_SYMOFFSET (1<<3) -#define EVSEL__PRINT_ONELINE (1<<4) -#define EVSEL__PRINT_SRCLINE (1<<5) -#define EVSEL__PRINT_UNKNOWN_AS_ADDR (1<<6) -#define EVSEL__PRINT_CALLCHAIN_ARROW (1<<7)
Quoted 8 lines
tools/perf/util/evsel_fprintf.h int evsel__fprintf(struct evsel *evsel, struct perf_attr_details *details, FILE · line 29
Quoted 8 lines
tools/perf/util/evsel_fprintf.h +7
-1-#define EVSEL__PRINT_SKIP_IGNORED (1<<8) +#define EVSEL__PRINT_DSOIP (1<<3) +#define EVSEL__PRINT_SYMOFFSET (1<<4) +#define EVSEL__PRINT_ONELINE (1<<5) +#define EVSEL__PRINT_SRCLINE (1<<6) +#define EVSEL__PRINT_UNKNOWN_AS_ADDR (1<<7) +#define EVSEL__PRINT_CALLCHAIN_ARROW (1<<8) +#define EVSEL__PRINT_SKIP_IGNORED (1<<9)
Also, do these really need to be renumbered? Why not just put:
#define EVSEL__PRINT_DSOIP (1<<9)
Quoted 4 lines
Quoted 3 lines
tools/perf/util/evsel_fprintf.h +0
-0struct addr_location ;struct perf_event_attr ;
Quoted 5 lines · Adrian Hunter
Quoted 4 lines · Changbin Du
The goal of this change is to achieve consistent output for address. Before this, the raw ip is printed for non-callchain and binary offset for callchain. Mostly what we expect is the raw ip.
Quoted 7 lines
Quoted 3 lines
This patch does two changes:
- Always print raw ip for symbols.
- Add a new 'dsoip' field if we really need the binary offset, and theIP stands for instruction pointer, which is always a memory address, so 'dsoip' does not seem like a good name. What about '
dso_offset'?
This name is inherited from the comments of map::map_ip. Actually now we have three terms: dos ip, binary offset and dso offset. I also prefer to 'dso_offset'.
Quoted 102 lines
Quoted 102 lines
offset is appended to dso name.
Default output now:
$ perf script perf-exec 171459 5380927.621499: 1 cycles: ffffffff8c66e1b8 [unknown] ([unknown]) perf-exec 171459 5380927.621524: 1 cycles: ffffffff8c66e1b8 [unknown] ([unknown]) perf-exec 171459 5380927.621527: 2 cycles: ffffffff8c66e1b8 [unknown] ([unknown]) perf-exec 171459 5380927.621530: 17 cycles: ffffffff8c66e1b8 [unknown] ([unknown]) perf-exec 171459 5380927.621533: 194 cycles: ffffffff8c66e1bf [unknown] ([unknown]) perf-exec 171459 5380927.621536: 2153 cycles: ffffffff8c6375fe [unknown] ([unknown]) perf-exec 171459 5380927.621540: 23135 cycles: ffffffff8d001ac4 [unknown] ([unknown]) perf-exec 171459 5380927.621555: 224703 cycles: ffffffff8c7a5153 [unknown] ([unknown]) ls 171459 5380927.621686: 587397 cycles: ffffffff8c7c43de [unknown] ([unknown]) ls 171459 5380927.622016: 653693 cycles: 7fe1e47278c7 _dl_map_object_deps+0x307 (/lib/x86_64-linux-gnu/ld-2.27.so) ls 171459 5380927.622382: 633896 cycles: 7fe1e41bd0d0 __wmemchr_ifunc+0x0 (/lib/x86_64-linux-gnu/libc-2.27.so) ls 171459 5380927.622737: 608856 cycles: 7fe1e4194594 _int_malloc+0x264 (/lib/x86_64-linux-gnu/libc-2.27.so) ls 171459 5380927.623078: 586376 cycles: 55ff5293d27c [unknown] (/bin/ls) ls 171459 5380927.623405: 566812 cycles: 55ff5293b202 [unknown] (/bin/ls) ls 171459 5380927.623723: 549960 cycles: ffffffff8c82b138 [unknown] ([unknown])Display 'dsoip' field:
$ perf script -F +dsoip perf-exec 171459 5380927.621499: 1 cycles: ffffffff8c66e1b8 [unknown] ([unknown]+0x0) perf-exec 171459 5380927.621524: 1 cycles: ffffffff8c66e1b8 [unknown] ([unknown]+0x0) perf-exec 171459 5380927.621527: 2 cycles: ffffffff8c66e1b8 [unknown] ([unknown]+0x0) perf-exec 171459 5380927.621530: 17 cycles: ffffffff8c66e1b8 [unknown] ([unknown]+0x0) perf-exec 171459 5380927.621533: 194 cycles: ffffffff8c66e1bf [unknown] ([unknown]+0x0) perf-exec 171459 5380927.621536: 2153 cycles: ffffffff8c6375fe [unknown] ([unknown]+0x0) perf-exec 171459 5380927.621540: 23135 cycles: ffffffff8d001ac4 [unknown] ([unknown]+0x0) perf-exec 171459 5380927.621555: 224703 cycles: ffffffff8c7a5153 [unknown] ([unknown]+0x0) ls 171459 5380927.621686: 587397 cycles: ffffffff8c7c43de [unknown] ([unknown]+0x0) ls 171459 5380927.622016: 653693 cycles: 7fe1e47278c7 _dl_map_object_deps+0x307 (/lib/x86_64-linux-gnu/ld-2.27.so+0xe8c7) ls 171459 5380927.622382: 633896 cycles: 7fe1e41bd0d0 __wmemchr_ifunc+0x0 (/lib/x86_64-linux-gnu/libc-2.27.so+0xbd0d0) ls 171459 5380927.622737: 608856 cycles: 7fe1e4194594 _int_malloc+0x264 (/lib/x86_64-linux-gnu/libc-2.27.so+0x94594) ls 171459 5380927.623078: 586376 cycles: 55ff5293d27c [unknown] (/bin/ls+0x1227c) ls 171459 5380927.623405: 566812 cycles: 55ff5293b202 [unknown] (/bin/ls+0x10202) ls 171459 5380927.623723: 549960 cycles: ffffffff8c82b138 [unknown] ([unknown]+0x0)Signed-off-by Changbin Du <[email protected]>--- tools/perf/Documentation/perf-script.txt | 2 +- tools/perf/builtin-script.c | 5 +++++ tools/perf/util/evsel_fprintf.c | 26 ++++++++++++------------ tools/perf/util/evsel_fprintf.h | 13 ++++++------ 4 files changed, 26 insertions(+), 20 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, dsoip, 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@@ -133,6 +133,7 @@ enum perf_output_field {PERF_OUTPUT_VCPU =1ULL <<38 ,PERF_OUTPUT_CGROUP =1ULL <<39 ,PERF_OUTPUT_RETIRE_LAT =1ULL <<40 , + PERF_OUTPUT_DSOIP = 1ULL << 41, }; struct perf_script {@@ -174,6 +175,7 @@ struct output_option { {.str = "ip", .field = PERF_OUTPUT_IP}, {.str = "sym", .field = PERF_OUTPUT_SYM}, {.str = "dso", .field = PERF_OUTPUT_DSO}, + {.str = "dsoip", .field = PERF_OUTPUT_DSOIP}, {.str = "addr", .field = PERF_OUTPUT_ADDR}, {.str = "symoff", .field = PERF_OUTPUT_SYMOFFSET}, {.str = "srcline", .field = PERF_OUTPUT_SRCLINE},@@ -574,6 +576,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 (DSOIP )) + output[type].print_ip_opts |=EVSEL__PRINT_DSOIP ; +if (PRINT_FIELD (SYMOFFSET )) output[type].print_ip_opts |=EVSEL__PRINT_SYMOFFSET ;tools/perf/util/evsel_fprintf.c +1
-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_dsoip = print_opts &EVSEL__PRINT_DSOIP ;int print_symoffset = print_opts &EVSEL__PRINT_SYMOFFSET ;int print_oneline = print_opts &EVSEL__PRINT_ONELINE ;int print_srcline = print_opts &EVSEL__PRINT_SRCLINE ;@@ -133,7 +134,7 @@ int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment,
Quoted 9 lines
tools/perf/util/evsel_fprintf.c int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment, · line 137
Quoted 5 lines
tools/perf/util/evsel_fprintf.c +1
-1while (1 ) {struct symbol *sym;struct map *map; -u64 addr =0 ; +u64 dso_ip =0 ;Renaming 'addr' just makes the patch more complicated. Just leave it as 'addr'
Just to make the variable name reflect its real content. It's not a memory address, right?
Quoted 5 lines
Quoted 5 lines
tools/perf/util/evsel_fprintf.c +0
-0node =callchain_cursor_current (cursor);if (!node)@@ -141,6 +142,8 @@ int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment,
Quoted 7 lines
tools/perf/util/evsel_fprintf.c int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment, · line 146
Quoted 4 lines
tools/perf/util/evsel_fprintf.c +2
-0sym = node->ms.sym; map = node->ms.map; +if (map) + dso_ip = map->map_ip (map, node->ip);There does not seem to be any reason to move these lines of code.
yes. I cound undo this. (just a clean up to not place addr calculation betwwen printings)
Quoted 7 lines
Quoted 7 lines
tools/perf/util/evsel_fprintf.c +0
-0if (sym && sym->ignore && print_skip_ignored) goto next;@@ -150,20 +153,12 @@ int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment,if (print_arrow && !first) printed +=fprintf (fp," <-" );
Quoted 9 lines
tools/perf/util/evsel_fprintf.c int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment, · line 158
Quoted 6 lines
tools/perf/util/evsel_fprintf.c +0
-6-if (map) - addr = map->map_ip (map, node->ip); - -if (print_ip) { -/* Show binary offset for userspace addr */ -if (map && !map->dso->kernel)I would have expected to keep existing functionality unchanged i.e.
But the goal is to make printed address consistent. See below difference.
$ perf script
...
ls 1341034 2739463.008343: 2162417 cycles:
ffffffff992a917d [unknown] ([unknown])
ffffffff992a9b0a [unknown] ([unknown])
ffffffff992efa3d [unknown] ([unknown])
ffffffff992f10c9 [unknown] ([unknown])
ffffffff992f47cc [unknown] ([unknown])
ffffffff992f4ab8 [unknown] ([unknown])
ffffffff9909daa2 [unknown] ([unknown])
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)$ 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 ipQuoted 25 lines
(quoted diff) +1
-1- if (map && !map->dso->kernel) + if (!print_dsoip && map && !map->dso->kernel)Quoted 16 lines
tools/perf/util/evsel_fprintf.c +3
-5- 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," " ); - node_al.addr = addr; + node_al.addr = dso_ip; node_al.map = map;if (print_symoffset) {tools/perf/util/evsel_fprintf.c int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment, · line 177
Quoted 4 lines
tools/perf/util/evsel_fprintf.c +1
-0@@ -179,11 +174,13 @@ 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_dsoip)Better to avoid '[unknown]+0x0' i.e.
Quoted 2 lines
if (print_dsoip && map && map->dso)
This is also to keep output consistent which is frendly for parsers (FlameGraph generator for example).
Quoted 26 lines
Quoted 19 lines
tools/perf/util/evsel_fprintf.c +3
-1+ printed +=fprintf (fp,"+0x%lx" , (map && map->dso) ? dso_ip :0 ); printed +=fprintf (fp,")" ); }if (print_srcline) - printed +=map__fprintf_srcline (map, addr,"\n " , fp); + printed +=map__fprintf_srcline (map, dso_ip,"\n " , fp);if (sym && sym->inlined) printed +=fprintf (fp," (inlined)" );@@ -214,6 +211,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_dsoip = print_opts &EVSEL__PRINT_DSOIP ;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 ;tools/perf/util/evsel_fprintf.c int sample__fprintf_sym(struct perf_sample *sample, struct addr_location *al, · line 243
Quoted 4 lines
tools/perf/util/evsel_fprintf.c +1
-0@@ -242,6 +240,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_dsoip)Better to avoid '[unknown]+0x0' i.e.
Quoted 3 lines
if (print_dsoip && al->map && al->map->dso)
Ditto.
Quoted 30 lines
Quoted 28 lines
tools/perf/util/evsel_fprintf.c +1
-0+ printed +=fprintf (fp,"+0x%lx" , (al->map && al->map->dso) ? al->addr :0 ); printed +=fprintf (fp,")" ); }tools/perf/util/evsel_fprintf.h +7
-6@@ -20,12 +20,13 @@ int evsel__fprintf(struct evsel *evsel, struct perf_attr_details *details, FILE#define EVSEL__PRINT_IP (1<<0)#define EVSEL__PRINT_SYM (1<<1)#define EVSEL__PRINT_DSO (1<<2) -#define EVSEL__PRINT_SYMOFFSET (1<<3) -#define EVSEL__PRINT_ONELINE (1<<4) -#define EVSEL__PRINT_SRCLINE (1<<5) -#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_DSOIP (1<<3) +#define EVSEL__PRINT_SYMOFFSET (1<<4) +#define EVSEL__PRINT_ONELINE (1<<5) +#define EVSEL__PRINT_SRCLINE (1<<6) +#define EVSEL__PRINT_UNKNOWN_AS_ADDR (1<<7) +#define EVSEL__PRINT_CALLCHAIN_ARROW (1<<8) +#define EVSEL__PRINT_SKIP_IGNORED (1<<9)struct addr_location ;struct perf_event_attr ;
Signature · 2 lines
Cheers, Changbin Du
Adrian Hunter
reviewerQuoted 128 lines · Changbin Du
Quoted 5 lines · Adrian Hunter
Quoted 4 lines · Changbin Du
The goal of this change is to achieve consistent output for address. Before this, the raw ip is printed for non-callchain and binary offset for callchain. Mostly what we expect is the raw ip.
Quoted 7 lines
Quoted 3 lines
This patch does two changes:
- Always print raw ip for symbols.
- Add a new 'dsoip' field if we really need the binary offset, and theIP stands for instruction pointer, which is always a memory address, so 'dsoip' does not seem like a good name. What about '
dso_offset'?This name is inherited from the comments of
map::map_ip. Actually now we have three terms: dos ip, binary offset and dso offset. I also prefer to 'dso_offset'.Quoted 102 lines
Quoted 102 lines
offset is appended to dso name.
Default output now:
$ perf script perf-exec 171459 5380927.621499: 1 cycles: ffffffff8c66e1b8 [unknown] ([unknown]) perf-exec 171459 5380927.621524: 1 cycles: ffffffff8c66e1b8 [unknown] ([unknown]) perf-exec 171459 5380927.621527: 2 cycles: ffffffff8c66e1b8 [unknown] ([unknown]) perf-exec 171459 5380927.621530: 17 cycles: ffffffff8c66e1b8 [unknown] ([unknown]) perf-exec 171459 5380927.621533: 194 cycles: ffffffff8c66e1bf [unknown] ([unknown]) perf-exec 171459 5380927.621536: 2153 cycles: ffffffff8c6375fe [unknown] ([unknown]) perf-exec 171459 5380927.621540: 23135 cycles: ffffffff8d001ac4 [unknown] ([unknown]) perf-exec 171459 5380927.621555: 224703 cycles: ffffffff8c7a5153 [unknown] ([unknown]) ls 171459 5380927.621686: 587397 cycles: ffffffff8c7c43de [unknown] ([unknown]) ls 171459 5380927.622016: 653693 cycles: 7fe1e47278c7 _dl_map_object_deps+0x307 (/lib/x86_64-linux-gnu/ld-2.27.so) ls 171459 5380927.622382: 633896 cycles: 7fe1e41bd0d0 __wmemchr_ifunc+0x0 (/lib/x86_64-linux-gnu/libc-2.27.so) ls 171459 5380927.622737: 608856 cycles: 7fe1e4194594 _int_malloc+0x264 (/lib/x86_64-linux-gnu/libc-2.27.so) ls 171459 5380927.623078: 586376 cycles: 55ff5293d27c [unknown] (/bin/ls) ls 171459 5380927.623405: 566812 cycles: 55ff5293b202 [unknown] (/bin/ls) ls 171459 5380927.623723: 549960 cycles: ffffffff8c82b138 [unknown] ([unknown])Display 'dsoip' field:
$ perf script -F +dsoip perf-exec 171459 5380927.621499: 1 cycles: ffffffff8c66e1b8 [unknown] ([unknown]+0x0) perf-exec 171459 5380927.621524: 1 cycles: ffffffff8c66e1b8 [unknown] ([unknown]+0x0) perf-exec 171459 5380927.621527: 2 cycles: ffffffff8c66e1b8 [unknown] ([unknown]+0x0) perf-exec 171459 5380927.621530: 17 cycles: ffffffff8c66e1b8 [unknown] ([unknown]+0x0) perf-exec 171459 5380927.621533: 194 cycles: ffffffff8c66e1bf [unknown] ([unknown]+0x0) perf-exec 171459 5380927.621536: 2153 cycles: ffffffff8c6375fe [unknown] ([unknown]+0x0) perf-exec 171459 5380927.621540: 23135 cycles: ffffffff8d001ac4 [unknown] ([unknown]+0x0) perf-exec 171459 5380927.621555: 224703 cycles: ffffffff8c7a5153 [unknown] ([unknown]+0x0) ls 171459 5380927.621686: 587397 cycles: ffffffff8c7c43de [unknown] ([unknown]+0x0) ls 171459 5380927.622016: 653693 cycles: 7fe1e47278c7 _dl_map_object_deps+0x307 (/lib/x86_64-linux-gnu/ld-2.27.so+0xe8c7) ls 171459 5380927.622382: 633896 cycles: 7fe1e41bd0d0 __wmemchr_ifunc+0x0 (/lib/x86_64-linux-gnu/libc-2.27.so+0xbd0d0) ls 171459 5380927.622737: 608856 cycles: 7fe1e4194594 _int_malloc+0x264 (/lib/x86_64-linux-gnu/libc-2.27.so+0x94594) ls 171459 5380927.623078: 586376 cycles: 55ff5293d27c [unknown] (/bin/ls+0x1227c) ls 171459 5380927.623405: 566812 cycles: 55ff5293b202 [unknown] (/bin/ls+0x10202) ls 171459 5380927.623723: 549960 cycles: ffffffff8c82b138 [unknown] ([unknown]+0x0)Signed-off-by Changbin Du <[email protected]>--- tools/perf/Documentation/perf-script.txt | 2 +- tools/perf/builtin-script.c | 5 +++++ tools/perf/util/evsel_fprintf.c | 26 ++++++++++++------------ tools/perf/util/evsel_fprintf.h | 13 ++++++------ 4 files changed, 26 insertions(+), 20 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, dsoip, 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@@ -133,6 +133,7 @@ enum perf_output_field {PERF_OUTPUT_VCPU =1ULL <<38 ,PERF_OUTPUT_CGROUP =1ULL <<39 ,PERF_OUTPUT_RETIRE_LAT =1ULL <<40 , + PERF_OUTPUT_DSOIP = 1ULL << 41, }; struct perf_script {@@ -174,6 +175,7 @@ struct output_option { {.str = "ip", .field = PERF_OUTPUT_IP}, {.str = "sym", .field = PERF_OUTPUT_SYM}, {.str = "dso", .field = PERF_OUTPUT_DSO}, + {.str = "dsoip", .field = PERF_OUTPUT_DSOIP}, {.str = "addr", .field = PERF_OUTPUT_ADDR}, {.str = "symoff", .field = PERF_OUTPUT_SYMOFFSET}, {.str = "srcline", .field = PERF_OUTPUT_SRCLINE},@@ -574,6 +576,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 (DSOIP )) + output[type].print_ip_opts |=EVSEL__PRINT_DSOIP ; +if (PRINT_FIELD (SYMOFFSET )) output[type].print_ip_opts |=EVSEL__PRINT_SYMOFFSET ;tools/perf/util/evsel_fprintf.c +1
-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_dsoip = print_opts &EVSEL__PRINT_DSOIP ;int print_symoffset = print_opts &EVSEL__PRINT_SYMOFFSET ;int print_oneline = print_opts &EVSEL__PRINT_ONELINE ;int print_srcline = print_opts &EVSEL__PRINT_SRCLINE ;@@ -133,7 +134,7 @@ int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment,Quoted 9 lines
tools/perf/util/evsel_fprintf.c int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment, · line 137
Quoted 5 lines
tools/perf/util/evsel_fprintf.c +1
-1while (1 ) {struct symbol *sym;struct map *map; -u64 addr =0 ; +u64 dso_ip =0 ;Renaming 'addr' just makes the patch more complicated. Just leave it as 'addr'
Quoted 2 lines
Just to make the variable name reflect its real content. It's not a memory address, right?
We already use addr e.g. in struct addr_location.
If you want to rename it, make it a separate patch.
Quoted 32 lines
Quoted 6 lines
Quoted 6 lines
tools/perf/util/evsel_fprintf.c +0
-0node =callchain_cursor_current (cursor);if (!node)@@ -141,6 +142,8 @@ int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment,Quoted 7 lines
tools/perf/util/evsel_fprintf.c int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment, · line 146
Quoted 4 lines
tools/perf/util/evsel_fprintf.c +2
-0sym = node->ms.sym; map = node->ms.map; +if (map) + dso_ip = map->map_ip (map, node->ip);There does not seem to be any reason to move these lines of code.
yes. I cound undo this. (just a clean up to not place addr calculation betwwen printings)
Quoted 7 lines
Quoted 7 lines
tools/perf/util/evsel_fprintf.c +0
-0if (sym && sym->ignore && print_skip_ignored) goto next;@@ -150,20 +153,12 @@ int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment,if (print_arrow && !first) printed +=fprintf (fp," <-" );Quoted 9 lines
tools/perf/util/evsel_fprintf.c int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment, · line 158
Quoted 6 lines
tools/perf/util/evsel_fprintf.c +0
-6-if (map) - addr = map->map_ip (map, node->ip); - -if (print_ip) { -/* Show binary offset for userspace addr */ -if (map && !map->dso->kernel)I would have expected to keep existing functionality unchanged i.e.
Quoted 1 line
But the goal is to make printed address consistent. See below difference.
Then make it a separate patch.
Quoted 47 lines
$ perf script ... ls 1341034 2739463.008343: 2162417 cycles: ffffffff992a917d [unknown] ([unknown]) ffffffff992a9b0a [unknown] ([unknown]) ffffffff992efa3d [unknown] ([unknown]) ffffffff992f10c9 [unknown] ([unknown]) ffffffff992f47cc [unknown] ([unknown]) ffffffff992f4ab8 [unknown] ([unknown]) ffffffff9909daa2 [unknown] ([unknown]) 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)$ 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 ipQuoted 25 lines
(quoted diff) +1
-1- if (map && !map->dso->kernel) + if (!print_dsoip && map && !map->dso->kernel)Quoted 16 lines
tools/perf/util/evsel_fprintf.c +3
-5- 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," " ); - node_al.addr = addr; + node_al.addr = dso_ip; node_al.map = map;if (print_symoffset) {tools/perf/util/evsel_fprintf.c int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment, · line 177
Quoted 4 lines
tools/perf/util/evsel_fprintf.c +1
-0@@ -179,11 +174,13 @@ 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_dsoip)Better to avoid '[unknown]+0x0' i.e.
Quoted 4 lines
Quoted 2 lines
if (print_dsoip && map && map->dso)This is also to keep output consistent which is frendly for parsers (FlameGraph generator for example).
And yet you want to change the existing output even when the new field is not requested. That is also unfriendly.
The default perf script output is human readable. Programs should use the Python scripting interface (or the dlfilter interface) to get data, not scrape the human readable output which is, after all, not an API.
Besides we don't do that (unknown+0x0) for unknown symbols, so why do it for unknown offsets.
Quoted 63 lines
Quoted 27 lines
Quoted 20 lines
tools/perf/util/evsel_fprintf.c +3
-1+ printed +=fprintf (fp,"+0x%lx" , (map && map->dso) ? dso_ip :0 ); printed +=fprintf (fp,")" ); }if (print_srcline) - printed +=map__fprintf_srcline (map, addr,"\n " , fp); + printed +=map__fprintf_srcline (map, dso_ip,"\n " , fp);if (sym && sym->inlined) printed +=fprintf (fp," (inlined)" );@@ -214,6 +211,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_dsoip = print_opts &EVSEL__PRINT_DSOIP ;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 ;tools/perf/util/evsel_fprintf.c int sample__fprintf_sym(struct perf_sample *sample, struct addr_location *al, · line 243
Quoted 4 lines
tools/perf/util/evsel_fprintf.c +1
-0@@ -242,6 +240,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_dsoip)Better to avoid '[unknown]+0x0' i.e.
Quoted 3 lines
if (print_dsoip && al->map && al->map->dso)Ditto.
Quoted 30 lines
Quoted 28 lines
tools/perf/util/evsel_fprintf.c +1
-0+ printed +=fprintf (fp,"+0x%lx" , (al->map && al->map->dso) ? al->addr :0 ); printed +=fprintf (fp,")" ); }tools/perf/util/evsel_fprintf.h +7
-6@@ -20,12 +20,13 @@ int evsel__fprintf(struct evsel *evsel, struct perf_attr_details *details, FILE#define EVSEL__PRINT_IP (1<<0)#define EVSEL__PRINT_SYM (1<<1)#define EVSEL__PRINT_DSO (1<<2) -#define EVSEL__PRINT_SYMOFFSET (1<<3) -#define EVSEL__PRINT_ONELINE (1<<4) -#define EVSEL__PRINT_SRCLINE (1<<5) -#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_DSOIP (1<<3) +#define EVSEL__PRINT_SYMOFFSET (1<<4) +#define EVSEL__PRINT_ONELINE (1<<5) +#define EVSEL__PRINT_SRCLINE (1<<6) +#define EVSEL__PRINT_UNKNOWN_AS_ADDR (1<<7) +#define EVSEL__PRINT_CALLCHAIN_ARROW (1<<8) +#define EVSEL__PRINT_SKIP_IGNORED (1<<9)struct addr_location ;struct perf_event_attr ;
Quoted 129 lines · Adrian Hunter
Quoted 128 lines · Changbin Du
Quoted 5 lines · Adrian Hunter
Quoted 4 lines · Changbin Du
The goal of this change is to achieve consistent output for address. Before this, the raw ip is printed for non-callchain and binary offset for callchain. Mostly what we expect is the raw ip.
Quoted 7 lines
Quoted 3 lines
This patch does two changes:
- Always print raw ip for symbols.
- Add a new 'dsoip' field if we really need the binary offset, and theIP stands for instruction pointer, which is always a memory address, so 'dsoip' does not seem like a good name. What about '
dso_offset'?This name is inherited from the comments of
map::map_ip. Actually now we have three terms: dos ip, binary offset and dso offset. I also prefer to 'dso_offset'.Quoted 111 lines
Quoted 102 lines
offset is appended to dso name.
Default output now:
$ perf script perf-exec 171459 5380927.621499: 1 cycles: ffffffff8c66e1b8 [unknown] ([unknown]) perf-exec 171459 5380927.621524: 1 cycles: ffffffff8c66e1b8 [unknown] ([unknown]) perf-exec 171459 5380927.621527: 2 cycles: ffffffff8c66e1b8 [unknown] ([unknown]) perf-exec 171459 5380927.621530: 17 cycles: ffffffff8c66e1b8 [unknown] ([unknown]) perf-exec 171459 5380927.621533: 194 cycles: ffffffff8c66e1bf [unknown] ([unknown]) perf-exec 171459 5380927.621536: 2153 cycles: ffffffff8c6375fe [unknown] ([unknown]) perf-exec 171459 5380927.621540: 23135 cycles: ffffffff8d001ac4 [unknown] ([unknown]) perf-exec 171459 5380927.621555: 224703 cycles: ffffffff8c7a5153 [unknown] ([unknown]) ls 171459 5380927.621686: 587397 cycles: ffffffff8c7c43de [unknown] ([unknown]) ls 171459 5380927.622016: 653693 cycles: 7fe1e47278c7 _dl_map_object_deps+0x307 (/lib/x86_64-linux-gnu/ld-2.27.so) ls 171459 5380927.622382: 633896 cycles: 7fe1e41bd0d0 __wmemchr_ifunc+0x0 (/lib/x86_64-linux-gnu/libc-2.27.so) ls 171459 5380927.622737: 608856 cycles: 7fe1e4194594 _int_malloc+0x264 (/lib/x86_64-linux-gnu/libc-2.27.so) ls 171459 5380927.623078: 586376 cycles: 55ff5293d27c [unknown] (/bin/ls) ls 171459 5380927.623405: 566812 cycles: 55ff5293b202 [unknown] (/bin/ls) ls 171459 5380927.623723: 549960 cycles: ffffffff8c82b138 [unknown] ([unknown])Display 'dsoip' field:
$ perf script -F +dsoip perf-exec 171459 5380927.621499: 1 cycles: ffffffff8c66e1b8 [unknown] ([unknown]+0x0) perf-exec 171459 5380927.621524: 1 cycles: ffffffff8c66e1b8 [unknown] ([unknown]+0x0) perf-exec 171459 5380927.621527: 2 cycles: ffffffff8c66e1b8 [unknown] ([unknown]+0x0) perf-exec 171459 5380927.621530: 17 cycles: ffffffff8c66e1b8 [unknown] ([unknown]+0x0) perf-exec 171459 5380927.621533: 194 cycles: ffffffff8c66e1bf [unknown] ([unknown]+0x0) perf-exec 171459 5380927.621536: 2153 cycles: ffffffff8c6375fe [unknown] ([unknown]+0x0) perf-exec 171459 5380927.621540: 23135 cycles: ffffffff8d001ac4 [unknown] ([unknown]+0x0) perf-exec 171459 5380927.621555: 224703 cycles: ffffffff8c7a5153 [unknown] ([unknown]+0x0) ls 171459 5380927.621686: 587397 cycles: ffffffff8c7c43de [unknown] ([unknown]+0x0) ls 171459 5380927.622016: 653693 cycles: 7fe1e47278c7 _dl_map_object_deps+0x307 (/lib/x86_64-linux-gnu/ld-2.27.so+0xe8c7) ls 171459 5380927.622382: 633896 cycles: 7fe1e41bd0d0 __wmemchr_ifunc+0x0 (/lib/x86_64-linux-gnu/libc-2.27.so+0xbd0d0) ls 171459 5380927.622737: 608856 cycles: 7fe1e4194594 _int_malloc+0x264 (/lib/x86_64-linux-gnu/libc-2.27.so+0x94594) ls 171459 5380927.623078: 586376 cycles: 55ff5293d27c [unknown] (/bin/ls+0x1227c) ls 171459 5380927.623405: 566812 cycles: 55ff5293b202 [unknown] (/bin/ls+0x10202) ls 171459 5380927.623723: 549960 cycles: ffffffff8c82b138 [unknown] ([unknown]+0x0)Signed-off-by Changbin Du <[email protected]>--- tools/perf/Documentation/perf-script.txt | 2 +- tools/perf/builtin-script.c | 5 +++++ tools/perf/util/evsel_fprintf.c | 26 ++++++++++++------------ tools/perf/util/evsel_fprintf.h | 13 ++++++------ 4 files changed, 26 insertions(+), 20 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, dsoip, 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@@ -133,6 +133,7 @@ enum perf_output_field {PERF_OUTPUT_VCPU =1ULL <<38 ,PERF_OUTPUT_CGROUP =1ULL <<39 ,PERF_OUTPUT_RETIRE_LAT =1ULL <<40 , + PERF_OUTPUT_DSOIP = 1ULL << 41, }; struct perf_script {@@ -174,6 +175,7 @@ struct output_option { {.str = "ip", .field = PERF_OUTPUT_IP}, {.str = "sym", .field = PERF_OUTPUT_SYM}, {.str = "dso", .field = PERF_OUTPUT_DSO}, + {.str = "dsoip", .field = PERF_OUTPUT_DSOIP}, {.str = "addr", .field = PERF_OUTPUT_ADDR}, {.str = "symoff", .field = PERF_OUTPUT_SYMOFFSET}, {.str = "srcline", .field = PERF_OUTPUT_SRCLINE},@@ -574,6 +576,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 (DSOIP )) + output[type].print_ip_opts |=EVSEL__PRINT_DSOIP ; +if (PRINT_FIELD (SYMOFFSET )) output[type].print_ip_opts |=EVSEL__PRINT_SYMOFFSET ;tools/perf/util/evsel_fprintf.c +1
-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_dsoip = print_opts &EVSEL__PRINT_DSOIP ;int print_symoffset = print_opts &EVSEL__PRINT_SYMOFFSET ;int print_oneline = print_opts &EVSEL__PRINT_ONELINE ;int print_srcline = print_opts &EVSEL__PRINT_SRCLINE ;tools/perf/util/evsel_fprintf.c int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment, · line 137
Quoted 5 lines
tools/perf/util/evsel_fprintf.c +1
-1@@ -133,7 +134,7 @@ int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment,while (1 ) {struct symbol *sym;struct map *map; -u64 addr =0 ; +u64 dso_ip =0 ;Renaming 'addr' just makes the patch more complicated. Just leave it as 'addr'
Quoted 7 lines
Quoted 2 lines
Just to make the variable name reflect its real content. It's not a memory address, right?
We already use addr e.g. in struct
addr_location.If you want to rename it, make it a separate patch.
okay.
Quoted 32 lines
Quoted 32 lines
Quoted 6 lines
Quoted 6 lines
tools/perf/util/evsel_fprintf.c +0
-0node =callchain_cursor_current (cursor);if (!node)@@ -141,6 +142,8 @@ int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment,Quoted 7 lines
tools/perf/util/evsel_fprintf.c int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment, · line 146
Quoted 4 lines
tools/perf/util/evsel_fprintf.c +2
-0sym = node->ms.sym; map = node->ms.map; +if (map) + dso_ip = map->map_ip (map, node->ip);There does not seem to be any reason to move these lines of code.
yes. I cound undo this. (just a clean up to not place addr calculation betwwen printings)
Quoted 16 lines
tools/perf/util/evsel_fprintf.c int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment, · line 158
Quoted 13 lines
tools/perf/util/evsel_fprintf.c +0
-6if (sym && sym->ignore && print_skip_ignored) goto next;@@ -150,20 +153,12 @@ int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment,if (print_arrow && !first) printed +=fprintf (fp," <-" ); -if (map) - addr = map->map_ip (map, node->ip); - -if (print_ip) { -/* Show binary offset for userspace addr */ -if (map && !map->dso->kernel)I would have expected to keep existing functionality unchanged i.e.
Quoted 4 lines
Quoted 1 line
But the goal is to make printed address consistent. See below difference.
Then make it a separate patch.
okay. this should be done in muti-patches.
Quoted 47 lines
Quoted 47 lines
$ perf script ... ls 1341034 2739463.008343: 2162417 cycles: ffffffff992a917d [unknown] ([unknown]) ffffffff992a9b0a [unknown] ([unknown]) ffffffff992efa3d [unknown] ([unknown]) ffffffff992f10c9 [unknown] ([unknown]) ffffffff992f47cc [unknown] ([unknown]) ffffffff992f4ab8 [unknown] ([unknown]) ffffffff9909daa2 [unknown] ([unknown]) 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)$ 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 ipQuoted 25 lines
(quoted diff) +1
-1- if (map && !map->dso->kernel) + if (!print_dsoip && map && !map->dso->kernel)Quoted 16 lines
tools/perf/util/evsel_fprintf.c +3
-5- 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," " ); - node_al.addr = addr; + node_al.addr = dso_ip; node_al.map = map;if (print_symoffset) {tools/perf/util/evsel_fprintf.c int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment, · line 177
Quoted 4 lines
tools/perf/util/evsel_fprintf.c +1
-0@@ -179,11 +174,13 @@ 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_dsoip)Better to avoid '[unknown]+0x0' i.e.
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
if (print_dsoip && map && map->dso)This is also to keep output consistent which is frendly for parsers (FlameGraph generator for example).
And yet you want to change the existing output even when the new field is not requested. That is also unfriendly.
I'd think consistency is very important. It confuses people without reading the code. So let's do them in seprated patches: one for consistency, another to add new dso_offset field.
Quoted 7 lines
The default perf script output is human readable. Programs should use the Python scripting interface (or the dlfilter interface) to get data, not scrape the human readable output which is, after all, not an API.
Besides we don't do that (
unknown+0x0) for unknown symbols, so why do it for unknown offsets.
Both (unknown) and (unknown+0x0) are good for me.
Quoted 65 lines
Quoted 64 lines
Quoted 28 lines
Quoted 21 lines
tools/perf/util/evsel_fprintf.c +3
-1+ printed +=fprintf (fp,"+0x%lx" , (map && map->dso) ? dso_ip :0 ); printed +=fprintf (fp,")" ); }if (print_srcline) - printed +=map__fprintf_srcline (map, addr,"\n " , fp); + printed +=map__fprintf_srcline (map, dso_ip,"\n " , fp);if (sym && sym->inlined) printed +=fprintf (fp," (inlined)" );@@ -214,6 +211,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_dsoip = print_opts &EVSEL__PRINT_DSOIP ;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 ;tools/perf/util/evsel_fprintf.c int sample__fprintf_sym(struct perf_sample *sample, struct addr_location *al, · line 243
Quoted 4 lines
tools/perf/util/evsel_fprintf.c +1
-0@@ -242,6 +240,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_dsoip)Better to avoid '[unknown]+0x0' i.e.
Quoted 3 lines
if (print_dsoip && al->map && al->map->dso)Ditto.
Quoted 30 lines
Quoted 28 lines
tools/perf/util/evsel_fprintf.c +1
-0+ printed +=fprintf (fp,"+0x%lx" , (al->map && al->map->dso) ? al->addr :0 ); printed +=fprintf (fp,")" ); }tools/perf/util/evsel_fprintf.h +7
-6@@ -20,12 +20,13 @@ int evsel__fprintf(struct evsel *evsel, struct perf_attr_details *details, FILE#define EVSEL__PRINT_IP (1<<0)#define EVSEL__PRINT_SYM (1<<1)#define EVSEL__PRINT_DSO (1<<2) -#define EVSEL__PRINT_SYMOFFSET (1<<3) -#define EVSEL__PRINT_ONELINE (1<<4) -#define EVSEL__PRINT_SRCLINE (1<<5) -#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_DSOIP (1<<3) +#define EVSEL__PRINT_SYMOFFSET (1<<4) +#define EVSEL__PRINT_ONELINE (1<<5) +#define EVSEL__PRINT_SRCLINE (1<<6) +#define EVSEL__PRINT_UNKNOWN_AS_ADDR (1<<7) +#define EVSEL__PRINT_CALLCHAIN_ARROW (1<<8) +#define EVSEL__PRINT_SKIP_IGNORED (1<<9)struct addr_location ;struct perf_event_attr ;
Signature · 2 lines
Cheers, Changbin Du