aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2009-11-18 17:20:51 -0500
committerIngo Molnar <mingo@elte.hu>2009-11-19 02:28:12 -0500
commite30a3d12ddf04add3268bfceb0e57ffe47f254c6 (patch)
tree421a5726e0f7f87fff772efd7a83ce15c82ba859
parentd3379ab9050e5522da2aac53d413651fc06be562 (diff)
perf symbols: Kill struct build_id_list and die() another day
No need for this struct and its allocations, we can just use the ->build_id member we already have in struct dso, then ask for it to be read, and later traverse the dsos list, writing the buildid table to the perf.data file. As a bonus, one more die() function got killed. Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Frédéric Weisbecker <fweisbec@gmail.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Paul Mackerras <paulus@samba.org> LKML-Reference: <1258582853-8579-2-git-send-email-acme@infradead.org> Signed-off-by: Ingo Molnar <mingo@elte.hu>
-rw-r--r--tools/perf/util/event.h7
-rw-r--r--tools/perf/util/header.c31
-rw-r--r--tools/perf/util/symbol.c37
-rw-r--r--tools/perf/util/symbol.h2
4 files changed, 28 insertions, 49 deletions
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
index 1f771ce3a957..34c6fcb82d92 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -69,13 +69,6 @@ struct build_id_event {
69 char filename[]; 69 char filename[];
70}; 70};
71 71
72struct build_id_list {
73 struct build_id_event event;
74 struct list_head list;
75 const char *dso_name;
76 int len;
77};
78
79typedef union event_union { 72typedef union event_union {
80 struct perf_event_header header; 73 struct perf_event_header header;
81 struct ip_event ip; 74 struct ip_event ip;
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index b01a9537977f..31731f1606b2 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -176,18 +176,24 @@ static int do_write(int fd, const void *buf, size_t size)
176 return 0; 176 return 0;
177} 177}
178 178
179static int write_buildid_table(int fd, struct list_head *id_head) 179static int dsos__write_buildid_table(int fd)
180{ 180{
181 struct build_id_list *iter, *next; 181 struct dso *pos;
182 182
183 list_for_each_entry_safe(iter, next, id_head, list) { 183 list_for_each_entry(pos, &dsos, node) {
184 struct build_id_event *b = &iter->event; 184 struct build_id_event b;
185 185 size_t len;
186 if (do_write(fd, b, sizeof(*b)) < 0 || 186
187 do_write(fd, iter->dso_name, iter->len) < 0) 187 if (!pos->has_build_id)
188 continue;
189 len = pos->long_name_len + 1;
190 len = ALIGN(len, 64);
191 memset(&b, 0, sizeof(b));
192 memcpy(&b.build_id, pos->build_id, sizeof(pos->build_id));
193 b.header.size = sizeof(b) + len;
194 if (do_write(fd, &b, sizeof(b)) < 0 ||
195 do_write(fd, pos->long_name, len) < 0)
188 return -1; 196 return -1;
189 list_del(&iter->list);
190 free(iter);
191 } 197 }
192 198
193 return 0; 199 return 0;
@@ -196,14 +202,13 @@ static int write_buildid_table(int fd, struct list_head *id_head)
196static void 202static void
197perf_header__adds_write(struct perf_header *self, int fd) 203perf_header__adds_write(struct perf_header *self, int fd)
198{ 204{
199 LIST_HEAD(id_list);
200 int nr_sections; 205 int nr_sections;
201 struct perf_file_section *feat_sec; 206 struct perf_file_section *feat_sec;
202 int sec_size; 207 int sec_size;
203 u64 sec_start; 208 u64 sec_start;
204 int idx = 0; 209 int idx = 0;
205 210
206 if (fetch_build_id_table(&id_list)) 211 if (dsos__read_build_ids())
207 perf_header__set_feat(self, HEADER_BUILD_ID); 212 perf_header__set_feat(self, HEADER_BUILD_ID);
208 213
209 nr_sections = bitmap_weight(self->adds_features, HEADER_FEAT_BITS); 214 nr_sections = bitmap_weight(self->adds_features, HEADER_FEAT_BITS);
@@ -238,7 +243,7 @@ perf_header__adds_write(struct perf_header *self, int fd)
238 243
239 /* Write build-ids */ 244 /* Write build-ids */
240 buildid_sec->offset = lseek(fd, 0, SEEK_CUR); 245 buildid_sec->offset = lseek(fd, 0, SEEK_CUR);
241 if (write_buildid_table(fd, &id_list) < 0) 246 if (dsos__write_buildid_table(fd) < 0)
242 die("failed to write buildid table"); 247 die("failed to write buildid table");
243 buildid_sec->size = lseek(fd, 0, SEEK_CUR) - buildid_sec->offset; 248 buildid_sec->size = lseek(fd, 0, SEEK_CUR) - buildid_sec->offset;
244 } 249 }
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 594f36a1da8f..946ec319568b 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -883,38 +883,19 @@ out_close:
883 return err; 883 return err;
884} 884}
885 885
886bool fetch_build_id_table(struct list_head *head) 886bool dsos__read_build_ids(void)
887{ 887{
888 bool have_buildid = false; 888 bool have_build_id = false;
889 struct dso *pos; 889 struct dso *pos;
890 890
891 list_for_each_entry(pos, &dsos, node) { 891 list_for_each_entry(pos, &dsos, node)
892 struct build_id_list *new; 892 if (filename__read_build_id(pos->long_name, pos->build_id,
893 struct build_id_event b; 893 sizeof(pos->build_id)) > 0) {
894 size_t len; 894 have_build_id = true;
895 895 pos->has_build_id = true;
896 if (filename__read_build_id(pos->long_name, 896 }
897 &b.build_id,
898 sizeof(b.build_id)) < 0)
899 continue;
900 have_buildid = true;
901 memset(&b.header, 0, sizeof(b.header));
902 len = pos->long_name_len + 1;
903 len = ALIGN(len, 64);
904 b.header.size = sizeof(b) + len;
905
906 new = malloc(sizeof(*new));
907 if (!new)
908 die("No memory\n");
909
910 memcpy(&new->event, &b, sizeof(b));
911 new->dso_name = pos->long_name;
912 new->len = len;
913
914 list_add_tail(&new->list, head);
915 }
916 897
917 return have_buildid; 898 return have_build_id;
918} 899}
919 900
920int filename__read_build_id(const char *filename, void *bf, size_t size) 901int filename__read_build_id(const char *filename, void *bf, size_t size)
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
index 5ad1019607dd..546eb766d81e 100644
--- a/tools/perf/util/symbol.h
+++ b/tools/perf/util/symbol.h
@@ -89,7 +89,7 @@ char dso__symtab_origin(const struct dso *self);
89void dso__set_build_id(struct dso *self, void *build_id); 89void dso__set_build_id(struct dso *self, void *build_id);
90 90
91int filename__read_build_id(const char *filename, void *bf, size_t size); 91int filename__read_build_id(const char *filename, void *bf, size_t size);
92bool fetch_build_id_table(struct list_head *head); 92bool dsos__read_build_ids(void);
93int build_id__sprintf(u8 *self, int len, char *bf); 93int build_id__sprintf(u8 *self, int len, char *bf);
94 94
95int load_kernel(symbol_filter_t filter); 95int load_kernel(symbol_filter_t filter);