Skip to content

Commit 454ff00

Browse files
ahunter6acmel
authored andcommitted
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>
1 parent d88938e commit 454ff00

3 files changed

Lines changed: 34 additions & 6 deletions

File tree

‎tools/perf/util/dso.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ void dso__delete(struct dso *dso)
469469
if (dso->lname_alloc)
470470
free(dso->long_name);
471471
dso_cache__free(&dso->cache);
472+
dso__free_a2l(dso);
472473
free(dso);
473474
}
474475

‎tools/perf/util/dso.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ struct dso {
7777
struct rb_root symbols[MAP__NR_TYPES];
7878
struct rb_root symbol_names[MAP__NR_TYPES];
7979
struct rb_root cache;
80+
void *a2l;
8081
enum dso_kernel_type kernel;
8182
enum dso_swap_type needs_swap;
8283
enum dso_binary_type symtab_type;
@@ -166,4 +167,6 @@ static inline bool dso__is_kcore(struct dso *dso)
166167
dso->data_type == DSO_BINARY_TYPE__GUEST_KCORE;
167168
}
168169

170+
void dso__free_a2l(struct dso *dso);
171+
169172
#endif /* __PERF_DSO */

‎tools/perf/util/srcline.c‎

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,18 +146,24 @@ static void addr2line_cleanup(struct a2l_data *a2l)
146146
}
147147

148148
static int addr2line(const char *dso_name, unsigned long addr,
149-
char **file, unsigned int *line)
149+
char **file, unsigned int *line, struct dso *dso)
150150
{
151151
int ret = 0;
152-
struct a2l_data *a2l;
152+
struct a2l_data *a2l = dso->a2l;
153+
154+
if (!a2l) {
155+
dso->a2l = addr2line_init(dso_name);
156+
a2l = dso->a2l;
157+
}
153158

154-
a2l = addr2line_init(dso_name);
155159
if (a2l == NULL) {
156160
pr_warning("addr2line_init failed for %s\n", dso_name);
157161
return 0;
158162
}
159163

160164
a2l->addr = addr;
165+
a2l->found = false;
166+
161167
bfd_map_over_sections(a2l->abfd, find_address_in_section, a2l);
162168

163169
if (a2l->found && a2l->filename) {
@@ -168,14 +174,26 @@ static int addr2line(const char *dso_name, unsigned long addr,
168174
ret = 1;
169175
}
170176

171-
addr2line_cleanup(a2l);
172177
return ret;
173178
}
174179

180+
void dso__free_a2l(struct dso *dso)
181+
{
182+
struct a2l_data *a2l = dso->a2l;
183+
184+
if (!a2l)
185+
return;
186+
187+
addr2line_cleanup(a2l);
188+
189+
dso->a2l = NULL;
190+
}
191+
175192
#else /* HAVE_LIBBFD_SUPPORT */
176193

177194
static int addr2line(const char *dso_name, unsigned long addr,
178-
char **file, unsigned int *line_nr)
195+
char **file, unsigned int *line_nr,
196+
struct dso *dso __maybe_unused)
179197
{
180198
FILE *fp;
181199
char cmd[PATH_MAX];
@@ -219,6 +237,11 @@ static int addr2line(const char *dso_name, unsigned long addr,
219237
pclose(fp);
220238
return ret;
221239
}
240+
241+
void dso__free_a2l(struct dso *dso __maybe_unused)
242+
{
243+
}
244+
222245
#endif /* HAVE_LIBBFD_SUPPORT */
223246

224247
char *get_srcline(struct dso *dso, unsigned long addr)
@@ -237,7 +260,7 @@ char *get_srcline(struct dso *dso, unsigned long addr)
237260
if (!strncmp(dso_name, "/tmp/perf-", 10))
238261
goto out;
239262

240-
if (!addr2line(dso_name, addr, &file, &line))
263+
if (!addr2line(dso_name, addr, &file, &line, dso))
241264
goto out;
242265

243266
if (asprintf(&srcline, "%s:%u", file, line) < 0)
@@ -248,6 +271,7 @@ char *get_srcline(struct dso *dso, unsigned long addr)
248271

249272
out:
250273
dso->has_srcline = 0;
274+
dso__free_a2l(dso);
251275
return SRCLINE_UNKNOWN;
252276
}
253277

0 commit comments

Comments
 (0)