* [PATCH V2 0/3] perf script: Add an option to print the source line number
@ 2013-12-06 7:42 Adrian Hunter
2013-12-06 7:42 ` [PATCH V2 1/3] perf script: Fix symoff printing in callchains Adrian Hunter
` (2 more replies)
0 siblings, 3 replies; 13+ messages in thread
From: Adrian Hunter @ 2013-12-06 7:42 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Peter Zijlstra, Ingo Molnar, linux-kernel, David Ahern,
Frederic Weisbecker, Jiri Olsa, Mike Galbraith, Namhyung Kim,
Paul Mackerras, Stephane Eranian, Andi Kleen
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
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH V2 1/3] perf script: Fix symoff printing in callchains 2013-12-06 7:42 [PATCH V2 0/3] perf script: Add an option to print the source line number Adrian Hunter @ 2013-12-06 7:42 ` Adrian Hunter 2013-12-08 17:32 ` David Ahern 2013-12-11 11:04 ` [tip:perf/core] " tip-bot for Adrian Hunter 2013-12-06 7:42 ` [PATCH V2 2/3] perf script: Add an option to print the source line number Adrian Hunter 2013-12-06 7:42 ` [PATCH V2 3/3] perf script: Improve srcline display for BTS Adrian Hunter 2 siblings, 2 replies; 13+ messages in thread From: Adrian Hunter @ 2013-12-06 7:42 UTC (permalink / raw) To: Arnaldo Carvalho de Melo Cc: Peter Zijlstra, Ingo Molnar, linux-kernel, David Ahern, Frederic Weisbecker, Jiri Olsa, Mike Galbraith, Namhyung Kim, Paul Mackerras, Stephane Eranian, Andi Kleen 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 <adrian.hunter@intel.com> --- tools/perf/util/session.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 8a7da6f..c236b38 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -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 -- 1.7.11.7 ^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH V2 1/3] perf script: Fix symoff printing in callchains 2013-12-06 7:42 ` [PATCH V2 1/3] perf script: Fix symoff printing in callchains Adrian Hunter @ 2013-12-08 17:32 ` David Ahern 2013-12-11 11:04 ` [tip:perf/core] " tip-bot for Adrian Hunter 1 sibling, 0 replies; 13+ messages in thread From: David Ahern @ 2013-12-08 17:32 UTC (permalink / raw) To: Adrian Hunter, Arnaldo Carvalho de Melo Cc: Peter Zijlstra, Ingo Molnar, linux-kernel, Frederic Weisbecker, Jiri Olsa, Mike Galbraith, Namhyung Kim, Paul Mackerras, Stephane Eranian, Andi Kleen On 12/6/13, 12:42 AM, Adrian Hunter wrote: > 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 <adrian.hunter@intel.com> > --- > tools/perf/util/session.c | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) > Acked-by: David Ahern <dsahern@gmail.com> ^ permalink raw reply [flat|nested] 13+ messages in thread
* [tip:perf/core] perf script: Fix symoff printing in callchains 2013-12-06 7:42 ` [PATCH V2 1/3] perf script: Fix symoff printing in callchains Adrian Hunter 2013-12-08 17:32 ` David Ahern @ 2013-12-11 11:04 ` tip-bot for Adrian Hunter 1 sibling, 0 replies; 13+ messages in thread From: tip-bot for Adrian Hunter @ 2013-12-11 11:04 UTC (permalink / raw) To: linux-tip-commits Cc: acme, eranian, mingo, mingo, a.p.zijlstra, efault, jolsa, fweisbec, dsahern, ak, tglx, hpa, paulus, linux-kernel, namhyung, adrian.hunter Commit-ID: a4eb24a49566db77ee999b46603f602a0302f481 Gitweb: http://git.kernel.org/tip/a4eb24a49566db77ee999b46603f602a0302f481 Author: Adrian Hunter <adrian.hunter@intel.com> AuthorDate: Fri, 6 Dec 2013 09:42:56 +0200 Committer: Arnaldo Carvalho de Melo <acme@redhat.com> 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' Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Acked-by: David Ahern <dsahern@gmail.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Namhyung Kim <namhyung@gmail.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/r/1386315778-11633-2-git-send-email-adrian.hunter@intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> --- tools/perf/util/session.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 8a7da6f..c236b38 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -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 ^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH V2 2/3] perf script: Add an option to print the source line number 2013-12-06 7:42 [PATCH V2 0/3] perf script: Add an option to print the source line number Adrian Hunter 2013-12-06 7:42 ` [PATCH V2 1/3] perf script: Fix symoff printing in callchains Adrian Hunter @ 2013-12-06 7:42 ` Adrian Hunter 2013-12-08 17:35 ` David Ahern 2013-12-11 11:04 ` [tip:perf/core] " tip-bot for Adrian Hunter 2013-12-06 7:42 ` [PATCH V2 3/3] perf script: Improve srcline display for BTS Adrian Hunter 2 siblings, 2 replies; 13+ messages in thread From: Adrian Hunter @ 2013-12-06 7:42 UTC (permalink / raw) To: Arnaldo Carvalho de Melo Cc: Peter Zijlstra, Ingo Molnar, linux-kernel, David Ahern, Frederic Weisbecker, Jiri Olsa, Mike Galbraith, Namhyung Kim, Paul Mackerras, Stephane Eranian, Andi Kleen 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. Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> --- 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(-) diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt index cfdbb1e..c2a5071 100644 --- a/tools/perf/Documentation/perf-script.txt +++ b/tools/perf/Documentation/perf-script.txt @@ -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 diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 4484886..7a571fb 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -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; } /* diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c index ef5bc91..9b9bd71 100644 --- a/tools/perf/util/map.c +++ b/tools/perf/util/map.c @@ -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 diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h index e4e259c..18068c6 100644 --- a/tools/perf/util/map.h +++ b/tools/perf/util/map.h @@ -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, diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index c236b38..e748f29 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -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); } } diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h index 004d3e8..2a3955e 100644 --- a/tools/perf/util/session.h +++ b/tools/perf/util/session.h @@ -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; -- 1.7.11.7 ^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH V2 2/3] perf script: Add an option to print the source line number 2013-12-06 7:42 ` [PATCH V2 2/3] perf script: Add an option to print the source line number Adrian Hunter @ 2013-12-08 17:35 ` David Ahern 2013-12-09 8:10 ` Adrian Hunter 2013-12-11 11:04 ` [tip:perf/core] " tip-bot for Adrian Hunter 1 sibling, 1 reply; 13+ messages in thread From: David Ahern @ 2013-12-08 17:35 UTC (permalink / raw) To: Adrian Hunter, Arnaldo Carvalho de Melo Cc: Peter Zijlstra, Ingo Molnar, linux-kernel, Frederic Weisbecker, Jiri Olsa, Mike Galbraith, Namhyung Kim, Paul Mackerras, Stephane Eranian, Andi Kleen On 12/6/13, 12:42 AM, Adrian Hunter wrote: > 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? > > Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> > --- > 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(-) > > diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt > index cfdbb1e..c2a5071 100644 > --- a/tools/perf/Documentation/perf-script.txt > +++ b/tools/perf/Documentation/perf-script.txt > @@ -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 > diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c > index 4484886..7a571fb 100644 > --- a/tools/perf/builtin-script.c > +++ b/tools/perf/builtin-script.c > @@ -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; > } > > /* > diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c > index ef5bc91..9b9bd71 100644 > --- a/tools/perf/util/map.c > +++ b/tools/perf/util/map.c > @@ -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 > diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h > index e4e259c..18068c6 100644 > --- a/tools/perf/util/map.h > +++ b/tools/perf/util/map.h > @@ -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, > diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c > index c236b38..e748f29 100644 > --- a/tools/perf/util/session.c > +++ b/tools/perf/util/session.c > @@ -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); > } > } Why newline followed by space? Otherwise, Acked-by: David Ahern <dsahern@gmail.com> ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH V2 2/3] perf script: Add an option to print the source line number 2013-12-08 17:35 ` David Ahern @ 2013-12-09 8:10 ` Adrian Hunter 0 siblings, 0 replies; 13+ messages in thread From: Adrian Hunter @ 2013-12-09 8:10 UTC (permalink / raw) To: David Ahern Cc: Arnaldo Carvalho de Melo, Peter Zijlstra, Ingo Molnar, linux-kernel, Frederic Weisbecker, Jiri Olsa, Mike Galbraith, Namhyung Kim, Paul Mackerras, Stephane Eranian, Andi Kleen On 08/12/13 19:35, David Ahern wrote: > On 12/6/13, 12:42 AM, Adrian Hunter wrote: >> 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 > >> >> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> >> --- >> 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(-) >> >> diff --git a/tools/perf/Documentation/perf-script.txt >> b/tools/perf/Documentation/perf-script.txt >> index cfdbb1e..c2a5071 100644 >> --- a/tools/perf/Documentation/perf-script.txt >> +++ b/tools/perf/Documentation/perf-script.txt >> @@ -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 >> diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c >> index 4484886..7a571fb 100644 >> --- a/tools/perf/builtin-script.c >> +++ b/tools/perf/builtin-script.c >> @@ -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; >> } >> >> /* >> diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c >> index ef5bc91..9b9bd71 100644 >> --- a/tools/perf/util/map.c >> +++ b/tools/perf/util/map.c >> @@ -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 >> diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h >> index e4e259c..18068c6 100644 >> --- a/tools/perf/util/map.h >> +++ b/tools/perf/util/map.h >> @@ -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, >> diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c >> index c236b38..e748f29 100644 >> --- a/tools/perf/util/session.c >> +++ b/tools/perf/util/session.c >> @@ -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); >> } >> } > > Why newline followed by space? It looked better that way to me. > > Otherwise, Acked-by: David Ahern <dsahern@gmail.com> > > > ^ permalink raw reply [flat|nested] 13+ messages in thread
* [tip:perf/core] perf script: Add an option to print the source line number 2013-12-06 7:42 ` [PATCH V2 2/3] perf script: Add an option to print the source line number Adrian Hunter 2013-12-08 17:35 ` David Ahern @ 2013-12-11 11:04 ` tip-bot for Adrian Hunter 1 sibling, 0 replies; 13+ messages in thread From: tip-bot for Adrian Hunter @ 2013-12-11 11:04 UTC (permalink / raw) To: linux-tip-commits Cc: acme, eranian, mingo, mingo, a.p.zijlstra, efault, jolsa, fweisbec, ak, dsahern, tglx, hpa, paulus, linux-kernel, namhyung, adrian.hunter Commit-ID: cc8fae1d81648e85587f5d18b4f93e0b771fb02d Gitweb: http://git.kernel.org/tip/cc8fae1d81648e85587f5d18b4f93e0b771fb02d Author: Adrian Hunter <adrian.hunter@intel.com> AuthorDate: Fri, 6 Dec 2013 09:42:57 +0200 Committer: Arnaldo Carvalho de Melo <acme@redhat.com> 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 Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Namhyung Kim <namhyung@gmail.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/r/1386315778-11633-3-git-send-email-adrian.hunter@intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> --- 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(-) diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt index cfdbb1e..c2a5071 100644 --- a/tools/perf/Documentation/perf-script.txt +++ b/tools/perf/Documentation/perf-script.txt @@ -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 diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 4484886..7a571fb 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -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; } /* diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c index ef5bc91..9b9bd71 100644 --- a/tools/perf/util/map.c +++ b/tools/perf/util/map.c @@ -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 diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h index e4e259c..18068c6 100644 --- a/tools/perf/util/map.h +++ b/tools/perf/util/map.h @@ -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, diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index c236b38..e748f29 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -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); } } diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h index 004d3e8..2a3955e 100644 --- a/tools/perf/util/session.h +++ b/tools/perf/util/session.h @@ -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; ^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH V2 3/3] perf script: Improve srcline display for BTS 2013-12-06 7:42 [PATCH V2 0/3] perf script: Add an option to print the source line number Adrian Hunter 2013-12-06 7:42 ` [PATCH V2 1/3] perf script: Fix symoff printing in callchains Adrian Hunter 2013-12-06 7:42 ` [PATCH V2 2/3] perf script: Add an option to print the source line number Adrian Hunter @ 2013-12-06 7:42 ` Adrian Hunter 2013-12-09 18:04 ` Arnaldo Carvalho de Melo 2 siblings, 1 reply; 13+ messages in thread From: Adrian Hunter @ 2013-12-06 7:42 UTC (permalink / raw) To: Arnaldo Carvalho de Melo Cc: Peter Zijlstra, Ingo Molnar, linux-kernel, David Ahern, Frederic Weisbecker, Jiri Olsa, Mike Galbraith, Namhyung Kim, Paul Mackerras, Stephane Eranian, Andi Kleen Change 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 Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> --- tools/perf/builtin-script.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 7a571fb..8997b69 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -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 ^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH V2 3/3] perf script: Improve srcline display for BTS 2013-12-06 7:42 ` [PATCH V2 3/3] perf script: Improve srcline display for BTS Adrian Hunter @ 2013-12-09 18:04 ` Arnaldo Carvalho de Melo 2013-12-10 7:04 ` Adrian Hunter 0 siblings, 1 reply; 13+ messages in thread From: Arnaldo Carvalho de Melo @ 2013-12-09 18:04 UTC (permalink / raw) To: Adrian Hunter Cc: Peter Zijlstra, Ingo Molnar, linux-kernel, David Ahern, Frederic Weisbecker, Jiri Olsa, Mike Galbraith, Namhyung Kim, Paul Mackerras, Stephane Eranian, Andi Kleen Em Fri, Dec 06, 2013 at 09:42:58AM +0200, Adrian Hunter escreveu: > 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 > 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 <adrian.hunter@intel.com> > --- > tools/perf/builtin-script.c | 20 +++++++++++++++----- > 1 file changed, 15 insertions(+), 5 deletions(-) > > diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c > index 7a571fb..8997b69 100644 > --- a/tools/perf/builtin-script.c > +++ b/tools/perf/builtin-script.c > @@ -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 ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH V2 3/3] perf script: Improve srcline display for BTS 2013-12-09 18:04 ` Arnaldo Carvalho de Melo @ 2013-12-10 7:04 ` Adrian Hunter 2013-12-10 7:05 ` Adrian Hunter 0 siblings, 1 reply; 13+ messages in thread From: Adrian Hunter @ 2013-12-10 7:04 UTC (permalink / raw) To: Arnaldo Carvalho de Melo Cc: Peter Zijlstra, Ingo Molnar, linux-kernel, David Ahern, Frederic Weisbecker, Jiri Olsa, Mike Galbraith, Namhyung Kim, Paul Mackerras, Stephane Eranian, Andi Kleen On 09/12/13 20:04, Arnaldo Carvalho de Melo wrote: > Em Fri, Dec 06, 2013 at 09:42:58AM +0200, Adrian Hunter escreveu: >> 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 > > - Arnaldo > >> 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 <adrian.hunter@intel.com> >> --- >> tools/perf/builtin-script.c | 20 +++++++++++++++----- >> 1 file changed, 15 insertions(+), 5 deletions(-) >> >> diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c >> index 7a571fb..8997b69 100644 >> --- a/tools/perf/builtin-script.c >> +++ b/tools/perf/builtin-script.c >> @@ -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 > > ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH V2 3/3] perf script: Improve srcline display for BTS 2013-12-10 7:04 ` Adrian Hunter @ 2013-12-10 7:05 ` Adrian Hunter 2013-12-13 10:21 ` [PATCH V3] " Adrian Hunter 0 siblings, 1 reply; 13+ messages in thread From: Adrian Hunter @ 2013-12-10 7:05 UTC (permalink / raw) To: Adrian Hunter Cc: Arnaldo Carvalho de Melo, Peter Zijlstra, Ingo Molnar, linux-kernel, David Ahern, Frederic Weisbecker, Jiri Olsa, Mike Galbraith, Namhyung Kim, Paul Mackerras, Stephane Eranian, Andi Kleen On 10/12/13 09:04, Adrian Hunter wrote: > On 09/12/13 20:04, Arnaldo Carvalho de Melo wrote: >> Em Fri, Dec 06, 2013 at 09:42:58AM +0200, Adrian Hunter escreveu: >>> 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 Oops missed dso. That should be: perf script -fip,sym,symoff,dso,addr,srcline > >> >> - Arnaldo >> >>> 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 <adrian.hunter@intel.com> >>> --- >>> tools/perf/builtin-script.c | 20 +++++++++++++++----- >>> 1 file changed, 15 insertions(+), 5 deletions(-) >>> >>> diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c >>> index 7a571fb..8997b69 100644 >>> --- a/tools/perf/builtin-script.c >>> +++ b/tools/perf/builtin-script.c >>> @@ -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 >> >> > > > ^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH V3] perf script: Improve srcline display for BTS 2013-12-10 7:05 ` Adrian Hunter @ 2013-12-13 10:21 ` Adrian Hunter 0 siblings, 0 replies; 13+ messages in thread From: Adrian Hunter @ 2013-12-13 10:21 UTC (permalink / raw) To: Arnaldo Carvalho de Melo Cc: Peter Zijlstra, Ingo Molnar, linux-kernel, David Ahern, Frederic Weisbecker, Jiri Olsa, Mike Galbraith, Namhyung Kim, Paul Mackerras, Stephane Eranian, Andi Kleen 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 Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> --- tools/perf/builtin-script.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 7a571fb..8997b69 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -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 ^ permalink raw reply related [flat|nested] 13+ messages in thread
end of thread, other threads:[~2013-12-13 10:21 UTC | newest] Thread overview: 13+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2013-12-06 7:42 [PATCH V2 0/3] perf script: Add an option to print the source line number Adrian Hunter 2013-12-06 7:42 ` [PATCH V2 1/3] perf script: Fix symoff printing in callchains Adrian Hunter 2013-12-08 17:32 ` David Ahern 2013-12-11 11:04 ` [tip:perf/core] " tip-bot for Adrian Hunter 2013-12-06 7:42 ` [PATCH V2 2/3] perf script: Add an option to print the source line number Adrian Hunter 2013-12-08 17:35 ` David Ahern 2013-12-09 8:10 ` Adrian Hunter 2013-12-11 11:04 ` [tip:perf/core] " tip-bot for Adrian Hunter 2013-12-06 7:42 ` [PATCH V2 3/3] perf script: Improve srcline display for BTS Adrian Hunter 2013-12-09 18:04 ` Arnaldo Carvalho de Melo 2013-12-10 7:04 ` Adrian Hunter 2013-12-10 7:05 ` Adrian Hunter 2013-12-13 10:21 ` [PATCH V3] " Adrian Hunter
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox