diff options
author | Frederic Weisbecker <fweisbec@gmail.com> | 2009-11-10 22:51:03 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-11-11 01:30:17 -0500 |
commit | 8671dab9d5b2f0b444b8d09792384dccbfd43d14 (patch) | |
tree | 399d45fd784e7210bc1847ab2643731243f67f1d /tools/perf/util/header.c | |
parent | de8967214d8ce536161a1ad6538ad1cb82e7428d (diff) |
perf tools: Move the build-id storage operations to headers
So that it makes easier to control it. Especially because we
plan to give it a feature section.
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Hitoshi Mitake <mitake@dcl.info.waseda.ac.jp>
LKML-Reference: <1257911467-28276-2-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools/perf/util/header.c')
-rw-r--r-- | tools/perf/util/header.c | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 050f543fd965..a4d0bbef9a43 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c | |||
@@ -2,11 +2,13 @@ | |||
2 | #include <unistd.h> | 2 | #include <unistd.h> |
3 | #include <stdio.h> | 3 | #include <stdio.h> |
4 | #include <stdlib.h> | 4 | #include <stdlib.h> |
5 | #include <linux/list.h> | ||
5 | 6 | ||
6 | #include "util.h" | 7 | #include "util.h" |
7 | #include "header.h" | 8 | #include "header.h" |
8 | #include "../perf.h" | 9 | #include "../perf.h" |
9 | #include "trace-event.h" | 10 | #include "trace-event.h" |
11 | #include "symbol.h" | ||
10 | 12 | ||
11 | /* | 13 | /* |
12 | * Create new perf.data header attribute: | 14 | * Create new perf.data header attribute: |
@@ -172,7 +174,33 @@ static void do_write(int fd, void *buf, size_t size) | |||
172 | } | 174 | } |
173 | } | 175 | } |
174 | 176 | ||
175 | static void perf_header__adds_write(struct perf_header *self, int fd) | 177 | static bool write_buildid_table(int fd) |
178 | { | ||
179 | struct dso *pos; | ||
180 | bool have_buildid = false; | ||
181 | |||
182 | list_for_each_entry(pos, &dsos, node) { | ||
183 | struct build_id_event b; | ||
184 | size_t len; | ||
185 | |||
186 | if (filename__read_build_id(pos->long_name, | ||
187 | &b.build_id, | ||
188 | sizeof(b.build_id)) < 0) | ||
189 | continue; | ||
190 | have_buildid = true; | ||
191 | memset(&b.header, 0, sizeof(b.header)); | ||
192 | len = strlen(pos->long_name) + 1; | ||
193 | len = ALIGN(len, 64); | ||
194 | b.header.size = sizeof(b) + len; | ||
195 | do_write(fd, &b, sizeof(b)); | ||
196 | do_write(fd, pos->long_name, len); | ||
197 | } | ||
198 | |||
199 | return have_buildid; | ||
200 | } | ||
201 | |||
202 | static void | ||
203 | perf_header__adds_write(struct perf_header *self, int fd, bool at_exit) | ||
176 | { | 204 | { |
177 | struct perf_file_section trace_sec; | 205 | struct perf_file_section trace_sec; |
178 | u64 cur_offset = lseek(fd, 0, SEEK_CUR); | 206 | u64 cur_offset = lseek(fd, 0, SEEK_CUR); |
@@ -196,9 +224,16 @@ static void perf_header__adds_write(struct perf_header *self, int fd) | |||
196 | */ | 224 | */ |
197 | cur_offset = lseek(fd, trace_sec.offset + trace_sec.size, SEEK_SET); | 225 | cur_offset = lseek(fd, trace_sec.offset + trace_sec.size, SEEK_SET); |
198 | } | 226 | } |
227 | |||
228 | if (at_exit) { | ||
229 | lseek(fd, self->data_offset + self->data_size, SEEK_SET); | ||
230 | if (write_buildid_table(fd)) | ||
231 | perf_header__set_feat(self, HEADER_BUILD_ID); | ||
232 | lseek(fd, cur_offset, SEEK_SET); | ||
233 | } | ||
199 | }; | 234 | }; |
200 | 235 | ||
201 | void perf_header__write(struct perf_header *self, int fd) | 236 | void perf_header__write(struct perf_header *self, int fd, bool at_exit) |
202 | { | 237 | { |
203 | struct perf_file_header f_header; | 238 | struct perf_file_header f_header; |
204 | struct perf_file_attr f_attr; | 239 | struct perf_file_attr f_attr; |
@@ -236,7 +271,7 @@ void perf_header__write(struct perf_header *self, int fd) | |||
236 | if (events) | 271 | if (events) |
237 | do_write(fd, events, self->event_size); | 272 | do_write(fd, events, self->event_size); |
238 | 273 | ||
239 | perf_header__adds_write(self, fd); | 274 | perf_header__adds_write(self, fd, at_exit); |
240 | 275 | ||
241 | self->data_offset = lseek(fd, 0, SEEK_CUR); | 276 | self->data_offset = lseek(fd, 0, SEEK_CUR); |
242 | 277 | ||