perf symbols: Kill struct build_id_list and die() another day
authorArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 18 Nov 2009 22:20:51 +0000 (20:20 -0200)
committerIngo Molnar <mingo@elte.hu>
Thu, 19 Nov 2009 07:28:12 +0000 (08:28 +0100)
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>
tools/perf/util/event.h
tools/perf/util/header.c
tools/perf/util/symbol.c
tools/perf/util/symbol.h

index 1f771ce3a95793c29abf14106e91408d86f319d6..34c6fcb82d927757058f249982e3215ca962e8d4 100644 (file)
@@ -69,13 +69,6 @@ struct build_id_event {
        char                     filename[];
 };
 
-struct build_id_list {
-       struct build_id_event   event;
-       struct list_head        list;
-       const char              *dso_name;
-       int                     len;
-};
-
 typedef union event_union {
        struct perf_event_header        header;
        struct ip_event                 ip;
index b01a9537977f41a57e7c61e803ff74bcdd58d4e9..31731f1606b21743516bb25156a031772eb7a2b3 100644 (file)
@@ -176,18 +176,24 @@ static int do_write(int fd, const void *buf, size_t size)
        return 0;
 }
 
-static int write_buildid_table(int fd, struct list_head *id_head)
+static int dsos__write_buildid_table(int fd)
 {
-       struct build_id_list *iter, *next;
-
-       list_for_each_entry_safe(iter, next, id_head, list) {
-               struct build_id_event *b = &iter->event;
-
-               if (do_write(fd, b, sizeof(*b)) < 0 ||
-                   do_write(fd, iter->dso_name, iter->len) < 0)
+       struct dso *pos;
+
+       list_for_each_entry(pos, &dsos, node) {
+               struct build_id_event b;
+               size_t len;
+
+               if (!pos->has_build_id)
+                       continue;
+               len = pos->long_name_len + 1;
+               len = ALIGN(len, 64);
+               memset(&b, 0, sizeof(b));
+               memcpy(&b.build_id, pos->build_id, sizeof(pos->build_id));
+               b.header.size = sizeof(b) + len;
+               if (do_write(fd, &b, sizeof(b)) < 0 ||
+                   do_write(fd, pos->long_name, len) < 0)
                        return -1;
-               list_del(&iter->list);
-               free(iter);
        }
 
        return 0;
@@ -196,14 +202,13 @@ static int write_buildid_table(int fd, struct list_head *id_head)
 static void
 perf_header__adds_write(struct perf_header *self, int fd)
 {
-       LIST_HEAD(id_list);
        int nr_sections;
        struct perf_file_section *feat_sec;
        int sec_size;
        u64 sec_start;
        int idx = 0;
 
-       if (fetch_build_id_table(&id_list))
+       if (dsos__read_build_ids())
                perf_header__set_feat(self, HEADER_BUILD_ID);
 
        nr_sections = bitmap_weight(self->adds_features, HEADER_FEAT_BITS);
@@ -238,7 +243,7 @@ perf_header__adds_write(struct perf_header *self, int fd)
 
                /* Write build-ids */
                buildid_sec->offset = lseek(fd, 0, SEEK_CUR);
-               if (write_buildid_table(fd, &id_list) < 0)
+               if (dsos__write_buildid_table(fd) < 0)
                        die("failed to write buildid table");
                buildid_sec->size = lseek(fd, 0, SEEK_CUR) - buildid_sec->offset;
        }
index 594f36a1da8f4f4625559fcd86049b990d654dda..946ec319568b8aa65c7e58103f3aa78416851823 100644 (file)
@@ -883,38 +883,19 @@ out_close:
        return err;
 }
 
-bool fetch_build_id_table(struct list_head *head)
+bool dsos__read_build_ids(void)
 {
-       bool have_buildid = false;
+       bool have_build_id = false;
        struct dso *pos;
 
-       list_for_each_entry(pos, &dsos, node) {
-               struct build_id_list *new;
-               struct build_id_event b;
-               size_t len;
-
-               if (filename__read_build_id(pos->long_name,
-                                           &b.build_id,
-                                           sizeof(b.build_id)) < 0)
-                       continue;
-               have_buildid = true;
-               memset(&b.header, 0, sizeof(b.header));
-               len = pos->long_name_len + 1;
-               len = ALIGN(len, 64);
-               b.header.size = sizeof(b) + len;
-
-               new = malloc(sizeof(*new));
-               if (!new)
-                       die("No memory\n");
-
-               memcpy(&new->event, &b, sizeof(b));
-               new->dso_name = pos->long_name;
-               new->len = len;
-
-               list_add_tail(&new->list, head);
-       }
+       list_for_each_entry(pos, &dsos, node)
+               if (filename__read_build_id(pos->long_name, pos->build_id,
+                                           sizeof(pos->build_id)) > 0) {
+                       have_build_id     = true;
+                       pos->has_build_id = true;
+               }
 
-       return have_buildid;
+       return have_build_id;
 }
 
 int filename__read_build_id(const char *filename, void *bf, size_t size)
index 5ad1019607dd7ae9a9f215104769a3c70e066b35..546eb766d81e2811a969c631e50fde76bd126b3f 100644 (file)
@@ -89,7 +89,7 @@ char dso__symtab_origin(const struct dso *self);
 void dso__set_build_id(struct dso *self, void *build_id);
 
 int filename__read_build_id(const char *filename, void *bf, size_t size);
-bool fetch_build_id_table(struct list_head *head);
+bool dsos__read_build_ids(void);
 int build_id__sprintf(u8 *self, int len, char *bf);
 
 int load_kernel(symbol_filter_t filter);