* [PATCH 1/7] perf script: Do not call perf_event__preprocess_sample() twice)
2013-12-03 7:23 [PATCH 0/7] perf script: Add an option to print the source line number Adrian Hunter
@ 2013-12-03 7:23 ` Adrian Hunter
2013-12-03 18:23 ` Arnaldo Carvalho de Melo
2013-12-03 7:23 ` [PATCH 2/7] perf script: Add an option to print the source line number Adrian Hunter
` (5 subsequent siblings)
6 siblings, 1 reply; 21+ messages in thread
From: Adrian Hunter @ 2013-12-03 7:23 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
perf_event__preprocess_sample() is called in
process_sample_event(). Instead of calling it
again in perf_evsel__print_ip(), pass though
the resultant addr_location.
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
tools/perf/builtin-script.c | 11 ++++++-----
tools/perf/util/session.c | 33 ++++++++++++++++-----------------
tools/perf/util/session.h | 3 ++-
3 files changed, 24 insertions(+), 23 deletions(-)
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 952dce9..5b865a9 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -414,7 +414,8 @@ static void print_sample_bts(union perf_event *event,
struct perf_sample *sample,
struct perf_evsel *evsel,
struct machine *machine,
- struct thread *thread)
+ struct thread *thread,
+ struct addr_location *al)
{
struct perf_event_attr *attr = &evsel->attr;
@@ -424,7 +425,7 @@ static void print_sample_bts(union perf_event *event,
printf(" ");
else
printf("\n");
- perf_evsel__print_ip(evsel, event, sample, machine,
+ perf_evsel__print_ip(evsel, event, sample, machine, al,
output[attr->type].print_ip_opts,
PERF_MAX_STACK_DEPTH);
}
@@ -443,7 +444,7 @@ static void print_sample_bts(union perf_event *event,
static void process_event(union perf_event *event, struct perf_sample *sample,
struct perf_evsel *evsel, struct machine *machine,
struct thread *thread,
- struct addr_location *al __maybe_unused)
+ struct addr_location *al)
{
struct perf_event_attr *attr = &evsel->attr;
@@ -458,7 +459,7 @@ static void process_event(union perf_event *event, struct perf_sample *sample,
}
if (is_bts_event(attr)) {
- print_sample_bts(event, sample, evsel, machine, thread);
+ print_sample_bts(event, sample, evsel, machine, thread, al);
return;
}
@@ -474,7 +475,7 @@ static void process_event(union perf_event *event, struct perf_sample *sample,
else
printf("\n");
- perf_evsel__print_ip(evsel, event, sample, machine,
+ perf_evsel__print_ip(evsel, event, sample, machine, al,
output[attr->type].print_ip_opts,
PERF_MAX_STACK_DEPTH);
}
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 4ce146b..bc821b3 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -1487,11 +1487,12 @@ struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session,
return NULL;
}
-void perf_evsel__print_ip(struct perf_evsel *evsel, union perf_event *event,
+void perf_evsel__print_ip(struct perf_evsel *evsel,
+ union perf_event *event __maybe_unused,
struct perf_sample *sample, struct machine *machine,
- unsigned int print_opts, unsigned int stack_depth)
+ struct addr_location *al, unsigned int print_opts,
+ unsigned int stack_depth)
{
- struct addr_location al;
struct callchain_cursor_node *node;
int print_ip = print_opts & PRINT_IP_OPT_IP;
int print_sym = print_opts & PRINT_IP_OPT_SYM;
@@ -1500,15 +1501,10 @@ void perf_evsel__print_ip(struct perf_evsel *evsel, union perf_event *event,
int print_oneline = print_opts & PRINT_IP_OPT_ONELINE;
char s = print_oneline ? ' ' : '\t';
- if (perf_event__preprocess_sample(event, machine, &al, sample) < 0) {
- error("problem processing %d event, skipping it.\n",
- event->header.type);
- return;
- }
-
if (symbol_conf.use_callchain && sample->callchain) {
+ struct addr_location node_al;
- if (machine__resolve_callchain(machine, evsel, al.thread,
+ if (machine__resolve_callchain(machine, evsel, al->thread,
sample, NULL, NULL,
PERF_MAX_STACK_DEPTH) != 0) {
if (verbose)
@@ -1517,6 +1513,9 @@ void perf_evsel__print_ip(struct perf_evsel *evsel, union perf_event *event,
}
callchain_cursor_commit(&callchain_cursor);
+ if (print_symoffset)
+ node_al = *al;
+
while (stack_depth) {
node = callchain_cursor_current(&callchain_cursor);
if (!node)
@@ -1531,9 +1530,9 @@ void perf_evsel__print_ip(struct perf_evsel *evsel, union perf_event *event,
if (print_sym) {
printf(" ");
if (print_symoffset) {
- al.addr = node->ip;
- al.map = node->map;
- symbol__fprintf_symname_offs(node->sym, &al, stdout);
+ node_al.addr = node->ip;
+ node_al.map = node->map;
+ symbol__fprintf_symname_offs(node->sym, &node_al, stdout);
} else
symbol__fprintf_symname(node->sym, stdout);
}
@@ -1553,7 +1552,7 @@ next:
}
} else {
- if (al.sym && al.sym->ignore)
+ if (al->sym && al->sym->ignore)
return;
if (print_ip)
@@ -1562,15 +1561,15 @@ next:
if (print_sym) {
printf(" ");
if (print_symoffset)
- symbol__fprintf_symname_offs(al.sym, &al,
+ symbol__fprintf_symname_offs(al->sym, al,
stdout);
else
- symbol__fprintf_symname(al.sym, stdout);
+ symbol__fprintf_symname(al->sym, stdout);
}
if (print_dso) {
printf(" (");
- map__fprintf_dsoname(al.map, stdout);
+ map__fprintf_dsoname(al->map, stdout);
printf(")");
}
}
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index 50f6409..ee88500 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -107,7 +107,8 @@ struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session,
void perf_evsel__print_ip(struct perf_evsel *evsel, union perf_event *event,
struct perf_sample *sample, struct machine *machine,
- unsigned int print_opts, unsigned int stack_depth);
+ struct addr_location *al, unsigned int print_opts,
+ unsigned int stack_depth);
int perf_session__cpu_bitmap(struct perf_session *session,
const char *cpu_list, unsigned long *cpu_bitmap);
--
1.7.11.7
^ permalink raw reply related [flat|nested] 21+ messages in thread* Re: [PATCH 1/7] perf script: Do not call perf_event__preprocess_sample() twice)
2013-12-03 7:23 ` [PATCH 1/7] perf script: Do not call perf_event__preprocess_sample() twice) Adrian Hunter
@ 2013-12-03 18:23 ` Arnaldo Carvalho de Melo
2013-12-04 14:09 ` Adrian Hunter
0 siblings, 1 reply; 21+ messages in thread
From: Arnaldo Carvalho de Melo @ 2013-12-03 18:23 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 Tue, Dec 03, 2013 at 09:23:04AM +0200, Adrian Hunter escreveu:
> perf_event__preprocess_sample() is called in
> process_sample_event(). Instead of calling it
> again in perf_evsel__print_ip(), pass though
> the resultant addr_location.
<SNIP>
> +++ b/tools/perf/util/session.c
> @@ -1487,11 +1487,12 @@ struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session,
> return NULL;
> }
>
> -void perf_evsel__print_ip(struct perf_evsel *evsel, union perf_event *event,
> +void perf_evsel__print_ip(struct perf_evsel *evsel,
> + union perf_event *event __maybe_unused,
Why do we have to keep this parameter?
- Arnaldo
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH 1/7] perf script: Do not call perf_event__preprocess_sample() twice)
2013-12-03 18:23 ` Arnaldo Carvalho de Melo
@ 2013-12-04 14:09 ` Adrian Hunter
2013-12-04 14:16 ` [PATCH V2 " Adrian Hunter
0 siblings, 1 reply; 21+ messages in thread
From: Adrian Hunter @ 2013-12-04 14:09 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 03/12/13 20:23, Arnaldo Carvalho de Melo wrote:
> Em Tue, Dec 03, 2013 at 09:23:04AM +0200, Adrian Hunter escreveu:
>> perf_event__preprocess_sample() is called in
>> process_sample_event(). Instead of calling it
>> again in perf_evsel__print_ip(), pass though
>> the resultant addr_location.
>
> <SNIP>
>> +++ b/tools/perf/util/session.c
>> @@ -1487,11 +1487,12 @@ struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session,
>> return NULL;
>> }
>>
>> -void perf_evsel__print_ip(struct perf_evsel *evsel, union perf_event *event,
>> +void perf_evsel__print_ip(struct perf_evsel *evsel,
>> + union perf_event *event __maybe_unused,
>
> Why do we have to keep this parameter?
You are right - it is not needed.
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH V2 1/7] perf script: Do not call perf_event__preprocess_sample() twice)
2013-12-04 14:09 ` Adrian Hunter
@ 2013-12-04 14:16 ` Adrian Hunter
2013-12-10 9:17 ` [tip:perf/core] " tip-bot for Adrian Hunter
0 siblings, 1 reply; 21+ messages in thread
From: Adrian Hunter @ 2013-12-04 14:16 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
perf_event__preprocess_sample() is called in
process_sample_event(). Instead of calling it
again in perf_evsel__print_ip(), pass though
the resultant addr_location.
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
V2: removed unused 'event' parameter from perf_evsel__print_ip()
tools/perf/builtin-script.c | 11 ++++++-----
tools/perf/util/session.c | 31 ++++++++++++++-----------------
tools/perf/util/session.h | 4 ++--
3 files changed, 22 insertions(+), 24 deletions(-)
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 952dce9..c555bdd 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -414,7 +414,8 @@ static void print_sample_bts(union perf_event *event,
struct perf_sample *sample,
struct perf_evsel *evsel,
struct machine *machine,
- struct thread *thread)
+ struct thread *thread,
+ struct addr_location *al)
{
struct perf_event_attr *attr = &evsel->attr;
@@ -424,7 +425,7 @@ static void print_sample_bts(union perf_event *event,
printf(" ");
else
printf("\n");
- perf_evsel__print_ip(evsel, event, sample, machine,
+ perf_evsel__print_ip(evsel, sample, machine, al,
output[attr->type].print_ip_opts,
PERF_MAX_STACK_DEPTH);
}
@@ -443,7 +444,7 @@ static void print_sample_bts(union perf_event *event,
static void process_event(union perf_event *event, struct perf_sample *sample,
struct perf_evsel *evsel, struct machine *machine,
struct thread *thread,
- struct addr_location *al __maybe_unused)
+ struct addr_location *al)
{
struct perf_event_attr *attr = &evsel->attr;
@@ -458,7 +459,7 @@ static void process_event(union perf_event *event, struct perf_sample *sample,
}
if (is_bts_event(attr)) {
- print_sample_bts(event, sample, evsel, machine, thread);
+ print_sample_bts(event, sample, evsel, machine, thread, al);
return;
}
@@ -474,7 +475,7 @@ static void process_event(union perf_event *event, struct perf_sample *sample,
else
printf("\n");
- perf_evsel__print_ip(evsel, event, sample, machine,
+ perf_evsel__print_ip(evsel, sample, machine, al,
output[attr->type].print_ip_opts,
PERF_MAX_STACK_DEPTH);
}
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 4ce146b..8a7da6f 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -1487,11 +1487,10 @@ struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session,
return NULL;
}
-void perf_evsel__print_ip(struct perf_evsel *evsel, union perf_event *event,
- struct perf_sample *sample, struct machine *machine,
+void perf_evsel__print_ip(struct perf_evsel *evsel, struct perf_sample *sample,
+ struct machine *machine, struct addr_location *al,
unsigned int print_opts, unsigned int stack_depth)
{
- struct addr_location al;
struct callchain_cursor_node *node;
int print_ip = print_opts & PRINT_IP_OPT_IP;
int print_sym = print_opts & PRINT_IP_OPT_SYM;
@@ -1500,15 +1499,10 @@ void perf_evsel__print_ip(struct perf_evsel *evsel, union perf_event *event,
int print_oneline = print_opts & PRINT_IP_OPT_ONELINE;
char s = print_oneline ? ' ' : '\t';
- if (perf_event__preprocess_sample(event, machine, &al, sample) < 0) {
- error("problem processing %d event, skipping it.\n",
- event->header.type);
- return;
- }
-
if (symbol_conf.use_callchain && sample->callchain) {
+ struct addr_location node_al;
- if (machine__resolve_callchain(machine, evsel, al.thread,
+ if (machine__resolve_callchain(machine, evsel, al->thread,
sample, NULL, NULL,
PERF_MAX_STACK_DEPTH) != 0) {
if (verbose)
@@ -1517,6 +1511,9 @@ void perf_evsel__print_ip(struct perf_evsel *evsel, union perf_event *event,
}
callchain_cursor_commit(&callchain_cursor);
+ if (print_symoffset)
+ node_al = *al;
+
while (stack_depth) {
node = callchain_cursor_current(&callchain_cursor);
if (!node)
@@ -1531,9 +1528,9 @@ void perf_evsel__print_ip(struct perf_evsel *evsel, union perf_event *event,
if (print_sym) {
printf(" ");
if (print_symoffset) {
- al.addr = node->ip;
- al.map = node->map;
- symbol__fprintf_symname_offs(node->sym, &al, stdout);
+ node_al.addr = node->ip;
+ node_al.map = node->map;
+ symbol__fprintf_symname_offs(node->sym, &node_al, stdout);
} else
symbol__fprintf_symname(node->sym, stdout);
}
@@ -1553,7 +1550,7 @@ next:
}
} else {
- if (al.sym && al.sym->ignore)
+ if (al->sym && al->sym->ignore)
return;
if (print_ip)
@@ -1562,15 +1559,15 @@ next:
if (print_sym) {
printf(" ");
if (print_symoffset)
- symbol__fprintf_symname_offs(al.sym, &al,
+ symbol__fprintf_symname_offs(al->sym, al,
stdout);
else
- symbol__fprintf_symname(al.sym, stdout);
+ symbol__fprintf_symname(al->sym, stdout);
}
if (print_dso) {
printf(" (");
- map__fprintf_dsoname(al.map, stdout);
+ map__fprintf_dsoname(al->map, stdout);
printf(")");
}
}
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index 50f6409..7e5d4398 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -105,8 +105,8 @@ size_t perf_session__fprintf_nr_events(struct perf_session *session, FILE *fp);
struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session,
unsigned int type);
-void perf_evsel__print_ip(struct perf_evsel *evsel, union perf_event *event,
- struct perf_sample *sample, struct machine *machine,
+void perf_evsel__print_ip(struct perf_evsel *evsel, struct perf_sample *sample,
+ struct machine *machine, struct addr_location *al,
unsigned int print_opts, unsigned int stack_depth);
int perf_session__cpu_bitmap(struct perf_session *session,
--
1.7.11.7
^ permalink raw reply related [flat|nested] 21+ messages in thread* [tip:perf/core] perf script: Do not call perf_event__preprocess_sample() twice)
2013-12-04 14:16 ` [PATCH V2 " Adrian Hunter
@ 2013-12-10 9:17 ` tip-bot for Adrian Hunter
0 siblings, 0 replies; 21+ messages in thread
From: tip-bot for Adrian Hunter @ 2013-12-10 9:17 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: a2cb3cf20e06ef119ae541c1a08dc1977f7f0fff
Gitweb: http://git.kernel.org/tip/a2cb3cf20e06ef119ae541c1a08dc1977f7f0fff
Author: Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Wed, 4 Dec 2013 16:16:36 +0200
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 4 Dec 2013 15:09:53 -0300
perf script: Do not call perf_event__preprocess_sample() twice)
The perf_event__preprocess_sample() function is called in
process_sample_event(). Instead of calling it again in
perf_evsel__print_ip(), pass through the resultant addr_location.
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/529F3944.9050007@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/builtin-script.c | 11 ++++++-----
tools/perf/util/session.c | 31 ++++++++++++++-----------------
tools/perf/util/session.h | 4 ++--
3 files changed, 22 insertions(+), 24 deletions(-)
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 952dce9..c555bdd 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -414,7 +414,8 @@ static void print_sample_bts(union perf_event *event,
struct perf_sample *sample,
struct perf_evsel *evsel,
struct machine *machine,
- struct thread *thread)
+ struct thread *thread,
+ struct addr_location *al)
{
struct perf_event_attr *attr = &evsel->attr;
@@ -424,7 +425,7 @@ static void print_sample_bts(union perf_event *event,
printf(" ");
else
printf("\n");
- perf_evsel__print_ip(evsel, event, sample, machine,
+ perf_evsel__print_ip(evsel, sample, machine, al,
output[attr->type].print_ip_opts,
PERF_MAX_STACK_DEPTH);
}
@@ -443,7 +444,7 @@ static void print_sample_bts(union perf_event *event,
static void process_event(union perf_event *event, struct perf_sample *sample,
struct perf_evsel *evsel, struct machine *machine,
struct thread *thread,
- struct addr_location *al __maybe_unused)
+ struct addr_location *al)
{
struct perf_event_attr *attr = &evsel->attr;
@@ -458,7 +459,7 @@ static void process_event(union perf_event *event, struct perf_sample *sample,
}
if (is_bts_event(attr)) {
- print_sample_bts(event, sample, evsel, machine, thread);
+ print_sample_bts(event, sample, evsel, machine, thread, al);
return;
}
@@ -474,7 +475,7 @@ static void process_event(union perf_event *event, struct perf_sample *sample,
else
printf("\n");
- perf_evsel__print_ip(evsel, event, sample, machine,
+ perf_evsel__print_ip(evsel, sample, machine, al,
output[attr->type].print_ip_opts,
PERF_MAX_STACK_DEPTH);
}
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 4ce146b..8a7da6f 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -1487,11 +1487,10 @@ struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session,
return NULL;
}
-void perf_evsel__print_ip(struct perf_evsel *evsel, union perf_event *event,
- struct perf_sample *sample, struct machine *machine,
+void perf_evsel__print_ip(struct perf_evsel *evsel, struct perf_sample *sample,
+ struct machine *machine, struct addr_location *al,
unsigned int print_opts, unsigned int stack_depth)
{
- struct addr_location al;
struct callchain_cursor_node *node;
int print_ip = print_opts & PRINT_IP_OPT_IP;
int print_sym = print_opts & PRINT_IP_OPT_SYM;
@@ -1500,15 +1499,10 @@ void perf_evsel__print_ip(struct perf_evsel *evsel, union perf_event *event,
int print_oneline = print_opts & PRINT_IP_OPT_ONELINE;
char s = print_oneline ? ' ' : '\t';
- if (perf_event__preprocess_sample(event, machine, &al, sample) < 0) {
- error("problem processing %d event, skipping it.\n",
- event->header.type);
- return;
- }
-
if (symbol_conf.use_callchain && sample->callchain) {
+ struct addr_location node_al;
- if (machine__resolve_callchain(machine, evsel, al.thread,
+ if (machine__resolve_callchain(machine, evsel, al->thread,
sample, NULL, NULL,
PERF_MAX_STACK_DEPTH) != 0) {
if (verbose)
@@ -1517,6 +1511,9 @@ void perf_evsel__print_ip(struct perf_evsel *evsel, union perf_event *event,
}
callchain_cursor_commit(&callchain_cursor);
+ if (print_symoffset)
+ node_al = *al;
+
while (stack_depth) {
node = callchain_cursor_current(&callchain_cursor);
if (!node)
@@ -1531,9 +1528,9 @@ void perf_evsel__print_ip(struct perf_evsel *evsel, union perf_event *event,
if (print_sym) {
printf(" ");
if (print_symoffset) {
- al.addr = node->ip;
- al.map = node->map;
- symbol__fprintf_symname_offs(node->sym, &al, stdout);
+ node_al.addr = node->ip;
+ node_al.map = node->map;
+ symbol__fprintf_symname_offs(node->sym, &node_al, stdout);
} else
symbol__fprintf_symname(node->sym, stdout);
}
@@ -1553,7 +1550,7 @@ next:
}
} else {
- if (al.sym && al.sym->ignore)
+ if (al->sym && al->sym->ignore)
return;
if (print_ip)
@@ -1562,15 +1559,15 @@ next:
if (print_sym) {
printf(" ");
if (print_symoffset)
- symbol__fprintf_symname_offs(al.sym, &al,
+ symbol__fprintf_symname_offs(al->sym, al,
stdout);
else
- symbol__fprintf_symname(al.sym, stdout);
+ symbol__fprintf_symname(al->sym, stdout);
}
if (print_dso) {
printf(" (");
- map__fprintf_dsoname(al.map, stdout);
+ map__fprintf_dsoname(al->map, stdout);
printf(")");
}
}
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index 50f6409..7e5d4398 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -105,8 +105,8 @@ size_t perf_session__fprintf_nr_events(struct perf_session *session, FILE *fp);
struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session,
unsigned int type);
-void perf_evsel__print_ip(struct perf_evsel *evsel, union perf_event *event,
- struct perf_sample *sample, struct machine *machine,
+void perf_evsel__print_ip(struct perf_evsel *evsel, struct perf_sample *sample,
+ struct machine *machine, struct addr_location *al,
unsigned int print_opts, unsigned int stack_depth);
int perf_session__cpu_bitmap(struct perf_session *session,
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 2/7] perf script: Add an option to print the source line number
2013-12-03 7:23 [PATCH 0/7] perf script: Add an option to print the source line number Adrian Hunter
2013-12-03 7:23 ` [PATCH 1/7] perf script: Do not call perf_event__preprocess_sample() twice) Adrian Hunter
@ 2013-12-03 7:23 ` Adrian Hunter
2013-12-03 16:04 ` David Ahern
2013-12-03 7:23 ` [PATCH 3/7] perf tools: Use asprintf instead of malloc plus snprintf Adrian Hunter
` (4 subsequent siblings)
6 siblings, 1 reply; 21+ messages in thread
From: Adrian Hunter @ 2013-12-03 7:23 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 | 29 +++++++++++++++++++++++++++--
2 files changed, 28 insertions(+), 3 deletions(-)
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 5b865a9..9d0febc 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",
@@ -348,6 +355,24 @@ static void print_sample_start(struct perf_sample *sample,
}
}
+static void print_sample_finish(struct perf_evsel *evsel,
+ struct addr_location *al)
+{
+ struct perf_event_attr *attr = &evsel->attr;
+
+ if (PRINT_FIELD(SRCLINE) && al->map && al->map->dso) {
+ char *srcline;
+
+ srcline = get_srcline(al->map->dso,
+ map__rip_2objdump(al->map, al->addr));
+ if (srcline != SRCLINE_UNKNOWN)
+ printf("\n %s", srcline);
+ free_srcline(srcline);
+ }
+
+ printf("\n");
+}
+
static bool is_bts_event(struct perf_event_attr *attr)
{
return ((attr->type == PERF_TYPE_HARDWARE) &&
@@ -438,7 +463,7 @@ static void print_sample_bts(union perf_event *event,
!output[attr->type].user_set))
print_sample_addr(event, sample, machine, thread, attr);
- printf("\n");
+ print_sample_finish(evsel, al);
}
static void process_event(union perf_event *event, struct perf_sample *sample,
@@ -480,7 +505,7 @@ static void process_event(union perf_event *event, struct perf_sample *sample,
PERF_MAX_STACK_DEPTH);
}
- printf("\n");
+ print_sample_finish(evsel, al);
}
static int default_start_script(const char *script __maybe_unused,
--
1.7.11.7
^ permalink raw reply related [flat|nested] 21+ messages in thread* Re: [PATCH 2/7] perf script: Add an option to print the source line number
2013-12-03 7:23 ` [PATCH 2/7] perf script: Add an option to print the source line number Adrian Hunter
@ 2013-12-03 16:04 ` David Ahern
2013-12-03 16:07 ` David Ahern
0 siblings, 1 reply; 21+ messages in thread
From: David Ahern @ 2013-12-03 16:04 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/3/13, 12:23 AM, Adrian Hunter wrote:
> @@ -348,6 +355,24 @@ static void print_sample_start(struct perf_sample *sample,
> }
> }
>
> +static void print_sample_finish(struct perf_evsel *evsel,
> + struct addr_location *al)
> +{
> + struct perf_event_attr *attr = &evsel->attr;
> +
> + if (PRINT_FIELD(SRCLINE) && al->map && al->map->dso) {
> + char *srcline;
> +
> + srcline = get_srcline(al->map->dso,
> + map__rip_2objdump(al->map, al->addr));
> + if (srcline != SRCLINE_UNKNOWN)
> + printf("\n %s", srcline);
> + free_srcline(srcline);
> + }
> +
> + printf("\n");
> +}
> +
> static bool is_bts_event(struct perf_event_attr *attr)
> {
> return ((attr->type == PERF_TYPE_HARDWARE) &&
> @@ -438,7 +463,7 @@ static void print_sample_bts(union perf_event *event,
> !output[attr->type].user_set))
> print_sample_addr(event, sample, machine, thread, attr);
>
> - printf("\n");
> + print_sample_finish(evsel, al);
> }
>
> static void process_event(union perf_event *event, struct perf_sample *sample,
> @@ -480,7 +505,7 @@ static void process_event(union perf_event *event, struct perf_sample *sample,
> PERF_MAX_STACK_DEPTH);
> }
>
> - printf("\n");
> + print_sample_finish(evsel, al);
> }
>
> static int default_start_script(const char *script __maybe_unused,
What about callchains?
David
^ permalink raw reply [flat|nested] 21+ messages in thread* Re: [PATCH 2/7] perf script: Add an option to print the source line number
2013-12-03 16:04 ` David Ahern
@ 2013-12-03 16:07 ` David Ahern
0 siblings, 0 replies; 21+ messages in thread
From: David Ahern @ 2013-12-03 16:07 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/3/13, 9:04 AM, David Ahern wrote:
> What about callchains?
I think you can handle callcahins and IP by moving the srcline printing
into perf_evsel__print_ip() and adding a PRINT_IP_OPT_SRCLINE option.
David
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH 3/7] perf tools: Use asprintf instead of malloc plus snprintf
2013-12-03 7:23 [PATCH 0/7] perf script: Add an option to print the source line number Adrian Hunter
2013-12-03 7:23 ` [PATCH 1/7] perf script: Do not call perf_event__preprocess_sample() twice) Adrian Hunter
2013-12-03 7:23 ` [PATCH 2/7] perf script: Add an option to print the source line number Adrian Hunter
@ 2013-12-03 7:23 ` Adrian Hunter
2013-12-10 9:15 ` [tip:perf/core] " tip-bot for Adrian Hunter
2013-12-03 7:23 ` [PATCH 4/7] perf tools: Retain bfd reference to lookup source line numbers Adrian Hunter
` (3 subsequent siblings)
6 siblings, 1 reply; 21+ messages in thread
From: Adrian Hunter @ 2013-12-03 7:23 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
asprintf is equivalent to malloc plus snprintf so
use it because it is simpler.
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
tools/perf/util/srcline.c | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)
diff --git a/tools/perf/util/srcline.c b/tools/perf/util/srcline.c
index d11aefb..4c8e816 100644
--- a/tools/perf/util/srcline.c
+++ b/tools/perf/util/srcline.c
@@ -227,7 +227,6 @@ char *get_srcline(struct dso *dso, unsigned long addr)
unsigned line = 0;
char *srcline;
char *dso_name = dso->long_name;
- size_t size;
if (!dso->has_srcline)
return SRCLINE_UNKNOWN;
@@ -241,13 +240,7 @@ char *get_srcline(struct dso *dso, unsigned long addr)
if (!addr2line(dso_name, addr, &file, &line))
goto out;
- /* just calculate actual length */
- size = snprintf(NULL, 0, "%s:%u", file, line) + 1;
-
- srcline = malloc(size);
- if (srcline)
- snprintf(srcline, size, "%s:%u", file, line);
- else
+ if (asprintf(&srcline, "%s:%u", file, line) < 0)
srcline = SRCLINE_UNKNOWN;
free(file);
--
1.7.11.7
^ permalink raw reply related [flat|nested] 21+ messages in thread* [tip:perf/core] perf tools: Use asprintf instead of malloc plus snprintf
2013-12-03 7:23 ` [PATCH 3/7] perf tools: Use asprintf instead of malloc plus snprintf Adrian Hunter
@ 2013-12-10 9:15 ` tip-bot for Adrian Hunter
0 siblings, 0 replies; 21+ messages in thread
From: tip-bot for Adrian Hunter @ 2013-12-10 9:15 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: d88938ebc97df72320609b33aa0cf9a9a98accb1
Gitweb: http://git.kernel.org/tip/d88938ebc97df72320609b33aa0cf9a9a98accb1
Author: Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Tue, 3 Dec 2013 09:23:06 +0200
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 4 Dec 2013 13:46:36 -0300
perf tools: Use asprintf instead of malloc plus snprintf
The asprintf library function is equivalent to malloc plus snprintf so
use it because it is simpler.
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/1386055390-13757-4-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/util/srcline.c | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)
diff --git a/tools/perf/util/srcline.c b/tools/perf/util/srcline.c
index d11aefb..4c8e816 100644
--- a/tools/perf/util/srcline.c
+++ b/tools/perf/util/srcline.c
@@ -227,7 +227,6 @@ char *get_srcline(struct dso *dso, unsigned long addr)
unsigned line = 0;
char *srcline;
char *dso_name = dso->long_name;
- size_t size;
if (!dso->has_srcline)
return SRCLINE_UNKNOWN;
@@ -241,13 +240,7 @@ char *get_srcline(struct dso *dso, unsigned long addr)
if (!addr2line(dso_name, addr, &file, &line))
goto out;
- /* just calculate actual length */
- size = snprintf(NULL, 0, "%s:%u", file, line) + 1;
-
- srcline = malloc(size);
- if (srcline)
- snprintf(srcline, size, "%s:%u", file, line);
- else
+ if (asprintf(&srcline, "%s:%u", file, line) < 0)
srcline = SRCLINE_UNKNOWN;
free(file);
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 4/7] perf tools: Retain bfd reference to lookup source line numbers
2013-12-03 7:23 [PATCH 0/7] perf script: Add an option to print the source line number Adrian Hunter
` (2 preceding siblings ...)
2013-12-03 7:23 ` [PATCH 3/7] perf tools: Use asprintf instead of malloc plus snprintf Adrian Hunter
@ 2013-12-03 7:23 ` Adrian Hunter
2013-12-10 9:15 ` [tip:perf/core] perf symbols: " tip-bot for Adrian Hunter
2013-12-03 7:23 ` [PATCH 5/7] perf tools: Retain symbol source file name " Adrian Hunter
` (2 subsequent siblings)
6 siblings, 1 reply; 21+ messages in thread
From: Adrian Hunter @ 2013-12-03 7:23 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
Closng and re-opening for every lookup when using
libbfd to lookup source file name and line number
is very very slow. Instead keep the reference on
struct dso.
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
tools/perf/util/dso.c | 1 +
tools/perf/util/dso.h | 3 +++
tools/perf/util/srcline.c | 36 ++++++++++++++++++++++++++++++------
3 files changed, 34 insertions(+), 6 deletions(-)
diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index af4c687c..68aa55a 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -469,6 +469,7 @@ void dso__delete(struct dso *dso)
if (dso->lname_alloc)
free(dso->long_name);
dso_cache__free(&dso->cache);
+ dso__free_a2l(dso);
free(dso);
}
diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h
index 9ac666a..d8613dc 100644
--- a/tools/perf/util/dso.h
+++ b/tools/perf/util/dso.h
@@ -77,6 +77,7 @@ struct dso {
struct rb_root symbols[MAP__NR_TYPES];
struct rb_root symbol_names[MAP__NR_TYPES];
struct rb_root cache;
+ void *a2l;
enum dso_kernel_type kernel;
enum dso_swap_type needs_swap;
enum dso_binary_type symtab_type;
@@ -166,4 +167,6 @@ static inline bool dso__is_kcore(struct dso *dso)
dso->data_type == DSO_BINARY_TYPE__GUEST_KCORE;
}
+void dso__free_a2l(struct dso *dso);
+
#endif /* __PERF_DSO */
diff --git a/tools/perf/util/srcline.c b/tools/perf/util/srcline.c
index 4c8e816..25b85b2 100644
--- a/tools/perf/util/srcline.c
+++ b/tools/perf/util/srcline.c
@@ -146,18 +146,24 @@ static void addr2line_cleanup(struct a2l_data *a2l)
}
static int addr2line(const char *dso_name, unsigned long addr,
- char **file, unsigned int *line)
+ char **file, unsigned int *line, struct dso *dso)
{
int ret = 0;
- struct a2l_data *a2l;
+ struct a2l_data *a2l = dso->a2l;
+
+ if (!a2l) {
+ dso->a2l = addr2line_init(dso_name);
+ a2l = dso->a2l;
+ }
- a2l = addr2line_init(dso_name);
if (a2l == NULL) {
pr_warning("addr2line_init failed for %s\n", dso_name);
return 0;
}
a2l->addr = addr;
+ a2l->found = false;
+
bfd_map_over_sections(a2l->abfd, find_address_in_section, a2l);
if (a2l->found && a2l->filename) {
@@ -168,14 +174,26 @@ static int addr2line(const char *dso_name, unsigned long addr,
ret = 1;
}
- addr2line_cleanup(a2l);
return ret;
}
+void dso__free_a2l(struct dso *dso)
+{
+ struct a2l_data *a2l = dso->a2l;
+
+ if (!a2l)
+ return;
+
+ addr2line_cleanup(a2l);
+
+ dso->a2l = NULL;
+}
+
#else /* HAVE_LIBBFD_SUPPORT */
static int addr2line(const char *dso_name, unsigned long addr,
- char **file, unsigned int *line_nr)
+ char **file, unsigned int *line_nr,
+ struct dso *dso __maybe_unused)
{
FILE *fp;
char cmd[PATH_MAX];
@@ -219,6 +237,11 @@ out:
pclose(fp);
return ret;
}
+
+void dso__free_a2l(struct dso *dso __maybe_unused)
+{
+}
+
#endif /* HAVE_LIBBFD_SUPPORT */
char *get_srcline(struct dso *dso, unsigned long addr)
@@ -237,7 +260,7 @@ char *get_srcline(struct dso *dso, unsigned long addr)
if (!strncmp(dso_name, "/tmp/perf-", 10))
goto out;
- if (!addr2line(dso_name, addr, &file, &line))
+ if (!addr2line(dso_name, addr, &file, &line, dso))
goto out;
if (asprintf(&srcline, "%s:%u", file, line) < 0)
@@ -248,6 +271,7 @@ char *get_srcline(struct dso *dso, unsigned long addr)
out:
dso->has_srcline = 0;
+ dso__free_a2l(dso);
return SRCLINE_UNKNOWN;
}
--
1.7.11.7
^ permalink raw reply related [flat|nested] 21+ messages in thread* [tip:perf/core] perf symbols: Retain bfd reference to lookup source line numbers
2013-12-03 7:23 ` [PATCH 4/7] perf tools: Retain bfd reference to lookup source line numbers Adrian Hunter
@ 2013-12-10 9:15 ` tip-bot for Adrian Hunter
0 siblings, 0 replies; 21+ messages in thread
From: tip-bot for Adrian Hunter @ 2013-12-10 9:15 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: 454ff00f969e515c4cbfd52718ec5e01c7d9aeef
Gitweb: http://git.kernel.org/tip/454ff00f969e515c4cbfd52718ec5e01c7d9aeef
Author: Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Tue, 3 Dec 2013 09:23:07 +0200
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 4 Dec 2013 13:46:36 -0300
perf symbols: Retain bfd reference to lookup source line numbers
Closng and re-opening for every lookup when using libbfd to lookup
source file name and line number is very very slow. Instead keep the
reference on struct dso.
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/1386055390-13757-5-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/util/dso.c | 1 +
tools/perf/util/dso.h | 3 +++
tools/perf/util/srcline.c | 36 ++++++++++++++++++++++++++++++------
3 files changed, 34 insertions(+), 6 deletions(-)
diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index af4c687c..68aa55a 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -469,6 +469,7 @@ void dso__delete(struct dso *dso)
if (dso->lname_alloc)
free(dso->long_name);
dso_cache__free(&dso->cache);
+ dso__free_a2l(dso);
free(dso);
}
diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h
index 9ac666a..d8613dc 100644
--- a/tools/perf/util/dso.h
+++ b/tools/perf/util/dso.h
@@ -77,6 +77,7 @@ struct dso {
struct rb_root symbols[MAP__NR_TYPES];
struct rb_root symbol_names[MAP__NR_TYPES];
struct rb_root cache;
+ void *a2l;
enum dso_kernel_type kernel;
enum dso_swap_type needs_swap;
enum dso_binary_type symtab_type;
@@ -166,4 +167,6 @@ static inline bool dso__is_kcore(struct dso *dso)
dso->data_type == DSO_BINARY_TYPE__GUEST_KCORE;
}
+void dso__free_a2l(struct dso *dso);
+
#endif /* __PERF_DSO */
diff --git a/tools/perf/util/srcline.c b/tools/perf/util/srcline.c
index 4c8e816..25b85b2 100644
--- a/tools/perf/util/srcline.c
+++ b/tools/perf/util/srcline.c
@@ -146,18 +146,24 @@ static void addr2line_cleanup(struct a2l_data *a2l)
}
static int addr2line(const char *dso_name, unsigned long addr,
- char **file, unsigned int *line)
+ char **file, unsigned int *line, struct dso *dso)
{
int ret = 0;
- struct a2l_data *a2l;
+ struct a2l_data *a2l = dso->a2l;
+
+ if (!a2l) {
+ dso->a2l = addr2line_init(dso_name);
+ a2l = dso->a2l;
+ }
- a2l = addr2line_init(dso_name);
if (a2l == NULL) {
pr_warning("addr2line_init failed for %s\n", dso_name);
return 0;
}
a2l->addr = addr;
+ a2l->found = false;
+
bfd_map_over_sections(a2l->abfd, find_address_in_section, a2l);
if (a2l->found && a2l->filename) {
@@ -168,14 +174,26 @@ static int addr2line(const char *dso_name, unsigned long addr,
ret = 1;
}
- addr2line_cleanup(a2l);
return ret;
}
+void dso__free_a2l(struct dso *dso)
+{
+ struct a2l_data *a2l = dso->a2l;
+
+ if (!a2l)
+ return;
+
+ addr2line_cleanup(a2l);
+
+ dso->a2l = NULL;
+}
+
#else /* HAVE_LIBBFD_SUPPORT */
static int addr2line(const char *dso_name, unsigned long addr,
- char **file, unsigned int *line_nr)
+ char **file, unsigned int *line_nr,
+ struct dso *dso __maybe_unused)
{
FILE *fp;
char cmd[PATH_MAX];
@@ -219,6 +237,11 @@ out:
pclose(fp);
return ret;
}
+
+void dso__free_a2l(struct dso *dso __maybe_unused)
+{
+}
+
#endif /* HAVE_LIBBFD_SUPPORT */
char *get_srcline(struct dso *dso, unsigned long addr)
@@ -237,7 +260,7 @@ char *get_srcline(struct dso *dso, unsigned long addr)
if (!strncmp(dso_name, "/tmp/perf-", 10))
goto out;
- if (!addr2line(dso_name, addr, &file, &line))
+ if (!addr2line(dso_name, addr, &file, &line, dso))
goto out;
if (asprintf(&srcline, "%s:%u", file, line) < 0)
@@ -248,6 +271,7 @@ char *get_srcline(struct dso *dso, unsigned long addr)
out:
dso->has_srcline = 0;
+ dso__free_a2l(dso);
return SRCLINE_UNKNOWN;
}
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 5/7] perf tools: Retain symbol source file name to lookup source line numbers
2013-12-03 7:23 [PATCH 0/7] perf script: Add an option to print the source line number Adrian Hunter
` (3 preceding siblings ...)
2013-12-03 7:23 ` [PATCH 4/7] perf tools: Retain bfd reference to lookup source line numbers Adrian Hunter
@ 2013-12-03 7:23 ` Adrian Hunter
2013-12-10 9:15 ` [tip:perf/core] perf symbols: " tip-bot for Adrian Hunter
2013-12-03 7:23 ` [PATCH 6/7] perf tools: Do not need to read symbols for source line lookup Adrian Hunter
2013-12-03 7:23 ` [PATCH 7/7] perf tools: Do not disable source line lookup just because of 1 failure Adrian Hunter
6 siblings, 1 reply; 21+ messages in thread
From: Adrian Hunter @ 2013-12-03 7:23 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
Currently, lookup of an ip's source file name
and line number is done using the dso file name.
Instead retain the file name used to lookup the
dso's symbols and use that.
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
tools/perf/util/dso.c | 1 +
tools/perf/util/dso.h | 1 +
tools/perf/util/srcline.c | 7 ++++++-
tools/perf/util/symbol.c | 2 ++
4 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index 68aa55a..49da968 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -470,6 +470,7 @@ void dso__delete(struct dso *dso)
free(dso->long_name);
dso_cache__free(&dso->cache);
dso__free_a2l(dso);
+ free(dso->symsrc_filename);
free(dso);
}
diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h
index d8613dc..7142e52 100644
--- a/tools/perf/util/dso.h
+++ b/tools/perf/util/dso.h
@@ -78,6 +78,7 @@ struct dso {
struct rb_root symbol_names[MAP__NR_TYPES];
struct rb_root cache;
void *a2l;
+ char *symsrc_filename;
enum dso_kernel_type kernel;
enum dso_swap_type needs_swap;
enum dso_binary_type symtab_type;
diff --git a/tools/perf/util/srcline.c b/tools/perf/util/srcline.c
index 25b85b2..93795f9 100644
--- a/tools/perf/util/srcline.c
+++ b/tools/perf/util/srcline.c
@@ -249,11 +249,16 @@ char *get_srcline(struct dso *dso, unsigned long addr)
char *file = NULL;
unsigned line = 0;
char *srcline;
- char *dso_name = dso->long_name;
+ char *dso_name;
if (!dso->has_srcline)
return SRCLINE_UNKNOWN;
+ if (dso->symsrc_filename)
+ dso_name = dso->symsrc_filename;
+ else
+ dso_name = dso->long_name;
+
if (dso_name[0] == '[')
goto out;
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 360eefe..de87dba 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -1336,6 +1336,8 @@ int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter)
if (!syms_ss && symsrc__has_symtab(ss)) {
syms_ss = ss;
next_slot = true;
+ if (!dso->symsrc_filename)
+ dso->symsrc_filename = strdup(name);
}
if (!runtime_ss && symsrc__possibly_runtime(ss)) {
--
1.7.11.7
^ permalink raw reply related [flat|nested] 21+ messages in thread* [tip:perf/core] perf symbols: Retain symbol source file name to lookup source line numbers
2013-12-03 7:23 ` [PATCH 5/7] perf tools: Retain symbol source file name " Adrian Hunter
@ 2013-12-10 9:15 ` tip-bot for Adrian Hunter
0 siblings, 0 replies; 21+ messages in thread
From: tip-bot for Adrian Hunter @ 2013-12-10 9:15 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: 0058aef65eda9c9dde8253af702d542ba7eef697
Gitweb: http://git.kernel.org/tip/0058aef65eda9c9dde8253af702d542ba7eef697
Author: Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Tue, 3 Dec 2013 09:23:08 +0200
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 4 Dec 2013 13:46:36 -0300
perf symbols: Retain symbol source file name to lookup source line numbers
Currently, lookup of an ip's source file name and line number is done
using the dso file name.
Instead retain the file name used to lookup the dso's symbols and use
that.
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/1386055390-13757-6-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/util/dso.c | 1 +
tools/perf/util/dso.h | 1 +
tools/perf/util/srcline.c | 7 ++++++-
tools/perf/util/symbol.c | 2 ++
4 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index 68aa55a..49da968 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -470,6 +470,7 @@ void dso__delete(struct dso *dso)
free(dso->long_name);
dso_cache__free(&dso->cache);
dso__free_a2l(dso);
+ free(dso->symsrc_filename);
free(dso);
}
diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h
index d8613dc..7142e52 100644
--- a/tools/perf/util/dso.h
+++ b/tools/perf/util/dso.h
@@ -78,6 +78,7 @@ struct dso {
struct rb_root symbol_names[MAP__NR_TYPES];
struct rb_root cache;
void *a2l;
+ char *symsrc_filename;
enum dso_kernel_type kernel;
enum dso_swap_type needs_swap;
enum dso_binary_type symtab_type;
diff --git a/tools/perf/util/srcline.c b/tools/perf/util/srcline.c
index 25b85b2..93795f9 100644
--- a/tools/perf/util/srcline.c
+++ b/tools/perf/util/srcline.c
@@ -249,11 +249,16 @@ char *get_srcline(struct dso *dso, unsigned long addr)
char *file = NULL;
unsigned line = 0;
char *srcline;
- char *dso_name = dso->long_name;
+ char *dso_name;
if (!dso->has_srcline)
return SRCLINE_UNKNOWN;
+ if (dso->symsrc_filename)
+ dso_name = dso->symsrc_filename;
+ else
+ dso_name = dso->long_name;
+
if (dso_name[0] == '[')
goto out;
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 360eefe..de87dba 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -1336,6 +1336,8 @@ int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter)
if (!syms_ss && symsrc__has_symtab(ss)) {
syms_ss = ss;
next_slot = true;
+ if (!dso->symsrc_filename)
+ dso->symsrc_filename = strdup(name);
}
if (!runtime_ss && symsrc__possibly_runtime(ss)) {
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 6/7] perf tools: Do not need to read symbols for source line lookup
2013-12-03 7:23 [PATCH 0/7] perf script: Add an option to print the source line number Adrian Hunter
` (4 preceding siblings ...)
2013-12-03 7:23 ` [PATCH 5/7] perf tools: Retain symbol source file name " Adrian Hunter
@ 2013-12-03 7:23 ` Adrian Hunter
2013-12-03 20:24 ` Arnaldo Carvalho de Melo
2013-12-03 7:23 ` [PATCH 7/7] perf tools: Do not disable source line lookup just because of 1 failure Adrian Hunter
6 siblings, 1 reply; 21+ messages in thread
From: Adrian Hunter @ 2013-12-03 7:23 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
When using libbfd to lookup source filename and line number,
libbfd does not need the symbol table. Removing the symbol
table reading, doubles the speed of 'perf script' with the
'srcline' option.
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
tools/perf/util/srcline.c | 53 +----------------------------------------------
1 file changed, 1 insertion(+), 52 deletions(-)
diff --git a/tools/perf/util/srcline.c b/tools/perf/util/srcline.c
index 93795f9..e09c9e0 100644
--- a/tools/perf/util/srcline.c
+++ b/tools/perf/util/srcline.c
@@ -29,54 +29,6 @@ struct a2l_data {
asymbol **syms;
};
-static int bfd_error(const char *string)
-{
- const char *errmsg;
-
- errmsg = bfd_errmsg(bfd_get_error());
- fflush(stdout);
-
- if (string)
- pr_debug("%s: %s\n", string, errmsg);
- else
- pr_debug("%s\n", errmsg);
-
- return -1;
-}
-
-static int slurp_symtab(bfd *abfd, struct a2l_data *a2l)
-{
- long storage;
- long symcount;
- asymbol **syms;
- bfd_boolean dynamic = FALSE;
-
- if ((bfd_get_file_flags(abfd) & HAS_SYMS) == 0)
- return bfd_error(bfd_get_filename(abfd));
-
- storage = bfd_get_symtab_upper_bound(abfd);
- if (storage == 0L) {
- storage = bfd_get_dynamic_symtab_upper_bound(abfd);
- dynamic = TRUE;
- }
- if (storage < 0L)
- return bfd_error(bfd_get_filename(abfd));
-
- syms = malloc(storage);
- if (dynamic)
- symcount = bfd_canonicalize_dynamic_symtab(abfd, syms);
- else
- symcount = bfd_canonicalize_symtab(abfd, syms);
-
- if (symcount < 0) {
- free(syms);
- return bfd_error(bfd_get_filename(abfd));
- }
-
- a2l->syms = syms;
- return 0;
-}
-
static void find_address_in_section(bfd *abfd, asection *section, void *data)
{
bfd_vma pc, vma;
@@ -96,7 +48,7 @@ static void find_address_in_section(bfd *abfd, asection *section, void *data)
if (pc < vma || pc >= vma + size)
return;
- a2l->found = bfd_find_nearest_line(abfd, section, a2l->syms, pc - vma,
+ a2l->found = bfd_find_nearest_line(abfd, section, NULL, pc - vma,
&a2l->filename, &a2l->funcname,
&a2l->line);
}
@@ -122,9 +74,6 @@ static struct a2l_data *addr2line_init(const char *path)
if (a2l->input == NULL)
goto out;
- if (slurp_symtab(abfd, a2l))
- goto out;
-
return a2l;
out:
--
1.7.11.7
^ permalink raw reply related [flat|nested] 21+ messages in thread* Re: [PATCH 6/7] perf tools: Do not need to read symbols for source line lookup
2013-12-03 7:23 ` [PATCH 6/7] perf tools: Do not need to read symbols for source line lookup Adrian Hunter
@ 2013-12-03 20:24 ` Arnaldo Carvalho de Melo
2013-12-04 14:00 ` Adrian Hunter
0 siblings, 1 reply; 21+ messages in thread
From: Arnaldo Carvalho de Melo @ 2013-12-03 20:24 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 Tue, Dec 03, 2013 at 09:23:09AM +0200, Adrian Hunter escreveu:
> When using libbfd to lookup source filename and line number,
> libbfd does not need the symbol table. Removing the symbol
> table reading, doubles the speed of 'perf script' with the
> 'srcline' option.
[root@zoo ~]# gdb perf
run report -s srcline
b00000m
bt
#0 0x000000000050ac60 in read_unsigned_leb128 ()
#1 0x00000000005189f7 in find_abstract_instance_name.isra.20 ()
#2 0x00000000005190e1 in scan_unit_for_symbols ()
#3 0x0000000000519a69 in comp_unit_find_nearest_line ()
#4 0x000000000051a6ff in find_line.part.26 ()
#5 0x0000000000531063 in _bfd_elf_find_nearest_line_discriminator ()
#6 0x000000000053117b in _bfd_elf_find_nearest_line ()
#7 0x00000000004bf22d in find_address_in_section (abfd=0x39de5f0, section=0x3a32c38, data=0x3901950) at util/srcline.c:51
#8 0x000000000050ccdc in bfd_map_over_sections ()
#9 0x00000000004bf48b in addr2line (dso_name=0x39fb830 "/lib/modules/3.13.0-rc1+/kernel/drivers/gpu/drm/drm.ko", addr=20832,
file=0x7fffffffcc00, line=0x7fffffffcbfc, dso=0x90f9e0) at util/srcline.c:116
#10 0x00000000004bf608 in get_srcline (dso=0x90f9e0, addr=20832) at util/srcline.c:217
#11 0x00000000004b00fe in sort__srcline_cmp (left=0x1dc76f0, right=0x7fffffffcd70) at util/sort.c:268
#12 0x00000000004b3942 in hist_entry__cmp (left=0x1dc76f0, right=0x7fffffffcd70) at util/hist.c:450
#13 0x00000000004b35f4 in add_hist_entry (hists=0x90f278, entry=0x7fffffffcd70, al=0x7fffffffcf90, period=399301, weight=0)
at util/hist.c:367
#14 0x00000000004b38d8 in __hists__add_entry (hists=0x90f278, al=0x7fffffffcf90, sym_parent=0x0, bi=0x0, mi=0x0, period=399301,
weight=0, transaction=0) at util/hist.c:440
#15 0x000000000042c9da in perf_evsel__add_hist_entry (tool=0x7fffffffd510, evsel=0x90f1d0, al=0x7fffffffcf90, sample=0x7fffffffd140,
machine=0x90e6b8) at builtin-report.c:274
#16 0x000000000042cd4f in process_sample_event (tool=0x7fffffffd510, event=0x7ffff17aea30, sample=0x7fffffffd140, evsel=0x90f1d0,
machine=0x90e6b8) at builtin-report.c:347
#17 0x000000000049df43 in perf_session__deliver_sample (session=0x90e5e0, tool=0x7fffffffd510, event=0x7ffff17aea30,
sample=0x7fffffffd140, evsel=0x90f1d0, machine=0x90e6b8) at util/session.c:930
#18 0x000000000049e107 in perf_session_deliver_event (session=0x90e5e0, event=0x7ffff17aea30, sample=0x7fffffffd140,
tool=0x7fffffffd510, file_offset=821808) at util/session.c:984
#19 0x000000000049cfb4 in flush_sample_queue (s=0x90e5e0, tool=0x7fffffffd510) at util/session.c:526
#20 0x000000000049ef53 in __perf_session__process_events (session=0x90e5e0, data_offset=216, data_size=832400, file_size=832616,
tool=0x7fffffffd510) at util/session.c:1371
#21 0x000000000049f02e in perf_session__process_events (session=0x90e5e0, tool=0x7fffffffd510) at util/session.c:1389
#22 0x000000000042d605 in __cmd_report (rep=0x7fffffffd510) at builtin-report.c:527
---Type <return> to continue, or q <return> to quit---
Applied all except this one and the other one David commented on,
waiting for that discussion to reach some conclusion.
But with the ones applied 'perf report -s srcline' is _much_ faster,
thanks!
- Arnaldo
> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
> ---
> tools/perf/util/srcline.c | 53 +----------------------------------------------
> 1 file changed, 1 insertion(+), 52 deletions(-)
>
> diff --git a/tools/perf/util/srcline.c b/tools/perf/util/srcline.c
> index 93795f9..e09c9e0 100644
> --- a/tools/perf/util/srcline.c
> +++ b/tools/perf/util/srcline.c
> @@ -29,54 +29,6 @@ struct a2l_data {
> asymbol **syms;
> };
>
> -static int bfd_error(const char *string)
> -{
> - const char *errmsg;
> -
> - errmsg = bfd_errmsg(bfd_get_error());
> - fflush(stdout);
> -
> - if (string)
> - pr_debug("%s: %s\n", string, errmsg);
> - else
> - pr_debug("%s\n", errmsg);
> -
> - return -1;
> -}
> -
> -static int slurp_symtab(bfd *abfd, struct a2l_data *a2l)
> -{
> - long storage;
> - long symcount;
> - asymbol **syms;
> - bfd_boolean dynamic = FALSE;
> -
> - if ((bfd_get_file_flags(abfd) & HAS_SYMS) == 0)
> - return bfd_error(bfd_get_filename(abfd));
> -
> - storage = bfd_get_symtab_upper_bound(abfd);
> - if (storage == 0L) {
> - storage = bfd_get_dynamic_symtab_upper_bound(abfd);
> - dynamic = TRUE;
> - }
> - if (storage < 0L)
> - return bfd_error(bfd_get_filename(abfd));
> -
> - syms = malloc(storage);
> - if (dynamic)
> - symcount = bfd_canonicalize_dynamic_symtab(abfd, syms);
> - else
> - symcount = bfd_canonicalize_symtab(abfd, syms);
> -
> - if (symcount < 0) {
> - free(syms);
> - return bfd_error(bfd_get_filename(abfd));
> - }
> -
> - a2l->syms = syms;
> - return 0;
> -}
> -
> static void find_address_in_section(bfd *abfd, asection *section, void *data)
> {
> bfd_vma pc, vma;
> @@ -96,7 +48,7 @@ static void find_address_in_section(bfd *abfd, asection *section, void *data)
> if (pc < vma || pc >= vma + size)
> return;
>
> - a2l->found = bfd_find_nearest_line(abfd, section, a2l->syms, pc - vma,
> + a2l->found = bfd_find_nearest_line(abfd, section, NULL, pc - vma,
> &a2l->filename, &a2l->funcname,
> &a2l->line);
> }
> @@ -122,9 +74,6 @@ static struct a2l_data *addr2line_init(const char *path)
> if (a2l->input == NULL)
> goto out;
>
> - if (slurp_symtab(abfd, a2l))
> - goto out;
> -
> return a2l;
>
> out:
> --
> 1.7.11.7
^ permalink raw reply [flat|nested] 21+ messages in thread* Re: [PATCH 6/7] perf tools: Do not need to read symbols for source line lookup
2013-12-03 20:24 ` Arnaldo Carvalho de Melo
@ 2013-12-04 14:00 ` Adrian Hunter
2013-12-04 18:08 ` Arnaldo Carvalho de Melo
0 siblings, 1 reply; 21+ messages in thread
From: Adrian Hunter @ 2013-12-04 14:00 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 03/12/13 22:24, Arnaldo Carvalho de Melo wrote:
> Em Tue, Dec 03, 2013 at 09:23:09AM +0200, Adrian Hunter escreveu:
>> When using libbfd to lookup source filename and line number,
>> libbfd does not need the symbol table. Removing the symbol
>> table reading, doubles the speed of 'perf script' with the
>> 'srcline' option.
>
> [root@zoo ~]# gdb perf
> run report -s srcline
>
> b00000m
I wasn't able to reproduce this but I noticed the line numbers
were not found for kernel modules with this patch - so it seems
some binaries need the symbol information and some don't.
So please disregard this patch, sorry for your trouble.
>
> bt
> #0 0x000000000050ac60 in read_unsigned_leb128 ()
> #1 0x00000000005189f7 in find_abstract_instance_name.isra.20 ()
> #2 0x00000000005190e1 in scan_unit_for_symbols ()
> #3 0x0000000000519a69 in comp_unit_find_nearest_line ()
> #4 0x000000000051a6ff in find_line.part.26 ()
> #5 0x0000000000531063 in _bfd_elf_find_nearest_line_discriminator ()
> #6 0x000000000053117b in _bfd_elf_find_nearest_line ()
> #7 0x00000000004bf22d in find_address_in_section (abfd=0x39de5f0, section=0x3a32c38, data=0x3901950) at util/srcline.c:51
> #8 0x000000000050ccdc in bfd_map_over_sections ()
> #9 0x00000000004bf48b in addr2line (dso_name=0x39fb830 "/lib/modules/3.13.0-rc1+/kernel/drivers/gpu/drm/drm.ko", addr=20832,
> file=0x7fffffffcc00, line=0x7fffffffcbfc, dso=0x90f9e0) at util/srcline.c:116
> #10 0x00000000004bf608 in get_srcline (dso=0x90f9e0, addr=20832) at util/srcline.c:217
> #11 0x00000000004b00fe in sort__srcline_cmp (left=0x1dc76f0, right=0x7fffffffcd70) at util/sort.c:268
> #12 0x00000000004b3942 in hist_entry__cmp (left=0x1dc76f0, right=0x7fffffffcd70) at util/hist.c:450
> #13 0x00000000004b35f4 in add_hist_entry (hists=0x90f278, entry=0x7fffffffcd70, al=0x7fffffffcf90, period=399301, weight=0)
> at util/hist.c:367
> #14 0x00000000004b38d8 in __hists__add_entry (hists=0x90f278, al=0x7fffffffcf90, sym_parent=0x0, bi=0x0, mi=0x0, period=399301,
> weight=0, transaction=0) at util/hist.c:440
> #15 0x000000000042c9da in perf_evsel__add_hist_entry (tool=0x7fffffffd510, evsel=0x90f1d0, al=0x7fffffffcf90, sample=0x7fffffffd140,
> machine=0x90e6b8) at builtin-report.c:274
> #16 0x000000000042cd4f in process_sample_event (tool=0x7fffffffd510, event=0x7ffff17aea30, sample=0x7fffffffd140, evsel=0x90f1d0,
> machine=0x90e6b8) at builtin-report.c:347
> #17 0x000000000049df43 in perf_session__deliver_sample (session=0x90e5e0, tool=0x7fffffffd510, event=0x7ffff17aea30,
> sample=0x7fffffffd140, evsel=0x90f1d0, machine=0x90e6b8) at util/session.c:930
> #18 0x000000000049e107 in perf_session_deliver_event (session=0x90e5e0, event=0x7ffff17aea30, sample=0x7fffffffd140,
> tool=0x7fffffffd510, file_offset=821808) at util/session.c:984
> #19 0x000000000049cfb4 in flush_sample_queue (s=0x90e5e0, tool=0x7fffffffd510) at util/session.c:526
> #20 0x000000000049ef53 in __perf_session__process_events (session=0x90e5e0, data_offset=216, data_size=832400, file_size=832616,
> tool=0x7fffffffd510) at util/session.c:1371
> #21 0x000000000049f02e in perf_session__process_events (session=0x90e5e0, tool=0x7fffffffd510) at util/session.c:1389
> #22 0x000000000042d605 in __cmd_report (rep=0x7fffffffd510) at builtin-report.c:527
> ---Type <return> to continue, or q <return> to quit---
>
> Applied all except this one and the other one David commented on,
> waiting for that discussion to reach some conclusion.
>
> But with the ones applied 'perf report -s srcline' is _much_ faster,
> thanks!
>
> - Arnaldo
>
>> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
>> ---
>> tools/perf/util/srcline.c | 53 +----------------------------------------------
>> 1 file changed, 1 insertion(+), 52 deletions(-)
>>
>> diff --git a/tools/perf/util/srcline.c b/tools/perf/util/srcline.c
>> index 93795f9..e09c9e0 100644
>> --- a/tools/perf/util/srcline.c
>> +++ b/tools/perf/util/srcline.c
>> @@ -29,54 +29,6 @@ struct a2l_data {
>> asymbol **syms;
>> };
>>
>> -static int bfd_error(const char *string)
>> -{
>> - const char *errmsg;
>> -
>> - errmsg = bfd_errmsg(bfd_get_error());
>> - fflush(stdout);
>> -
>> - if (string)
>> - pr_debug("%s: %s\n", string, errmsg);
>> - else
>> - pr_debug("%s\n", errmsg);
>> -
>> - return -1;
>> -}
>> -
>> -static int slurp_symtab(bfd *abfd, struct a2l_data *a2l)
>> -{
>> - long storage;
>> - long symcount;
>> - asymbol **syms;
>> - bfd_boolean dynamic = FALSE;
>> -
>> - if ((bfd_get_file_flags(abfd) & HAS_SYMS) == 0)
>> - return bfd_error(bfd_get_filename(abfd));
>> -
>> - storage = bfd_get_symtab_upper_bound(abfd);
>> - if (storage == 0L) {
>> - storage = bfd_get_dynamic_symtab_upper_bound(abfd);
>> - dynamic = TRUE;
>> - }
>> - if (storage < 0L)
>> - return bfd_error(bfd_get_filename(abfd));
>> -
>> - syms = malloc(storage);
>> - if (dynamic)
>> - symcount = bfd_canonicalize_dynamic_symtab(abfd, syms);
>> - else
>> - symcount = bfd_canonicalize_symtab(abfd, syms);
>> -
>> - if (symcount < 0) {
>> - free(syms);
>> - return bfd_error(bfd_get_filename(abfd));
>> - }
>> -
>> - a2l->syms = syms;
>> - return 0;
>> -}
>> -
>> static void find_address_in_section(bfd *abfd, asection *section, void *data)
>> {
>> bfd_vma pc, vma;
>> @@ -96,7 +48,7 @@ static void find_address_in_section(bfd *abfd, asection *section, void *data)
>> if (pc < vma || pc >= vma + size)
>> return;
>>
>> - a2l->found = bfd_find_nearest_line(abfd, section, a2l->syms, pc - vma,
>> + a2l->found = bfd_find_nearest_line(abfd, section, NULL, pc - vma,
>> &a2l->filename, &a2l->funcname,
>> &a2l->line);
>> }
>> @@ -122,9 +74,6 @@ static struct a2l_data *addr2line_init(const char *path)
>> if (a2l->input == NULL)
>> goto out;
>>
>> - if (slurp_symtab(abfd, a2l))
>> - goto out;
>> -
>> return a2l;
>>
>> out:
>> --
>> 1.7.11.7
>
>
^ permalink raw reply [flat|nested] 21+ messages in thread* Re: [PATCH 6/7] perf tools: Do not need to read symbols for source line lookup
2013-12-04 14:00 ` Adrian Hunter
@ 2013-12-04 18:08 ` Arnaldo Carvalho de Melo
0 siblings, 0 replies; 21+ messages in thread
From: Arnaldo Carvalho de Melo @ 2013-12-04 18:08 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 Wed, Dec 04, 2013 at 04:00:18PM +0200, Adrian Hunter escreveu:
> On 03/12/13 22:24, Arnaldo Carvalho de Melo wrote:
> > Em Tue, Dec 03, 2013 at 09:23:09AM +0200, Adrian Hunter escreveu:
> >> When using libbfd to lookup source filename and line number,
> >> libbfd does not need the symbol table. Removing the symbol
> >> table reading, doubles the speed of 'perf script' with the
> >> 'srcline' option.
> >
> > [root@zoo ~]# gdb perf
> > run report -s srcline
> >
> > b00000m
>
> I wasn't able to reproduce this but I noticed the line numbers
> were not found for kernel modules with this patch - so it seems
> some binaries need the symbol information and some don't.
>
> So please disregard this patch, sorry for your trouble.
No problem, disregarding it.
- Arnaldo
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH 7/7] perf tools: Do not disable source line lookup just because of 1 failure
2013-12-03 7:23 [PATCH 0/7] perf script: Add an option to print the source line number Adrian Hunter
` (5 preceding siblings ...)
2013-12-03 7:23 ` [PATCH 6/7] perf tools: Do not need to read symbols for source line lookup Adrian Hunter
@ 2013-12-03 7:23 ` Adrian Hunter
2013-12-10 9:16 ` [tip:perf/core] " tip-bot for Adrian Hunter
6 siblings, 1 reply; 21+ messages in thread
From: Adrian Hunter @ 2013-12-03 7:23 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
Looking up an ip's source file name and line
number does not succeed always. Current logic
disables the lookup for a dso entirely on any
failure. Change it so that disabling never
happens if there has ever been a successful
lookup for that dso but disable if the first
123 lookups fail.
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
tools/perf/util/dso.c | 1 +
tools/perf/util/dso.h | 1 +
tools/perf/util/srcline.c | 20 ++++++++++++++++----
3 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index 49da968..a0c7c59 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -451,6 +451,7 @@ struct dso *dso__new(const char *name)
dso->sorted_by_name = 0;
dso->has_build_id = 0;
dso->has_srcline = 1;
+ dso->a2l_fails = 1;
dso->kernel = DSO_TYPE_USER;
dso->needs_swap = DSO_SWAP__UNSET;
INIT_LIST_HEAD(&dso->node);
diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h
index 7142e52..384f2d9 100644
--- a/tools/perf/util/dso.h
+++ b/tools/perf/util/dso.h
@@ -79,6 +79,7 @@ struct dso {
struct rb_root cache;
void *a2l;
char *symsrc_filename;
+ unsigned int a2l_fails;
enum dso_kernel_type kernel;
enum dso_swap_type needs_swap;
enum dso_binary_type symtab_type;
diff --git a/tools/perf/util/srcline.c b/tools/perf/util/srcline.c
index e09c9e0..d351d62 100644
--- a/tools/perf/util/srcline.c
+++ b/tools/perf/util/srcline.c
@@ -193,6 +193,12 @@ void dso__free_a2l(struct dso *dso __maybe_unused)
#endif /* HAVE_LIBBFD_SUPPORT */
+/*
+ * Number of addr2line failures (without success) before disabling it for that
+ * dso.
+ */
+#define A2L_FAIL_LIMIT 123
+
char *get_srcline(struct dso *dso, unsigned long addr)
{
char *file = NULL;
@@ -217,15 +223,21 @@ char *get_srcline(struct dso *dso, unsigned long addr)
if (!addr2line(dso_name, addr, &file, &line, dso))
goto out;
- if (asprintf(&srcline, "%s:%u", file, line) < 0)
- srcline = SRCLINE_UNKNOWN;
+ if (asprintf(&srcline, "%s:%u", file, line) < 0) {
+ free(file);
+ goto out;
+ }
+
+ dso->a2l_fails = 0;
free(file);
return srcline;
out:
- dso->has_srcline = 0;
- dso__free_a2l(dso);
+ if (dso->a2l_fails && ++dso->a2l_fails > A2L_FAIL_LIMIT) {
+ dso->has_srcline = 0;
+ dso__free_a2l(dso);
+ }
return SRCLINE_UNKNOWN;
}
--
1.7.11.7
^ permalink raw reply related [flat|nested] 21+ messages in thread* [tip:perf/core] perf tools: Do not disable source line lookup just because of 1 failure
2013-12-03 7:23 ` [PATCH 7/7] perf tools: Do not disable source line lookup just because of 1 failure Adrian Hunter
@ 2013-12-10 9:16 ` tip-bot for Adrian Hunter
0 siblings, 0 replies; 21+ messages in thread
From: tip-bot for Adrian Hunter @ 2013-12-10 9:16 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: 906049c8276eb99af997f73d602649a98e360035
Gitweb: http://git.kernel.org/tip/906049c8276eb99af997f73d602649a98e360035
Author: Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Tue, 3 Dec 2013 09:23:10 +0200
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 4 Dec 2013 13:46:36 -0300
perf tools: Do not disable source line lookup just because of 1 failure
Looking up an ip's source file name and line number does not succeed
always. Current logic disables the lookup for a dso entirely on any
failure. Change it so that disabling never happens if there has ever
been a successful lookup for that dso but disable if the first 123
lookups fail.
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/1386055390-13757-8-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/util/dso.c | 1 +
tools/perf/util/dso.h | 1 +
tools/perf/util/srcline.c | 20 ++++++++++++++++----
3 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index 49da968..a0c7c59 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -451,6 +451,7 @@ struct dso *dso__new(const char *name)
dso->sorted_by_name = 0;
dso->has_build_id = 0;
dso->has_srcline = 1;
+ dso->a2l_fails = 1;
dso->kernel = DSO_TYPE_USER;
dso->needs_swap = DSO_SWAP__UNSET;
INIT_LIST_HEAD(&dso->node);
diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h
index 7142e52..384f2d9 100644
--- a/tools/perf/util/dso.h
+++ b/tools/perf/util/dso.h
@@ -79,6 +79,7 @@ struct dso {
struct rb_root cache;
void *a2l;
char *symsrc_filename;
+ unsigned int a2l_fails;
enum dso_kernel_type kernel;
enum dso_swap_type needs_swap;
enum dso_binary_type symtab_type;
diff --git a/tools/perf/util/srcline.c b/tools/perf/util/srcline.c
index 93795f9..0c07556 100644
--- a/tools/perf/util/srcline.c
+++ b/tools/perf/util/srcline.c
@@ -244,6 +244,12 @@ void dso__free_a2l(struct dso *dso __maybe_unused)
#endif /* HAVE_LIBBFD_SUPPORT */
+/*
+ * Number of addr2line failures (without success) before disabling it for that
+ * dso.
+ */
+#define A2L_FAIL_LIMIT 123
+
char *get_srcline(struct dso *dso, unsigned long addr)
{
char *file = NULL;
@@ -268,15 +274,21 @@ char *get_srcline(struct dso *dso, unsigned long addr)
if (!addr2line(dso_name, addr, &file, &line, dso))
goto out;
- if (asprintf(&srcline, "%s:%u", file, line) < 0)
- srcline = SRCLINE_UNKNOWN;
+ if (asprintf(&srcline, "%s:%u", file, line) < 0) {
+ free(file);
+ goto out;
+ }
+
+ dso->a2l_fails = 0;
free(file);
return srcline;
out:
- dso->has_srcline = 0;
- dso__free_a2l(dso);
+ if (dso->a2l_fails && ++dso->a2l_fails > A2L_FAIL_LIMIT) {
+ dso->has_srcline = 0;
+ dso__free_a2l(dso);
+ }
return SRCLINE_UNKNOWN;
}
^ permalink raw reply related [flat|nested] 21+ messages in thread