perf script: Add an option to print the source line number
Adrian Hunter
reviewerv2 cover perf script: Add an option to print the source line number
Hi
Here is perf script srcline printing.
Changes in V2:
Also print scrline for callchains
Adrian Hunter (3):
perf script: Fix symoff printing in callchains perf script: Add an option to print the source line number perf script: Improve srcline display for BTS
tools/perf/Documentation/perf-script.txt | 2 +- tools/perf/builtin-script.c | 30 +++++++++++++++++++++++++----- tools/perf/util/map.c | 17 +++++++++++++++++ tools/perf/util/map.h | 2 ++ tools/perf/util/session.c | 15 ++++++++++++++- tools/perf/util/session.h | 1 + 6 files changed, 60 insertions(+), 7 deletions(-)
Regards
Adrian
Adrian Hunter
reviewerPATCH v2 1/3 perf script: Fix symoff printing in callchains
The address being used to calculate the offset was the memory address but the address needed is the address mapped to the dso. i.e. the 'addr' member of 'struct addr_location'
--- tools/perf/util/session.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
tools/perf/util/session.c +6 -1
@@ -1515,6 +1515,8 @@ void perf_evsel__print_ip(struct perf_evsel *evsel, struct perf_sample *sample, node_al = *al;while (stack_depth) { +u64 addr =0 ; + node =callchain_cursor_current (&callchain_cursor);if (!node)break ;
@@ -1525,10 +1527,13 @@ void perf_evsel__print_ip(struct perf_evsel *evsel, struct perf_sample *sample,if (print_ip)printf ("%c%16" PRIx64, s, node->ip); +if (node->map) + addr = node->map->map_ip (node->map, node->ip); +if (print_sym) {printf (" " );if (print_symoffset) { - node_al.addr = node->ip; + node_al.addr = addr; node_al.map = node->map;symbol__fprintf_symname_offs (node->sym, &node_al, stdout); }else
Signature · 1 line
1.7.11.7
Re: [PATCH V2 1/3] perf script: Fix symoff printing in callchains
Quoted 10 lines · Adrian Hunter
The address being used to calculate the offset was the memory address but the address needed is the address mapped to the dso. i.e. the 'addr' member of 'struct
addr_location'Signed-off-by Adrian Hunter <[email protected]>--- tools/perf/util/session.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf script: Fix symoff printing in callchains
In reply to Adrian Hunterperf script: Fix symoff printing in callchains
Commit-ID: a4eb24a49566db77ee999b46603f602a0302f481 Gitweb: http://git.kernel.org/tip/a4eb24a49566db77ee999b46603f602a0302f481 Author: Adrian Hunter <[email protected]> AuthorDate: Fri, 6 Dec 2013 09:42:56 +0200 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 9 Dec 2013 11:13:50 -0300
perf script: Fix symoff printing in callchains
The address being used to calculate the offset was the memory address but the address needed is the address mapped to the dso. i.e. the 'addr' member of 'struct addr_location'
--- tools/perf/util/session.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
tools/perf/util/session.c +6 -1
@@ -1515,6 +1515,8 @@ void perf_evsel__print_ip(struct perf_evsel *evsel, struct perf_sample *sample, node_al = *al;while (stack_depth) { +u64 addr =0 ; + node =callchain_cursor_current (&callchain_cursor);if (!node)break ;
@@ -1525,10 +1527,13 @@ void perf_evsel__print_ip(struct perf_evsel *evsel, struct perf_sample *sample,if (print_ip)printf ("%c%16" PRIx64, s, node->ip); +if (node->map) + addr = node->map->map_ip (node->map, node->ip); +if (print_sym) {printf (" " );if (print_symoffset) { - node_al.addr = node->ip; + node_al.addr = addr; node_al.map = node->map;symbol__fprintf_symname_offs (node->sym, &node_al, stdout); }else
Adrian Hunter
reviewerPATCH v2 2/3 perf script: Add an option to print the source line number
In reply to Adrian HunterAdd field 'srcline' that displays the source file name and line number associated with the sample ip. The information displayed is the same as from addr2line.
--- tools/perf/Documentation/perf-script.txt | 2 +- tools/perf/builtin-script.c | 10 ++++++++++ tools/perf/util/map.c | 17 +++++++++++++++++ tools/perf/util/map.h | 2 ++ tools/perf/util/session.c | 8 ++++++++ tools/perf/util/session.h | 1 + 6 files changed, 39 insertions(+), 1 deletion(-)
tools/perf/Documentation/perf-script.txt +1 -1
@@ -115,7 +115,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, addr, symoff, srcline. Field list can be prepended with the type, trace, sw or hw, to indicate to which event type the field list applies. e.g., -f sw:comm,tid,time,ip,sym and -f trace:time,cpu,trace
tools/perf/builtin-script.c +10 -0
@@ -43,6 +43,7 @@ enum perf_output_field {PERF_OUTPUT_DSO =1U <<9 ,PERF_OUTPUT_ADDR =1U <<10 ,PERF_OUTPUT_SYMOFFSET =1U <<11 , + PERF_OUTPUT_SRCLINE = 1U << 12, }; struct output_option {
@@ -61,6 +62,7 @@ struct output_option { {.str = "dso", .field = PERF_OUTPUT_DSO}, {.str = "addr", .field = PERF_OUTPUT_ADDR}, {.str = "symoff", .field = PERF_OUTPUT_SYMOFFSET}, + {.str = "srcline", .field = PERF_OUTPUT_SRCLINE}, };/* default set to maintain compatibility with current format */
@@ -210,6 +212,11 @@ static int perf_evsel__check_attr(struct perf_evsel *evsel, "to DSO.\n");return -EINVAL ; } +if (PRINT_FIELD (SRCLINE ) && !PRINT_FIELD (IP )) { +pr_err ("Display of source line number requested but sample IP is not\n" +"selected. Hence, no address to lookup the source line number.\n" ); +return -EINVAL ; + }if ((PRINT_FIELD (PID ) ||PRINT_FIELD (TID )) && perf_evsel__check_stype(evsel, PERF_SAMPLE_TID, "TID",
@@ -245,6 +252,9 @@ static void set_print_ip_opts(struct perf_event_attr *attr)if (PRINT_FIELD (SYMOFFSET )) output[type].print_ip_opts |=PRINT_IP_OPT_SYMOFFSET ; + +if (PRINT_FIELD (SRCLINE )) + output[type].print_ip_opts |=PRINT_IP_OPT_SRCLINE ; }/*
tools/perf/util/map.c +17 -0
@@ -11,6 +11,7 @@#include "strlist.h" #include "vdso.h" #include "build-id.h" +#include "util.h" #include <linux/string.h> const char *map_type__name[MAP__NR_TYPES ] = {
@@ -252,6 +253,22 @@ size_t map__fprintf_dsoname(struct map *map, FILE *fp)return fprintf (fp,"%s" , dsoname); } +int map__fprintf_srcline (struct map *map,u64 addr,const char *prefix, +FILE *fp) +{ +char *srcline; +int ret =0 ; + +if (map && map->dso) { + srcline =get_srcline (map->dso, +map__rip_2objdump (map, addr)); +if (srcline !=SRCLINE_UNKNOWN ) + ret =fprintf (fp,"%s%s" , prefix, srcline); +free_srcline (srcline); + } +return ret; +} +/** * map__rip_2objdump - convert symbol start address to objdump address. * @map: memory map
tools/perf/util/map.h +2 -0
@@ -103,6 +103,8 @@ struct map *map__clone(struct map *map);int map__overlap (struct map *l,struct map *r);size_t map__fprintf (struct map *map,FILE *fp);size_t map__fprintf_dsoname (struct map *map,FILE *fp); +int map__fprintf_srcline (struct map *map,u64 addr,const char *prefix, +FILE *fp);int map__load (struct map *map,symbol_filter_t filter); struct symbol *map__find_symbol(struct map *map,
tools/perf/util/session.c +8 -0
@@ -1497,6 +1497,7 @@ void perf_evsel__print_ip(struct perf_evsel *evsel, struct perf_sample *sample,int print_dso = print_opts &PRINT_IP_OPT_DSO ;int print_symoffset = print_opts &PRINT_IP_OPT_SYMOFFSET ;int print_oneline = print_opts &PRINT_IP_OPT_ONELINE ; +int print_srcline = print_opts &PRINT_IP_OPT_SRCLINE ;char s = print_oneline ?' ' :'\t' ;if (symbol_conf.use_callchain && sample->callchain) {
@@ -1546,6 +1547,10 @@ void perf_evsel__print_ip(struct perf_evsel *evsel, struct perf_sample *sample,printf (")" ); } +if (print_srcline) +map__fprintf_srcline (node->map, addr,"\n " , + stdout); +if (!print_oneline)printf ("\n" );
@@ -1575,6 +1580,9 @@ next:map__fprintf_dsoname (al->map, stdout);printf (")" ); } + +if (print_srcline) +map__fprintf_srcline (al->map, al->addr,"\n " , stdout); } }
tools/perf/util/session.h +1 -0
@@ -45,6 +45,7 @@ struct perf_session {#define PRINT_IP_OPT_DSO (1<<2)#define PRINT_IP_OPT_SYMOFFSET (1<<3)#define PRINT_IP_OPT_ONELINE (1<<4) +#define PRINT_IP_OPT_SRCLINE (1<<5)struct perf_tool ;
Signature · 1 line
1.7.11.7
Quoted 3 lines · Adrian Hunter
Add field 'srcline' that displays the source file name and line number associated with the sample ip. The information displayed is the same as from addr2line.
example output?
Quoted 138 lines
Signed-off-by Adrian Hunter <[email protected]>--- tools/perf/Documentation/perf-script.txt | 2 +- tools/perf/builtin-script.c | 10 ++++++++++ tools/perf/util/map.c | 17 +++++++++++++++++ tools/perf/util/map.h | 2 ++ tools/perf/util/session.c | 8 ++++++++ tools/perf/util/session.h | 1 + 6 files changed, 39 insertions(+), 1 deletion(-)tools/perf/Documentation/perf-script.txt +1
-1@@ -115,7 +115,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, addr, symoff, srcline. Field list can be prepended with the type, trace, sw or hw, to indicate to which event type the field list applies. e.g., -f sw:comm,tid,time,ip,sym and -f trace:time,cpu,tracetools/perf/builtin-script.c +10
-0@@ -43,6 +43,7 @@ enum perf_output_field {PERF_OUTPUT_DSO =1U <<9 ,PERF_OUTPUT_ADDR =1U <<10 ,PERF_OUTPUT_SYMOFFSET =1U <<11 , + PERF_OUTPUT_SRCLINE = 1U << 12, }; struct output_option {@@ -61,6 +62,7 @@ struct output_option { {.str = "dso", .field = PERF_OUTPUT_DSO}, {.str = "addr", .field = PERF_OUTPUT_ADDR}, {.str = "symoff", .field = PERF_OUTPUT_SYMOFFSET}, + {.str = "srcline", .field = PERF_OUTPUT_SRCLINE}, };/* default set to maintain compatibility with current format */ @@ -210,6 +212,11 @@ static int perf_evsel__check_attr(struct perf_evsel *evsel, "to DSO.\n");return -EINVAL ; } +if (PRINT_FIELD (SRCLINE ) && !PRINT_FIELD (IP )) { +pr_err ("Display of source line number requested but sample IP is not\n" +"selected. Hence, no address to lookup the source line number.\n" ); +return -EINVAL ; + }if ((PRINT_FIELD (PID ) ||PRINT_FIELD (TID )) && perf_evsel__check_stype(evsel, PERF_SAMPLE_TID, "TID",@@ -245,6 +252,9 @@ static void set_print_ip_opts(struct perf_event_attr *attr)if (PRINT_FIELD (SYMOFFSET )) output[type].print_ip_opts |=PRINT_IP_OPT_SYMOFFSET ; + +if (PRINT_FIELD (SRCLINE )) + output[type].print_ip_opts |=PRINT_IP_OPT_SRCLINE ; }/* tools/perf/util/map.c +17
-0@@ -11,6 +11,7 @@#include "strlist.h" #include "vdso.h" #include "build-id.h" +#include "util.h" #include <linux/string.h> const char *map_type__name[MAP__NR_TYPES ] = {@@ -252,6 +253,22 @@ size_t map__fprintf_dsoname(struct map *map, FILE *fp)return fprintf (fp,"%s" , dsoname); } +int map__fprintf_srcline (struct map *map,u64 addr,const char *prefix, +FILE *fp) +{ +char *srcline; +int ret =0 ; + +if (map && map->dso) { + srcline =get_srcline (map->dso, +map__rip_2objdump (map, addr)); +if (srcline !=SRCLINE_UNKNOWN ) + ret =fprintf (fp,"%s%s" , prefix, srcline); +free_srcline (srcline); + } +return ret; +} +/** * map__rip_2objdump - convert symbol start address to objdump address. * @map: memory map tools/perf/util/map.h +2
-0@@ -103,6 +103,8 @@ struct map *map__clone(struct map *map);int map__overlap (struct map *l,struct map *r);size_t map__fprintf (struct map *map,FILE *fp);size_t map__fprintf_dsoname (struct map *map,FILE *fp); +int map__fprintf_srcline (struct map *map,u64 addr,const char *prefix, +FILE *fp);int map__load (struct map *map,symbol_filter_t filter); struct symbol *map__find_symbol(struct map *map,tools/perf/util/session.c +5
-0@@ -1497,6 +1497,7 @@ void perf_evsel__print_ip(struct perf_evsel *evsel, struct perf_sample *sample,int print_dso = print_opts &PRINT_IP_OPT_DSO ;int print_symoffset = print_opts &PRINT_IP_OPT_SYMOFFSET ;int print_oneline = print_opts &PRINT_IP_OPT_ONELINE ; +int print_srcline = print_opts &PRINT_IP_OPT_SRCLINE ;char s = print_oneline ?' ' :'\t' ;if (symbol_conf.use_callchain && sample->callchain) {@@ -1546,6 +1547,10 @@ void perf_evsel__print_ip(struct perf_evsel *evsel, struct perf_sample *sample,printf (")" ); } +if (print_srcline) +map__fprintf_srcline (node->map, addr,"\n " , + stdout); +if (!print_oneline)printf ("\n" );
tools/perf/util/session.c next: · line 1587
Quoted 8 lines
tools/perf/util/session.c +3
-0@@ -1575,6 +1580,9 @@ next:map__fprintf_dsoname (al->map, stdout);printf (")" ); } + +if (print_srcline) +map__fprintf_srcline (al->map, al->addr,"\n " , stdout); } }
Why newline followed by space?
Otherwise, Acked-by: David Ahern <[email protected]>
Adrian Hunter
reviewerQuoted 6 lines · David Ahern
Quoted 3 lines · Adrian Hunter
Add field 'srcline' that displays the source file name and line number associated with the sample ip. The information displayed is the same as from addr2line.
example output?
grep 10701/10701 2497321.421013: ffffffff81043ffa native_write_msr_safe+0xa ([kernel.kallsyms])
/usr/src/debug/kernel-3.9.fc17/linux-3.9.10-100.fc17.x86_64/arch/x86/include/asm/msr.h:95
grep 10701/10701 2497321.421984: ffffffff8165b6b3 _raw_spin_lock+0x13 ([kernel.kallsyms])
/usr/src/debug/kernel-3.9.fc17/linux-3.9.10-100.fc17.x86_64/arch/x86/include/asm/spinlock.h:54
grep 10701/10701 2497321.421990: ffffffff810b64b3 tick_sched_timer+0x53 ([kernel.kallsyms])
/usr/src/debug/kernel-3.9.fc17/linux-3.9.10-100.fc17.x86_64/kernel/time/tick-sched.c:840
grep 10701/10701 2497321.421992: ffffffff8106f63f run_timer_softirq+0x2f ([kernel.kallsyms]) /usr/src/debug/kernel-3.9.fc17/linux-3.9.10-100.fc17.x86_64/kernel/timer.c:1372
Quoted 146 lines
Quoted 146 lines
Signed-off-by Adrian Hunter <[email protected]>--- tools/perf/Documentation/perf-script.txt | 2 +- tools/perf/builtin-script.c | 10 ++++++++++ tools/perf/util/map.c | 17 +++++++++++++++++ tools/perf/util/map.h | 2 ++ tools/perf/util/session.c | 8 ++++++++ tools/perf/util/session.h | 1 + 6 files changed, 39 insertions(+), 1 deletion(-)tools/perf/Documentation/perf-script.txt +1
-1@@ -115,7 +115,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, addr,symoff, srcline.
Field list can be prepended with the type, trace, sw or hw, to indicate to which event type the field list applies. e.g., -f sw:comm,tid,time,ip,sym and -f trace:time,cpu,tracetools/perf/builtin-script.c +4
-0@@ -43,6 +43,7 @@ enum perf_output_field {PERF_OUTPUT_DSO =1U <<9 ,PERF_OUTPUT_ADDR =1U <<10 ,PERF_OUTPUT_SYMOFFSET =1U <<11 , + PERF_OUTPUT_SRCLINE = 1U << 12, }; struct output_option {@@ -61,6 +62,7 @@ struct output_option { {.str = "dso", .field = PERF_OUTPUT_DSO}, {.str = "addr", .field = PERF_OUTPUT_ADDR}, {.str = "symoff", .field = PERF_OUTPUT_SYMOFFSET}, + {.str = "srcline", .field = PERF_OUTPUT_SRCLINE}, };/* default set to maintain compatibility with current format */ @@ -210,6 +212,11 @@ static int perf_evsel__check_attr(struct perf_evsel *evsel, "to DSO.\n");return -EINVAL ; } +if (PRINT_FIELD (SRCLINE ) && !PRINT_FIELD (IP )) { + pr_err("Display of source line number requested but sample IP isnot\n"
+ "selected. Hence, no address to lookup the source line
number.\n");tools/perf/builtin-script.c +5
-0+return -EINVAL ; + }if ((PRINT_FIELD (PID ) ||PRINT_FIELD (TID )) && perf_evsel__check_stype(evsel, PERF_SAMPLE_TID, "TID",@@ -245,6 +252,9 @@ static void set_print_ip_opts(struct perf_event_attr *attr)if (PRINT_FIELD (SYMOFFSET )) output[type].print_ip_opts |=PRINT_IP_OPT_SYMOFFSET ; + +if (PRINT_FIELD (SRCLINE )) + output[type].print_ip_opts |=PRINT_IP_OPT_SRCLINE ; }/*
tools/perf/util/map.c +17
-0@@ -11,6 +11,7 @@#include "strlist.h" #include "vdso.h" #include "build-id.h" +#include "util.h" #include <linux/string.h> const char *map_type__name[MAP__NR_TYPES ] = {@@ -252,6 +253,22 @@ size_t map__fprintf_dsoname(struct map *map, FILE *fp)return fprintf (fp,"%s" , dsoname); } +int map__fprintf_srcline (struct map *map,u64 addr,const char *prefix, +FILE *fp) +{ +char *srcline; +int ret =0 ; + +if (map && map->dso) { + srcline =get_srcline (map->dso, +map__rip_2objdump (map, addr)); +if (srcline !=SRCLINE_UNKNOWN ) + ret =fprintf (fp,"%s%s" , prefix, srcline); +free_srcline (srcline); + } +return ret; +} +/** * map__rip_2objdump - convert symbol start address to objdump address. * @map: memory map tools/perf/util/map.h +2
-0@@ -103,6 +103,8 @@ struct map *map__clone(struct map *map);int map__overlap (struct map *l,struct map *r);size_t map__fprintf (struct map *map,FILE *fp);size_t map__fprintf_dsoname (struct map *map,FILE *fp); +int map__fprintf_srcline (struct map *map,u64 addr,const char *prefix, +FILE *fp);int map__load (struct map *map,symbol_filter_t filter); struct symbol *map__find_symbol(struct map *map,tools/perf/util/session.c +1
-0@@ -1497,6 +1497,7 @@ void perf_evsel__print_ip(struct perf_evsel *evsel,struct perf_sample *sample, int print_dso = print_opts & PRINT_IP_OPT_DSO;int print_symoffset = print_opts &PRINT_IP_OPT_SYMOFFSET ;int print_oneline = print_opts &PRINT_IP_OPT_ONELINE ; +int print_srcline = print_opts &PRINT_IP_OPT_SRCLINE ;char s = print_oneline ?' ' :'\t' ;if (symbol_conf.use_callchain && sample->callchain) {tools/perf/util/session.c +4
-0@@ -1546,6 +1547,10 @@ void perf_evsel__print_ip(struct perf_evsel *evsel,struct perf_sample *sample, printf(")"); } +if (print_srcline) +map__fprintf_srcline (node->map, addr,"\n " , + stdout); +if (!print_oneline)printf ("\n" );
Quoted 11 lines
tools/perf/util/session.c next: · line 1587
Quoted 9 lines
tools/perf/util/session.c +3
-0@@ -1575,6 +1580,9 @@ next:map__fprintf_dsoname (al->map, stdout);printf (")" ); } + +if (print_srcline) +map__fprintf_srcline (al->map, al->addr,"\n " , stdout); } }Why newline followed by space?
It looked better that way to me.
Quoted 5 lines
Otherwise, Acked-by: David Ahern <[email protected]>
tip-bot for Adrian Hunter
merge botperf script: Add an option to print the source line number
Commit-ID: cc8fae1d81648e85587f5d18b4f93e0b771fb02d Gitweb: http://git.kernel.org/tip/cc8fae1d81648e85587f5d18b4f93e0b771fb02d Author: Adrian Hunter <[email protected]> AuthorDate: Fri, 6 Dec 2013 09:42:57 +0200 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 9 Dec 2013 14:47:15 -0300
perf script: Add an option to print the source line number
Add field 'srcline' that displays the source file name and line number associated with the sample ip. The information displayed is the same as from addr2line.
$ perf script -f comm,tid,pid,time,ip,sym,dso,symoff,srcline
grep 10701/10701 2497321.421013: ffffffff81043ffa native_write_msr_safe+0xa ([kernel.kallsyms])
/usr/src/debug/kernel-3.9.fc17/linux-3.9.10-100.fc17.x86_64/arch/x86/include/asm/msr.h:95
grep 10701/10701 2497321.421984: ffffffff8165b6b3 _raw_spin_lock+0x13 ([kernel.kallsyms])
/usr/src/debug/kernel-3.9.fc17/linux-3.9.10-100.fc17.x86_64/arch/x86/include/asm/spinlock.h:54
grep 10701/10701 2497321.421990: ffffffff810b64b3 tick_sched_timer+0x53 ([kernel.kallsyms])
/usr/src/debug/kernel-3.9.fc17/linux-3.9.10-100.fc17.x86_64/kernel/time/tick-sched.c:840
grep 10701/10701 2497321.421992: ffffffff8106f63f run_timer_softirq+0x2f ([kernel.kallsyms])
/usr/src/debug/kernel-3.9.fc17/linux-3.9.10-100.fc17.x86_64/kernel/timer.c:1372--- tools/perf/Documentation/perf-script.txt | 2 +- tools/perf/builtin-script.c | 10 ++++++++++ tools/perf/util/map.c | 17 +++++++++++++++++ tools/perf/util/map.h | 2 ++ tools/perf/util/session.c | 8 ++++++++ tools/perf/util/session.h | 1 + 6 files changed, 39 insertions(+), 1 deletion(-)
tools/perf/Documentation/perf-script.txt +1 -1
@@ -115,7 +115,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, addr, symoff, srcline. Field list can be prepended with the type, trace, sw or hw, to indicate to which event type the field list applies. e.g., -f sw:comm,tid,time,ip,sym and -f trace:time,cpu,trace
tools/perf/builtin-script.c +10 -0
@@ -43,6 +43,7 @@ enum perf_output_field {PERF_OUTPUT_DSO =1U <<9 ,PERF_OUTPUT_ADDR =1U <<10 ,PERF_OUTPUT_SYMOFFSET =1U <<11 , + PERF_OUTPUT_SRCLINE = 1U << 12, }; struct output_option {
@@ -61,6 +62,7 @@ struct output_option { {.str = "dso", .field = PERF_OUTPUT_DSO}, {.str = "addr", .field = PERF_OUTPUT_ADDR}, {.str = "symoff", .field = PERF_OUTPUT_SYMOFFSET}, + {.str = "srcline", .field = PERF_OUTPUT_SRCLINE}, };/* default set to maintain compatibility with current format */
@@ -210,6 +212,11 @@ static int perf_evsel__check_attr(struct perf_evsel *evsel, "to DSO.\n");return -EINVAL ; } +if (PRINT_FIELD (SRCLINE ) && !PRINT_FIELD (IP )) { +pr_err ("Display of source line number requested but sample IP is not\n" +"selected. Hence, no address to lookup the source line number.\n" ); +return -EINVAL ; + }if ((PRINT_FIELD (PID ) ||PRINT_FIELD (TID )) && perf_evsel__check_stype(evsel, PERF_SAMPLE_TID, "TID",
@@ -245,6 +252,9 @@ static void set_print_ip_opts(struct perf_event_attr *attr)if (PRINT_FIELD (SYMOFFSET )) output[type].print_ip_opts |=PRINT_IP_OPT_SYMOFFSET ; + +if (PRINT_FIELD (SRCLINE )) + output[type].print_ip_opts |=PRINT_IP_OPT_SRCLINE ; }/*
tools/perf/util/map.c +17 -0
@@ -11,6 +11,7 @@#include "strlist.h" #include "vdso.h" #include "build-id.h" +#include "util.h" #include <linux/string.h> const char *map_type__name[MAP__NR_TYPES ] = {
@@ -252,6 +253,22 @@ size_t map__fprintf_dsoname(struct map *map, FILE *fp)return fprintf (fp,"%s" , dsoname); } +int map__fprintf_srcline (struct map *map,u64 addr,const char *prefix, +FILE *fp) +{ +char *srcline; +int ret =0 ; + +if (map && map->dso) { + srcline =get_srcline (map->dso, +map__rip_2objdump (map, addr)); +if (srcline !=SRCLINE_UNKNOWN ) + ret =fprintf (fp,"%s%s" , prefix, srcline); +free_srcline (srcline); + } +return ret; +} +/** * map__rip_2objdump - convert symbol start address to objdump address. * @map: memory map
tools/perf/util/map.h +2 -0
@@ -103,6 +103,8 @@ struct map *map__clone(struct map *map);int map__overlap (struct map *l,struct map *r);size_t map__fprintf (struct map *map,FILE *fp);size_t map__fprintf_dsoname (struct map *map,FILE *fp); +int map__fprintf_srcline (struct map *map,u64 addr,const char *prefix, +FILE *fp);int map__load (struct map *map,symbol_filter_t filter); struct symbol *map__find_symbol(struct map *map,
tools/perf/util/session.c +8 -0
@@ -1497,6 +1497,7 @@ void perf_evsel__print_ip(struct perf_evsel *evsel, struct perf_sample *sample,int print_dso = print_opts &PRINT_IP_OPT_DSO ;int print_symoffset = print_opts &PRINT_IP_OPT_SYMOFFSET ;int print_oneline = print_opts &PRINT_IP_OPT_ONELINE ; +int print_srcline = print_opts &PRINT_IP_OPT_SRCLINE ;char s = print_oneline ?' ' :'\t' ;if (symbol_conf.use_callchain && sample->callchain) {
@@ -1546,6 +1547,10 @@ void perf_evsel__print_ip(struct perf_evsel *evsel, struct perf_sample *sample,printf (")" ); } +if (print_srcline) +map__fprintf_srcline (node->map, addr,"\n " , + stdout); +if (!print_oneline)printf ("\n" );
@@ -1575,6 +1580,9 @@ next:map__fprintf_dsoname (al->map, stdout);printf (")" ); } + +if (print_srcline) +map__fprintf_srcline (al->map, al->addr,"\n " , stdout); } }
tools/perf/util/session.h +1 -0
@@ -45,6 +45,7 @@ struct perf_session {#define PRINT_IP_OPT_DSO (1<<2)#define PRINT_IP_OPT_SYMOFFSET (1<<3)#define PRINT_IP_OPT_ONELINE (1<<4) +#define PRINT_IP_OPT_SRCLINE (1<<5)struct perf_tool ;
Adrian Hunter
reviewerPATCH v2 3/3 perf script: Improve srcline display for BTS
In reply to Adrian HunterChange the order of the output to put the srcline last. e.g. old format:
4028fc main+0x2c (/bin/ls)
/build/buildd/coreutils-8.20/src/ls.c:1269 => 40d8a0 set_program_name+0x0 (/bin/ls)
new format:
4028fc main+0x2c (/bin/ls) => 40d8a0 set_program_name+0x0 (/bin/ls)
/build/buildd/coreutils-8.20/src/ls.c:1269
--- tools/perf/builtin-script.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)
tools/perf/builtin-script.c +15 -5
@@ -428,15 +428,22 @@ static void print_sample_bts(union perf_event *event, struct addr_location *al) {struct perf_event_attr *attr = &evsel->attr; +bool print_srcline_last = false;/* print branch_from information */ if (PRINT_FIELD (IP )) { -if (!symbol_conf.use_callchain) -printf (" " ); -else +unsigned int print_opts = output[attr->type].print_ip_opts; + +if (symbol_conf.use_callchain && sample->callchain) {printf ("\n" ); -perf_evsel__print_ip (evsel, sample, machine, al, - output[attr->type].print_ip_opts, + }else { +printf (" " ); +if (print_opts &PRINT_IP_OPT_SRCLINE ) { + print_srcline_last = true; + print_opts &= ~PRINT_IP_OPT_SRCLINE ; + } + } +perf_evsel__print_ip (evsel, sample, machine, al, print_opts,PERF_MAX_STACK_DEPTH ); }
@@ -448,6 +455,9 @@ static void print_sample_bts(union perf_event *event, !output[attr->type].user_set))print_sample_addr (event, sample, machine, thread, attr); +if (print_srcline_last) +map__fprintf_srcline (al->map, al->addr,"\n " , stdout); +printf ("\n" ); }
Signature · 1 line
1.7.11.7
Re: [PATCH V2 3/3] perf script: Improve srcline display for BTS
Em Fri, Dec 06, 2013 at 09:42:58AM +0200, Adrian Hunter escreveu:
Quoted 2 lines
Change the order of the output to put the srcline last. e.g. old format:
Can you please always provide the command line used, so that people can quickly reproduce your results, before and after your changes?
- Arnaldo
Quoted 57 lines
4028fc main+0x2c (/bin/ls)/build/buildd/coreutils-8.20/src/ls.c:1269 => 40d8a0
set_program_name+0x0(/bin/ls)new format:
4028fc main+0x2c (/bin/ls) => 40d8a0 set_program_name+0x0 (/bin/ls)/build/buildd/coreutils-8.20/src/ls.c:1269
Signed-off-by Adrian Hunter <[email protected]>--- tools/perf/builtin-script.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)tools/perf/builtin-script.c +15
-5@@ -428,15 +428,22 @@ static void print_sample_bts(union perf_event *event, struct addr_location *al) {struct perf_event_attr *attr = &evsel->attr; +bool print_srcline_last = false;/* print branch_from information */ if (PRINT_FIELD (IP )) { -if (!symbol_conf.use_callchain) -printf (" " ); -else +unsigned int print_opts = output[attr->type].print_ip_opts; + +if (symbol_conf.use_callchain && sample->callchain) {printf ("\n" ); -perf_evsel__print_ip (evsel, sample, machine, al, - output[attr->type].print_ip_opts, + }else { +printf (" " ); +if (print_opts &PRINT_IP_OPT_SRCLINE ) { + print_srcline_last = true; + print_opts &= ~PRINT_IP_OPT_SRCLINE ; + } + } +perf_evsel__print_ip (evsel, sample, machine, al, print_opts,PERF_MAX_STACK_DEPTH ); }@@ -448,6 +455,9 @@ static void print_sample_bts(union perf_event *event, !output[attr->type].user_set))print_sample_addr (event, sample, machine, thread, attr); +if (print_srcline_last) +map__fprintf_srcline (al->map, al->addr,"\n " , stdout); +printf ("\n" ); }Signature · 1 line
1.7.11.7
Adrian Hunter
reviewerRe: [PATCH V2 3/3] perf script: Improve srcline display for BTS
Quoted 6 lines · Arnaldo Carvalho de Melo
Em Fri, Dec 06, 2013 at 09:42:58AM +0200, Adrian Hunter escreveu:
Quoted 2 lines
Change the order of the output to put the srcline last. e.g. old format:
Can you please always provide the command line used, so that people can quickly reproduce your results, before and after your changes?
OK
perf record -e branches:u -c 1 -d ls
perf script -fip,sym,symoff,addr,srcline
Quoted 62 lines
- Arnaldo
Quoted 57 lines
4028fc main+0x2c (/bin/ls)/build/buildd/coreutils-8.20/src/ls.c:1269 => 40d8a0
set_program_name+0x0(/bin/ls)new format:
4028fc main+0x2c (/bin/ls) => 40d8a0 set_program_name+0x0 (/bin/ls)/build/buildd/coreutils-8.20/src/ls.c:1269
Signed-off-by Adrian Hunter <[email protected]>--- tools/perf/builtin-script.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)tools/perf/builtin-script.c +15
-5@@ -428,15 +428,22 @@ static void print_sample_bts(union perf_event *event, struct addr_location *al) {struct perf_event_attr *attr = &evsel->attr; +bool print_srcline_last = false;/* print branch_from information */ if (PRINT_FIELD (IP )) { -if (!symbol_conf.use_callchain) -printf (" " ); -else +unsigned int print_opts = output[attr->type].print_ip_opts; + +if (symbol_conf.use_callchain && sample->callchain) {printf ("\n" ); -perf_evsel__print_ip (evsel, sample, machine, al, - output[attr->type].print_ip_opts, + }else { +printf (" " ); +if (print_opts &PRINT_IP_OPT_SRCLINE ) { + print_srcline_last = true; + print_opts &= ~PRINT_IP_OPT_SRCLINE ; + } + } +perf_evsel__print_ip (evsel, sample, machine, al, print_opts,PERF_MAX_STACK_DEPTH ); }@@ -448,6 +455,9 @@ static void print_sample_bts(union perf_event *event, !output[attr->type].user_set))print_sample_addr (event, sample, machine, thread, attr); +if (print_srcline_last) +map__fprintf_srcline (al->map, al->addr,"\n " , stdout); +printf ("\n" ); }Signature · 1 line
1.7.11.7
Adrian Hunter
reviewerRe: [PATCH V2 3/3] perf script: Improve srcline display for BTS
Quoted 5 lines · Adrian Hunter
Quoted 4 lines · Arnaldo Carvalho de Melo
Em Fri, Dec 06, 2013 at 09:42:58AM +0200, Adrian Hunter escreveu:
Quoted 2 lines
Change the order of the output to put the srcline last. e.g. old format:
Quoted 8 lines
Quoted 2 lines
Can you please always provide the command line used, so that people can quickly reproduce your results, before and after your changes?
OK
perf record -e branches:u -c 1 -d ls
perf script -fip,sym,symoff,addr,srcline
Oops missed dso. That should be:
perf script -fip,sym,symoff,dso,addr,srcline
Quoted 66 lines
Quoted 63 lines
- Arnaldo
Quoted 57 lines
4028fc main+0x2c (/bin/ls)/build/buildd/coreutils-8.20/src/ls.c:1269 => 40d8a0
set_program_name+0x0(/bin/ls)new format:
4028fc main+0x2c (/bin/ls) => 40d8a0 set_program_name+0x0 (/bin/ls)/build/buildd/coreutils-8.20/src/ls.c:1269
Signed-off-by Adrian Hunter <[email protected]>--- tools/perf/builtin-script.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)tools/perf/builtin-script.c +15
-5@@ -428,15 +428,22 @@ static void print_sample_bts(union perf_event *event, struct addr_location *al) {struct perf_event_attr *attr = &evsel->attr; +bool print_srcline_last = false;/* print branch_from information */ if (PRINT_FIELD (IP )) { -if (!symbol_conf.use_callchain) -printf (" " ); -else +unsigned int print_opts = output[attr->type].print_ip_opts; + +if (symbol_conf.use_callchain && sample->callchain) {printf ("\n" ); -perf_evsel__print_ip (evsel, sample, machine, al, - output[attr->type].print_ip_opts, + }else { +printf (" " ); +if (print_opts &PRINT_IP_OPT_SRCLINE ) { + print_srcline_last = true; + print_opts &= ~PRINT_IP_OPT_SRCLINE ; + } + } +perf_evsel__print_ip (evsel, sample, machine, al, print_opts,PERF_MAX_STACK_DEPTH ); }@@ -448,6 +455,9 @@ static void print_sample_bts(union perf_event *event, !output[attr->type].user_set))print_sample_addr (event, sample, machine, thread, attr); +if (print_srcline_last) +map__fprintf_srcline (al->map, al->addr,"\n " , stdout); +printf ("\n" ); }Signature · 1 line
1.7.11.7
Adrian Hunter
reviewerPATCH v3 1/1 perf script: Improve srcline display for BTS
Change the order of the output to put the srcline last. e.g.
perf record -e branches:u -c 1 -d ls perf script -fip,sym,symoff,dso,addr,srcline
old format:
4028fc main+0x2c (/bin/ls)
/build/buildd/coreutils-8.20/src/ls.c:1269 => 40d8a0 set_program_name+0x0 (/bin/ls)
new format:
4028fc main+0x2c (/bin/ls) => 40d8a0 set_program_name+0x0 (/bin/ls)
/build/buildd/coreutils-8.20/src/ls.c:1269
--- tools/perf/builtin-script.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)
tools/perf/builtin-script.c +15 -5
@@ -428,15 +428,22 @@ static void print_sample_bts(union perf_event *event, struct addr_location *al) {struct perf_event_attr *attr = &evsel->attr; +bool print_srcline_last = false;/* print branch_from information */ if (PRINT_FIELD (IP )) { -if (!symbol_conf.use_callchain) -printf (" " ); -else +unsigned int print_opts = output[attr->type].print_ip_opts; + +if (symbol_conf.use_callchain && sample->callchain) {printf ("\n" ); -perf_evsel__print_ip (evsel, sample, machine, al, - output[attr->type].print_ip_opts, + }else { +printf (" " ); +if (print_opts &PRINT_IP_OPT_SRCLINE ) { + print_srcline_last = true; + print_opts &= ~PRINT_IP_OPT_SRCLINE ; + } + } +perf_evsel__print_ip (evsel, sample, machine, al, print_opts,PERF_MAX_STACK_DEPTH ); }
@@ -448,6 +455,9 @@ static void print_sample_bts(union perf_event *event, !output[attr->type].user_set))print_sample_addr (event, sample, machine, thread, attr); +if (print_srcline_last) +map__fprintf_srcline (al->map, al->addr,"\n " , stdout); +printf ("\n" ); }
-- 1.7.11.7