Skip to content

Commit e30a3d1

Browse files
acmelIngo Molnar
authored andcommitted
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>
1 parent d3379ab commit e30a3d1

4 files changed

Lines changed: 28 additions & 49 deletions

File tree

‎tools/perf/util/event.h‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,6 @@ struct build_id_event {
6969
char filename[];
7070
};
7171

72-
struct build_id_list {
73-
struct build_id_event event;
74-
struct list_head list;
75-
const char *dso_name;
76-
int len;
77-
};
78-
7972
typedef union event_union {
8073
struct perf_event_header header;
8174
struct ip_event ip;

‎tools/perf/util/header.c‎

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -176,18 +176,24 @@ static int do_write(int fd, const void *buf, size_t size)
176176
return 0;
177177
}
178178

179-
static int write_buildid_table(int fd, struct list_head *id_head)
179+
static int dsos__write_buildid_table(int fd)
180180
{
181-
struct build_id_list *iter, *next;
182-
183-
list_for_each_entry_safe(iter, next, id_head, list) {
184-
struct build_id_event *b = &iter->event;
185-
186-
if (do_write(fd, b, sizeof(*b)) < 0 ||
187-
do_write(fd, iter->dso_name, iter->len) < 0)
181+
struct dso *pos;
182+
183+
list_for_each_entry(pos, &dsos, node) {
184+
struct build_id_event b;
185+
size_t len;
186+
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)
188196
return -1;
189-
list_del(&iter->list);
190-
free(iter);
191197
}
192198

193199
return 0;
@@ -196,14 +202,13 @@ static int write_buildid_table(int fd, struct list_head *id_head)
196202
static void
197203
perf_header__adds_write(struct perf_header *self, int fd)
198204
{
199-
LIST_HEAD(id_list);
200205
int nr_sections;
201206
struct perf_file_section *feat_sec;
202207
int sec_size;
203208
u64 sec_start;
204209
int idx = 0;
205210

206-
if (fetch_build_id_table(&id_list))
211+
if (dsos__read_build_ids())
207212
perf_header__set_feat(self, HEADER_BUILD_ID);
208213

209214
nr_sections = bitmap_weight(self->adds_features, HEADER_FEAT_BITS);
@@ -238,7 +243,7 @@ perf_header__adds_write(struct perf_header *self, int fd)
238243

239244
/* Write build-ids */
240245
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)
242247
die("failed to write buildid table");
243248
buildid_sec->size = lseek(fd, 0, SEEK_CUR) - buildid_sec->offset;
244249
}

‎tools/perf/util/symbol.c‎

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -883,38 +883,19 @@ static int dso__load_sym(struct dso *self, struct map *map, const char *name,
883883
return err;
884884
}
885885

886-
bool fetch_build_id_table(struct list_head *head)
886+
bool dsos__read_build_ids(void)
887887
{
888-
bool have_buildid = false;
888+
bool have_build_id = false;
889889
struct dso *pos;
890890

891-
list_for_each_entry(pos, &dsos, node) {
892-
struct build_id_list *new;
893-
struct build_id_event b;
894-
size_t len;
895-
896-
if (filename__read_build_id(pos->long_name,
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-
}
891+
list_for_each_entry(pos, &dsos, node)
892+
if (filename__read_build_id(pos->long_name, pos->build_id,
893+
sizeof(pos->build_id)) > 0) {
894+
have_build_id = true;
895+
pos->has_build_id = true;
896+
}
916897

917-
return have_buildid;
898+
return have_build_id;
918899
}
919900

920901
int filename__read_build_id(const char *filename, void *bf, size_t size)

‎tools/perf/util/symbol.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ char dso__symtab_origin(const struct dso *self);
8989
void dso__set_build_id(struct dso *self, void *build_id);
9090

9191
int filename__read_build_id(const char *filename, void *bf, size_t size);
92-
bool fetch_build_id_table(struct list_head *head);
92+
bool dsos__read_build_ids(void);
9393
int build_id__sprintf(u8 *self, int len, char *bf);
9494

9595
int load_kernel(symbol_filter_t filter);

0 commit comments

Comments
 (0)