aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/header.c
diff options
context:
space:
mode:
authorFrederic Weisbecker <fweisbec@gmail.com>2009-10-06 17:36:47 -0400
committerIngo Molnar <mingo@elte.hu>2009-10-07 02:36:10 -0400
commit03456a158d9067d2f657bec170506009db81756d (patch)
treee242a1751bd48cf8731165d6b71a952fd1936a69 /tools/perf/util/header.c
parentb209aa1f83964d49a332a7b6b818ebede5cdc6ef (diff)
perf tools: Merge trace.info content into perf.data
This drops the trace.info file and move its contents into the common perf.data file. This is done by creating a new trace_info section into this file. A user of perf headers needs to call perf_header__set_trace_info() to save the trace meta informations into the perf.data file. A file created by perf after his patch is unsupported by previous version because the size of the headers have increased. That said, it's two new fields that have been added in the end of the headers, and those could be ignored by previous versions if they just handled the dynamic header size and then ignore the unknow part. The offsets guarantee the compatibility. We'll do a -stable fix for that. But current previous versions handle the header size using its static size, not dynamic, then it's not backward compatible with trace records. Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Mike Galbraith <efault@gmx.de> Cc: Paul Mackerras <paulus@samba.org> LKML-Reference: <20091006213643.GA5343@nowhere> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools/perf/util/header.c')
-rw-r--r--tools/perf/util/header.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index e306857b2c2b..212fade7ee74 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -5,6 +5,8 @@
5 5
6#include "util.h" 6#include "util.h"
7#include "header.h" 7#include "header.h"
8#include "../perf.h"
9#include "trace-event.h"
8 10
9/* 11/*
10 * Create new perf.data header attribute: 12 * Create new perf.data header attribute:
@@ -62,6 +64,8 @@ struct perf_header *perf_header__new(void)
62 64
63 self->data_offset = 0; 65 self->data_offset = 0;
64 self->data_size = 0; 66 self->data_size = 0;
67 self->trace_info_offset = 0;
68 self->trace_info_size = 0;
65 69
66 return self; 70 return self;
67} 71}
@@ -145,8 +149,16 @@ struct perf_file_header {
145 struct perf_file_section attrs; 149 struct perf_file_section attrs;
146 struct perf_file_section data; 150 struct perf_file_section data;
147 struct perf_file_section event_types; 151 struct perf_file_section event_types;
152 struct perf_file_section trace_info;
148}; 153};
149 154
155static int trace_info;
156
157void perf_header__set_trace_info(void)
158{
159 trace_info = 1;
160}
161
150static void do_write(int fd, void *buf, size_t size) 162static void do_write(int fd, void *buf, size_t size)
151{ 163{
152 while (size) { 164 while (size) {
@@ -198,6 +210,23 @@ void perf_header__write(struct perf_header *self, int fd)
198 if (events) 210 if (events)
199 do_write(fd, events, self->event_size); 211 do_write(fd, events, self->event_size);
200 212
213 if (trace_info) {
214 static int trace_info_written;
215
216 /*
217 * Write it only once
218 */
219 if (!trace_info_written) {
220 self->trace_info_offset = lseek(fd, 0, SEEK_CUR);
221 read_tracing_data(fd, attrs, nr_counters);
222 self->trace_info_size = lseek(fd, 0, SEEK_CUR) -
223 self->trace_info_offset;
224 trace_info_written = 1;
225 } else {
226 lseek(fd, self->trace_info_offset +
227 self->trace_info_size, SEEK_SET);
228 }
229 }
201 230
202 self->data_offset = lseek(fd, 0, SEEK_CUR); 231 self->data_offset = lseek(fd, 0, SEEK_CUR);
203 232
@@ -217,6 +246,10 @@ void perf_header__write(struct perf_header *self, int fd)
217 .offset = self->event_offset, 246 .offset = self->event_offset,
218 .size = self->event_size, 247 .size = self->event_size,
219 }, 248 },
249 .trace_info = {
250 .offset = self->trace_info_offset,
251 .size = self->trace_info_size,
252 },
220 }; 253 };
221 254
222 lseek(fd, 0, SEEK_SET); 255 lseek(fd, 0, SEEK_SET);
@@ -290,6 +323,15 @@ struct perf_header *perf_header__read(int fd)
290 do_read(fd, events, f_header.event_types.size); 323 do_read(fd, events, f_header.event_types.size);
291 event_count = f_header.event_types.size / sizeof(struct perf_trace_event_type); 324 event_count = f_header.event_types.size / sizeof(struct perf_trace_event_type);
292 } 325 }
326
327 self->trace_info_offset = f_header.trace_info.offset;
328 self->trace_info_size = f_header.trace_info.size;
329
330 if (self->trace_info_size) {
331 lseek(fd, self->trace_info_offset, SEEK_SET);
332 trace_report(fd);
333 }
334
293 self->event_offset = f_header.event_types.offset; 335 self->event_offset = f_header.event_types.offset;
294 self->event_size = f_header.event_types.size; 336 self->event_size = f_header.event_types.size;
295 337