aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorFrederic Weisbecker <fweisbec@gmail.com>2009-11-10 22:51:03 -0500
committerIngo Molnar <mingo@elte.hu>2009-11-11 01:30:17 -0500
commit8671dab9d5b2f0b444b8d09792384dccbfd43d14 (patch)
tree399d45fd784e7210bc1847ab2643731243f67f1d /tools
parentde8967214d8ce536161a1ad6538ad1cb82e7428d (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')
-rw-r--r--tools/perf/builtin-record.c32
-rw-r--r--tools/perf/util/header.c41
-rw-r--r--tools/perf/util/header.h2
3 files changed, 41 insertions, 34 deletions
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 9f98b86e747c..c35e61b30988 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -378,39 +378,11 @@ static void open_counters(int cpu, pid_t pid)
378 nr_cpu++; 378 nr_cpu++;
379} 379}
380 380
381static bool write_buildid_table(void)
382{
383 struct dso *pos;
384 bool have_buildid = false;
385
386 list_for_each_entry(pos, &dsos, node) {
387 struct build_id_event b;
388 size_t len;
389
390 if (filename__read_build_id(pos->long_name,
391 &b.build_id,
392 sizeof(b.build_id)) < 0)
393 continue;
394 have_buildid = true;
395 memset(&b.header, 0, sizeof(b.header));
396 len = strlen(pos->long_name) + 1;
397 len = ALIGN(len, 64);
398 b.header.size = sizeof(b) + len;
399 write_output(&b, sizeof(b));
400 write_output(pos->long_name, len);
401 }
402
403 return have_buildid;
404}
405
406static void atexit_header(void) 381static void atexit_header(void)
407{ 382{
408 header->data_size += bytes_written; 383 header->data_size += bytes_written;
409 384
410 if (write_buildid_table()) 385 perf_header__write(header, output, true);
411 perf_header__set_feat(header, HEADER_BUILD_ID);
412
413 perf_header__write(header, output);
414} 386}
415 387
416static int __cmd_record(int argc, const char **argv) 388static int __cmd_record(int argc, const char **argv)
@@ -487,7 +459,7 @@ static int __cmd_record(int argc, const char **argv)
487 } 459 }
488 460
489 if (file_new) 461 if (file_new)
490 perf_header__write(header, output); 462 perf_header__write(header, output, false);
491 463
492 if (!system_wide) 464 if (!system_wide)
493 event__synthesize_thread(pid, process_synthesized_event); 465 event__synthesize_thread(pid, process_synthesized_event);
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
175static void perf_header__adds_write(struct perf_header *self, int fd) 177static 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
202static void
203perf_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
201void perf_header__write(struct perf_header *self, int fd) 236void 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
diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h
index 2f233c5db7e9..77186c9e605b 100644
--- a/tools/perf/util/header.h
+++ b/tools/perf/util/header.h
@@ -33,7 +33,7 @@ struct perf_header {
33}; 33};
34 34
35struct perf_header *perf_header__read(int fd); 35struct perf_header *perf_header__read(int fd);
36void perf_header__write(struct perf_header *self, int fd); 36void perf_header__write(struct perf_header *self, int fd, bool at_exit);
37 37
38void perf_header__add_attr(struct perf_header *self, 38void perf_header__add_attr(struct perf_header *self,
39 struct perf_header_attr *attr); 39 struct perf_header_attr *attr);