aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/symbol.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2009-10-30 14:28:24 -0400
committerIngo Molnar <mingo@elte.hu>2009-11-02 10:52:11 -0500
commit00a192b395b0606ad0265243844b3cd68e73420a (patch)
tree09149f550807c365f170c857b1021d66e5bb8b4b /tools/perf/util/symbol.c
parentafb7b4f08e274cecd8337f9444affa288a9cd4c1 (diff)
perf tools: Simplify the symbol priv area mechanism
Before we were storing this in the DSO, but in fact this is a property of the 'symbol' class, not something that will vary among DSOs, so move it to a global variable and initialize it using the existing symbol__init routine. Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Mike Galbraith <efault@gmx.de> LKML-Reference: <1256927305-4628-2-git-send-email-acme@infradead.org> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools/perf/util/symbol.c')
-rw-r--r--tools/perf/util/symbol.c73
1 files changed, 34 insertions, 39 deletions
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 13677b5dbe5e..cf2c7f778868 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -26,6 +26,7 @@ static void dsos__add(struct dso *dso);
26static struct dso *dsos__find(const char *name); 26static struct dso *dsos__find(const char *name);
27static struct map *map__new2(u64 start, struct dso *dso); 27static struct map *map__new2(u64 start, struct dso *dso);
28static void kernel_maps__insert(struct map *map); 28static void kernel_maps__insert(struct map *map);
29unsigned int symbol__priv_size;
29 30
30static struct rb_root kernel_maps; 31static struct rb_root kernel_maps;
31 32
@@ -75,18 +76,17 @@ static void kernel_maps__fixup_end(void)
75 } 76 }
76} 77}
77 78
78static struct symbol *symbol__new(u64 start, u64 len, const char *name, 79static struct symbol *symbol__new(u64 start, u64 len, const char *name)
79 unsigned int priv_size)
80{ 80{
81 size_t namelen = strlen(name) + 1; 81 size_t namelen = strlen(name) + 1;
82 struct symbol *self = calloc(1, priv_size + sizeof(*self) + namelen); 82 struct symbol *self = calloc(1, (symbol__priv_size +
83 83 sizeof(*self) + namelen));
84 if (!self) 84 if (!self)
85 return NULL; 85 return NULL;
86 86
87 if (priv_size) { 87 if (symbol__priv_size) {
88 memset(self, 0, priv_size); 88 memset(self, 0, symbol__priv_size);
89 self = ((void *)self) + priv_size; 89 self = ((void *)self) + symbol__priv_size;
90 } 90 }
91 self->start = start; 91 self->start = start;
92 self->end = len ? start + len - 1 : start; 92 self->end = len ? start + len - 1 : start;
@@ -98,9 +98,9 @@ static struct symbol *symbol__new(u64 start, u64 len, const char *name,
98 return self; 98 return self;
99} 99}
100 100
101static void symbol__delete(struct symbol *self, unsigned int priv_size) 101static void symbol__delete(struct symbol *self)
102{ 102{
103 free(((void *)self) - priv_size); 103 free(((void *)self) - symbol__priv_size);
104} 104}
105 105
106static size_t symbol__fprintf(struct symbol *self, FILE *fp) 106static size_t symbol__fprintf(struct symbol *self, FILE *fp)
@@ -109,7 +109,7 @@ static size_t symbol__fprintf(struct symbol *self, FILE *fp)
109 self->start, self->end, self->name); 109 self->start, self->end, self->name);
110} 110}
111 111
112struct dso *dso__new(const char *name, unsigned int sym_priv_size) 112struct dso *dso__new(const char *name)
113{ 113{
114 struct dso *self = malloc(sizeof(*self) + strlen(name) + 1); 114 struct dso *self = malloc(sizeof(*self) + strlen(name) + 1);
115 115
@@ -118,7 +118,6 @@ struct dso *dso__new(const char *name, unsigned int sym_priv_size)
118 self->long_name = self->name; 118 self->long_name = self->name;
119 self->short_name = self->name; 119 self->short_name = self->name;
120 self->syms = RB_ROOT; 120 self->syms = RB_ROOT;
121 self->sym_priv_size = sym_priv_size;
122 self->find_symbol = dso__find_symbol; 121 self->find_symbol = dso__find_symbol;
123 self->slen_calculated = 0; 122 self->slen_calculated = 0;
124 self->origin = DSO__ORIG_NOT_FOUND; 123 self->origin = DSO__ORIG_NOT_FOUND;
@@ -136,7 +135,7 @@ static void dso__delete_symbols(struct dso *self)
136 pos = rb_entry(next, struct symbol, rb_node); 135 pos = rb_entry(next, struct symbol, rb_node);
137 next = rb_next(&pos->rb_node); 136 next = rb_next(&pos->rb_node);
138 rb_erase(&pos->rb_node, &self->syms); 137 rb_erase(&pos->rb_node, &self->syms);
139 symbol__delete(pos, self->sym_priv_size); 138 symbol__delete(pos);
140 } 139 }
141} 140}
142 141
@@ -250,8 +249,7 @@ static int kernel_maps__load_all_kallsyms(void)
250 /* 249 /*
251 * Will fix up the end later, when we have all symbols sorted. 250 * Will fix up the end later, when we have all symbols sorted.
252 */ 251 */
253 sym = symbol__new(start, 0, symbol_name, 252 sym = symbol__new(start, 0, symbol_name);
254 kernel_map->dso->sym_priv_size);
255 253
256 if (sym == NULL) 254 if (sym == NULL)
257 goto out_delete_line; 255 goto out_delete_line;
@@ -317,8 +315,7 @@ static int kernel_maps__split_kallsyms(symbol_filter_t filter, int use_modules)
317 snprintf(dso_name, sizeof(dso_name), "[kernel].%d", 315 snprintf(dso_name, sizeof(dso_name), "[kernel].%d",
318 kernel_range++); 316 kernel_range++);
319 317
320 dso = dso__new(dso_name, 318 dso = dso__new(dso_name);
321 kernel_map->dso->sym_priv_size);
322 if (dso == NULL) 319 if (dso == NULL)
323 return -1; 320 return -1;
324 321
@@ -336,7 +333,7 @@ static int kernel_maps__split_kallsyms(symbol_filter_t filter, int use_modules)
336 if (filter && filter(map, pos)) { 333 if (filter && filter(map, pos)) {
337delete_symbol: 334delete_symbol:
338 rb_erase(&pos->rb_node, &kernel_map->dso->syms); 335 rb_erase(&pos->rb_node, &kernel_map->dso->syms);
339 symbol__delete(pos, kernel_map->dso->sym_priv_size); 336 symbol__delete(pos);
340 } else { 337 } else {
341 if (map != kernel_map) { 338 if (map != kernel_map) {
342 rb_erase(&pos->rb_node, &kernel_map->dso->syms); 339 rb_erase(&pos->rb_node, &kernel_map->dso->syms);
@@ -417,14 +414,13 @@ static int dso__load_perf_map(struct dso *self, struct map *map,
417 if (len + 2 >= line_len) 414 if (len + 2 >= line_len)
418 continue; 415 continue;
419 416
420 sym = symbol__new(start, size, line + len, 417 sym = symbol__new(start, size, line + len);
421 self->sym_priv_size);
422 418
423 if (sym == NULL) 419 if (sym == NULL)
424 goto out_delete_line; 420 goto out_delete_line;
425 421
426 if (filter && filter(map, sym)) 422 if (filter && filter(map, sym))
427 symbol__delete(sym, self->sym_priv_size); 423 symbol__delete(sym);
428 else { 424 else {
429 dso__insert_symbol(self, sym); 425 dso__insert_symbol(self, sym);
430 nr_syms++; 426 nr_syms++;
@@ -616,7 +612,7 @@ static int dso__synthesize_plt_symbols(struct dso *self)
616 "%s@plt", elf_sym__name(&sym, symstrs)); 612 "%s@plt", elf_sym__name(&sym, symstrs));
617 613
618 f = symbol__new(plt_offset, shdr_plt.sh_entsize, 614 f = symbol__new(plt_offset, shdr_plt.sh_entsize,
619 sympltname, self->sym_priv_size); 615 sympltname);
620 if (!f) 616 if (!f)
621 goto out_elf_end; 617 goto out_elf_end;
622 618
@@ -634,7 +630,7 @@ static int dso__synthesize_plt_symbols(struct dso *self)
634 "%s@plt", elf_sym__name(&sym, symstrs)); 630 "%s@plt", elf_sym__name(&sym, symstrs));
635 631
636 f = symbol__new(plt_offset, shdr_plt.sh_entsize, 632 f = symbol__new(plt_offset, shdr_plt.sh_entsize,
637 sympltname, self->sym_priv_size); 633 sympltname);
638 if (!f) 634 if (!f)
639 goto out_elf_end; 635 goto out_elf_end;
640 636
@@ -769,7 +765,7 @@ static int dso__load_sym(struct dso *self, struct map *map, const char *name,
769 if (kmodule) 765 if (kmodule)
770 start += map->start + shdr.sh_offset; 766 start += map->start + shdr.sh_offset;
771 767
772 curr_dso = dso__new(dso_name, self->sym_priv_size); 768 curr_dso = dso__new(dso_name);
773 if (curr_dso == NULL) 769 if (curr_dso == NULL)
774 goto out_elf_end; 770 goto out_elf_end;
775 curr_map = map__new2(start, curr_dso); 771 curr_map = map__new2(start, curr_dso);
@@ -803,14 +799,13 @@ static int dso__load_sym(struct dso *self, struct map *map, const char *name,
803 if (demangled != NULL) 799 if (demangled != NULL)
804 elf_name = demangled; 800 elf_name = demangled;
805new_symbol: 801new_symbol:
806 f = symbol__new(sym.st_value, sym.st_size, elf_name, 802 f = symbol__new(sym.st_value, sym.st_size, elf_name);
807 curr_dso->sym_priv_size);
808 free(demangled); 803 free(demangled);
809 if (!f) 804 if (!f)
810 goto out_elf_end; 805 goto out_elf_end;
811 806
812 if (filter && filter(curr_map, f)) 807 if (filter && filter(curr_map, f))
813 symbol__delete(f, curr_dso->sym_priv_size); 808 symbol__delete(f);
814 else { 809 else {
815 dso__insert_symbol(curr_dso, f); 810 dso__insert_symbol(curr_dso, f);
816 nr++; 811 nr++;
@@ -1141,7 +1136,7 @@ static struct map *map__new2(u64 start, struct dso *dso)
1141 return self; 1136 return self;
1142} 1137}
1143 1138
1144static int dsos__load_modules(unsigned int sym_priv_size) 1139static int dsos__load_modules(void)
1145{ 1140{
1146 char *line = NULL; 1141 char *line = NULL;
1147 size_t n; 1142 size_t n;
@@ -1180,7 +1175,7 @@ static int dsos__load_modules(unsigned int sym_priv_size)
1180 *sep = '\0'; 1175 *sep = '\0';
1181 1176
1182 snprintf(name, sizeof(name), "[%s]", line); 1177 snprintf(name, sizeof(name), "[%s]", line);
1183 dso = dso__new(name, sym_priv_size); 1178 dso = dso__new(name);
1184 1179
1185 if (dso == NULL) 1180 if (dso == NULL)
1186 goto out_delete_line; 1181 goto out_delete_line;
@@ -1224,11 +1219,11 @@ static int dso__load_vmlinux(struct dso *self, struct map *map,
1224 return err; 1219 return err;
1225} 1220}
1226 1221
1227int dsos__load_kernel(const char *vmlinux, unsigned int sym_priv_size, 1222int dsos__load_kernel(const char *vmlinux, symbol_filter_t filter,
1228 symbol_filter_t filter, int use_modules) 1223 int use_modules)
1229{ 1224{
1230 int err = -1; 1225 int err = -1;
1231 struct dso *dso = dso__new(vmlinux, sym_priv_size); 1226 struct dso *dso = dso__new(vmlinux);
1232 1227
1233 if (dso == NULL) 1228 if (dso == NULL)
1234 return -1; 1229 return -1;
@@ -1240,7 +1235,7 @@ int dsos__load_kernel(const char *vmlinux, unsigned int sym_priv_size,
1240 1235
1241 kernel_map->map_ip = kernel_map->unmap_ip = identity__map_ip; 1236 kernel_map->map_ip = kernel_map->unmap_ip = identity__map_ip;
1242 1237
1243 if (use_modules && dsos__load_modules(sym_priv_size) < 0) { 1238 if (use_modules && dsos__load_modules() < 0) {
1244 pr_warning("Failed to load list of modules in use! " 1239 pr_warning("Failed to load list of modules in use! "
1245 "Continuing...\n"); 1240 "Continuing...\n");
1246 use_modules = 0; 1241 use_modules = 0;
@@ -1312,12 +1307,12 @@ static struct dso *dsos__find(const char *name)
1312 return NULL; 1307 return NULL;
1313} 1308}
1314 1309
1315struct dso *dsos__findnew(const char *name, unsigned int sym_priv_size) 1310struct dso *dsos__findnew(const char *name)
1316{ 1311{
1317 struct dso *dso = dsos__find(name); 1312 struct dso *dso = dsos__find(name);
1318 1313
1319 if (!dso) { 1314 if (!dso) {
1320 dso = dso__new(name, sym_priv_size); 1315 dso = dso__new(name);
1321 if (dso != NULL) 1316 if (dso != NULL)
1322 dsos__add(dso); 1317 dsos__add(dso);
1323 } 1318 }
@@ -1333,13 +1328,12 @@ void dsos__fprintf(FILE *fp)
1333 dso__fprintf(pos, fp); 1328 dso__fprintf(pos, fp);
1334} 1329}
1335 1330
1336int load_kernel(unsigned int sym_priv_size, symbol_filter_t filter) 1331int load_kernel(symbol_filter_t filter)
1337{ 1332{
1338 if (dsos__load_kernel(vmlinux_name, sym_priv_size, filter, 1333 if (dsos__load_kernel(vmlinux_name, filter, modules) <= 0)
1339 modules) <= 0)
1340 return -1; 1334 return -1;
1341 1335
1342 vdso = dso__new("[vdso]", 0); 1336 vdso = dso__new("[vdso]");
1343 if (!vdso) 1337 if (!vdso)
1344 return -1; 1338 return -1;
1345 1339
@@ -1348,7 +1342,8 @@ int load_kernel(unsigned int sym_priv_size, symbol_filter_t filter)
1348 return 0; 1342 return 0;
1349} 1343}
1350 1344
1351void symbol__init(void) 1345void symbol__init(unsigned int priv_size)
1352{ 1346{
1353 elf_version(EV_CURRENT); 1347 elf_version(EV_CURRENT);
1348 symbol__priv_size = priv_size;
1354} 1349}