aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2009-05-28 13:55:26 -0400
committerIngo Molnar <mingo@elte.hu>2009-05-28 17:25:44 -0400
commit69ee69f63c82e63d9c6c6081d12673af4933c51e (patch)
treef96e4dd66b6d1261cccad46ac09e6f1180760c4b /Documentation
parenta827c875f2ebe69c6e6db5e7f112d4beb4d80f01 (diff)
perf_counter tools: Optionally pass a symbol filter to the dso load routines
Will be used by perf top. Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Mike Galbraith <efault@gmx.de> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> LKML-Reference: <20090528175526.GF4747@ghostprotocols.net> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'Documentation')
-rw-r--r--Documentation/perf_counter/builtin-report.c4
-rw-r--r--Documentation/perf_counter/util/symbol.c34
-rw-r--r--Documentation/perf_counter/util/symbol.h7
3 files changed, 28 insertions, 17 deletions
diff --git a/Documentation/perf_counter/builtin-report.c b/Documentation/perf_counter/builtin-report.c
index 4e9f2bc10452..412d524dd658 100644
--- a/Documentation/perf_counter/builtin-report.c
+++ b/Documentation/perf_counter/builtin-report.c
@@ -87,7 +87,7 @@ static struct dso *dsos__findnew(const char *name)
87 if (!dso) 87 if (!dso)
88 goto out_delete_dso; 88 goto out_delete_dso;
89 89
90 nr = dso__load(dso); 90 nr = dso__load(dso, NULL);
91 if (nr < 0) { 91 if (nr < 0) {
92 fprintf(stderr, "Failed to open: %s\n", name); 92 fprintf(stderr, "Failed to open: %s\n", name);
93 goto out_delete_dso; 93 goto out_delete_dso;
@@ -124,7 +124,7 @@ static int load_kernel(void)
124 if (!kernel_dso) 124 if (!kernel_dso)
125 return -1; 125 return -1;
126 126
127 err = dso__load_kernel(kernel_dso, vmlinux); 127 err = dso__load_kernel(kernel_dso, vmlinux, NULL);
128 if (err) { 128 if (err) {
129 dso__delete(kernel_dso); 129 dso__delete(kernel_dso);
130 kernel_dso = NULL; 130 kernel_dso = NULL;
diff --git a/Documentation/perf_counter/util/symbol.c b/Documentation/perf_counter/util/symbol.c
index 504ac3132019..47281210443d 100644
--- a/Documentation/perf_counter/util/symbol.c
+++ b/Documentation/perf_counter/util/symbol.c
@@ -155,7 +155,7 @@ static int hex2long(char *ptr, unsigned long *long_val)
155 return p - ptr; 155 return p - ptr;
156} 156}
157 157
158static int dso__load_kallsyms(struct dso *self) 158static int dso__load_kallsyms(struct dso *self, symbol_filter_t filter)
159{ 159{
160 struct rb_node *nd, *prevnd; 160 struct rb_node *nd, *prevnd;
161 char *line = NULL; 161 char *line = NULL;
@@ -201,7 +201,10 @@ static int dso__load_kallsyms(struct dso *self)
201 if (sym == NULL) 201 if (sym == NULL)
202 goto out_delete_line; 202 goto out_delete_line;
203 203
204 dso__insert_symbol(self, sym); 204 if (filter && filter(self, sym))
205 symbol__delete(sym, self->sym_priv_size);
206 else
207 dso__insert_symbol(self, sym);
205 } 208 }
206 209
207 /* 210 /*
@@ -286,7 +289,8 @@ static Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep,
286 return sec; 289 return sec;
287} 290}
288 291
289static int dso__load_sym(struct dso *self, int fd, const char *name) 292static int dso__load_sym(struct dso *self, int fd, const char *name,
293 symbol_filter_t filter)
290{ 294{
291 Elf_Data *symstrs; 295 Elf_Data *symstrs;
292 uint32_t nr_syms; 296 uint32_t nr_syms;
@@ -352,9 +356,12 @@ static int dso__load_sym(struct dso *self, int fd, const char *name)
352 if (!f) 356 if (!f)
353 goto out_elf_end; 357 goto out_elf_end;
354 358
355 dso__insert_symbol(self, f); 359 if (filter && filter(self, f))
356 360 symbol__delete(f, self->sym_priv_size);
357 nr++; 361 else {
362 dso__insert_symbol(self, f);
363 nr++;
364 }
358 } 365 }
359 366
360 err = nr; 367 err = nr;
@@ -364,7 +371,7 @@ out_close:
364 return err; 371 return err;
365} 372}
366 373
367int dso__load(struct dso *self) 374int dso__load(struct dso *self, symbol_filter_t filter)
368{ 375{
369 int size = strlen(self->name) + sizeof("/usr/lib/debug%s.debug"); 376 int size = strlen(self->name) + sizeof("/usr/lib/debug%s.debug");
370 char *name = malloc(size); 377 char *name = malloc(size);
@@ -396,7 +403,7 @@ more:
396 fd = open(name, O_RDONLY); 403 fd = open(name, O_RDONLY);
397 } while (fd < 0); 404 } while (fd < 0);
398 405
399 ret = dso__load_sym(self, fd, name); 406 ret = dso__load_sym(self, fd, name, filter);
400 close(fd); 407 close(fd);
401 408
402 /* 409 /*
@@ -410,28 +417,29 @@ out:
410 return ret; 417 return ret;
411} 418}
412 419
413static int dso__load_vmlinux(struct dso *self, const char *vmlinux) 420static int dso__load_vmlinux(struct dso *self, const char *vmlinux,
421 symbol_filter_t filter)
414{ 422{
415 int err, fd = open(vmlinux, O_RDONLY); 423 int err, fd = open(vmlinux, O_RDONLY);
416 424
417 if (fd < 0) 425 if (fd < 0)
418 return -1; 426 return -1;
419 427
420 err = dso__load_sym(self, fd, vmlinux); 428 err = dso__load_sym(self, fd, vmlinux, filter);
421 close(fd); 429 close(fd);
422 430
423 return err; 431 return err;
424} 432}
425 433
426int dso__load_kernel(struct dso *self, const char *vmlinux) 434int dso__load_kernel(struct dso *self, const char *vmlinux, symbol_filter_t filter)
427{ 435{
428 int err = -1; 436 int err = -1;
429 437
430 if (vmlinux) 438 if (vmlinux)
431 err = dso__load_vmlinux(self, vmlinux); 439 err = dso__load_vmlinux(self, vmlinux, filter);
432 440
433 if (err) 441 if (err)
434 err = dso__load_kallsyms(self); 442 err = dso__load_kallsyms(self, filter);
435 443
436 return err; 444 return err;
437} 445}
diff --git a/Documentation/perf_counter/util/symbol.h b/Documentation/perf_counter/util/symbol.h
index db2fdf9f70a2..b0299bc0cf50 100644
--- a/Documentation/perf_counter/util/symbol.h
+++ b/Documentation/perf_counter/util/symbol.h
@@ -19,6 +19,8 @@ struct dso {
19 char name[0]; 19 char name[0];
20}; 20};
21 21
22typedef int (*symbol_filter_t)(struct dso *self, struct symbol *sym);
23
22struct dso *dso__new(const char *name, unsigned int sym_priv_size); 24struct dso *dso__new(const char *name, unsigned int sym_priv_size);
23void dso__delete(struct dso *self); 25void dso__delete(struct dso *self);
24 26
@@ -29,8 +31,9 @@ static inline void *dso__sym_priv(struct dso *self, struct symbol *sym)
29 31
30struct symbol *dso__find_symbol(struct dso *self, uint64_t ip); 32struct symbol *dso__find_symbol(struct dso *self, uint64_t ip);
31 33
32int dso__load_kernel(struct dso *self, const char *vmlinux); 34int dso__load_kernel(struct dso *self, const char *vmlinux,
33int dso__load(struct dso *self); 35 symbol_filter_t filter);
36int dso__load(struct dso *self, symbol_filter_t filter);
34 37
35size_t dso__fprintf(struct dso *self, FILE *fp); 38size_t dso__fprintf(struct dso *self, FILE *fp);
36 39