aboutsummaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--tools/perf/builtin-record.c7
-rw-r--r--tools/perf/builtin-sched.c1
-rw-r--r--tools/perf/builtin-trace.c1
-rw-r--r--tools/perf/util/header.c42
-rw-r--r--tools/perf/util/header.h4
-rw-r--r--tools/perf/util/trace-event-info.c6
-rw-r--r--tools/perf/util/trace-event-read.c7
-rw-r--r--tools/perf/util/trace-event.h4
8 files changed, 54 insertions, 18 deletions
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 494f8c7d7521..59af03d80d07 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -17,7 +17,6 @@
17#include "util/header.h" 17#include "util/header.h"
18#include "util/event.h" 18#include "util/event.h"
19#include "util/debug.h" 19#include "util/debug.h"
20#include "util/trace-event.h"
21 20
22#include <unistd.h> 21#include <unistd.h>
23#include <sched.h> 22#include <sched.h>
@@ -566,17 +565,17 @@ static int __cmd_record(int argc, const char **argv)
566 else 565 else
567 header = perf_header__new(); 566 header = perf_header__new();
568 567
569
570 if (raw_samples) { 568 if (raw_samples) {
571 read_tracing_data(attrs, nr_counters); 569 perf_header__set_trace_info();
572 } else { 570 } else {
573 for (i = 0; i < nr_counters; i++) { 571 for (i = 0; i < nr_counters; i++) {
574 if (attrs[i].sample_type & PERF_SAMPLE_RAW) { 572 if (attrs[i].sample_type & PERF_SAMPLE_RAW) {
575 read_tracing_data(attrs, nr_counters); 573 perf_header__set_trace_info();
576 break; 574 break;
577 } 575 }
578 } 576 }
579 } 577 }
578
580 atexit(atexit_header); 579 atexit(atexit_header);
581 580
582 if (!system_wide) { 581 if (!system_wide) {
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 4470f2535706..18871380b015 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -1634,7 +1634,6 @@ static int read_events(void)
1634 uint32_t size; 1634 uint32_t size;
1635 char *buf; 1635 char *buf;
1636 1636
1637 trace_report();
1638 register_idle_thread(&threads, &last_match); 1637 register_idle_thread(&threads, &last_match);
1639 1638
1640 input = open(input_name, O_RDONLY); 1639 input = open(input_name, O_RDONLY);
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index d573d4ea6c21..d9abb4ae5f79 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -149,7 +149,6 @@ static int __cmd_trace(void)
149 uint32_t size; 149 uint32_t size;
150 char *buf; 150 char *buf;
151 151
152 trace_report();
153 register_idle_thread(&threads, &last_match); 152 register_idle_thread(&threads, &last_match);
154 153
155 input = open(input_name, O_RDONLY); 154 input = open(input_name, O_RDONLY);
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
diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h
index a2916b652a1b..30aee5160dc0 100644
--- a/tools/perf/util/header.h
+++ b/tools/perf/util/header.h
@@ -21,6 +21,8 @@ struct perf_header {
21 u64 data_size; 21 u64 data_size;
22 u64 event_offset; 22 u64 event_offset;
23 u64 event_size; 23 u64 event_size;
24 u64 trace_info_offset;
25 u64 trace_info_size;
24}; 26};
25 27
26struct perf_header *perf_header__read(int fd); 28struct perf_header *perf_header__read(int fd);
@@ -40,7 +42,7 @@ void perf_header_attr__add_id(struct perf_header_attr *self, u64 id);
40u64 perf_header__sample_type(struct perf_header *header); 42u64 perf_header__sample_type(struct perf_header *header);
41struct perf_event_attr * 43struct perf_event_attr *
42perf_header__find_attr(u64 id, struct perf_header *header); 44perf_header__find_attr(u64 id, struct perf_header *header);
43 45void perf_header__set_trace_info(void);
44 46
45struct perf_header *perf_header__new(void); 47struct perf_header *perf_header__new(void);
46 48
diff --git a/tools/perf/util/trace-event-info.c b/tools/perf/util/trace-event-info.c
index af4b0573b37f..831052d4b4fb 100644
--- a/tools/perf/util/trace-event-info.c
+++ b/tools/perf/util/trace-event-info.c
@@ -496,14 +496,12 @@ get_tracepoints_path(struct perf_event_attr *pattrs, int nb_events)
496 496
497 return path.next; 497 return path.next;
498} 498}
499void read_tracing_data(struct perf_event_attr *pattrs, int nb_events) 499void read_tracing_data(int fd, struct perf_event_attr *pattrs, int nb_events)
500{ 500{
501 char buf[BUFSIZ]; 501 char buf[BUFSIZ];
502 struct tracepoint_path *tps; 502 struct tracepoint_path *tps;
503 503
504 output_fd = open(output_file, O_WRONLY | O_CREAT | O_TRUNC | O_LARGEFILE, 0644); 504 output_fd = fd;
505 if (output_fd < 0)
506 die("creating file '%s'", output_file);
507 505
508 buf[0] = 23; 506 buf[0] = 23;
509 buf[1] = 8; 507 buf[1] = 8;
diff --git a/tools/perf/util/trace-event-read.c b/tools/perf/util/trace-event-read.c
index 1b5c847d2c22..44292e06cca4 100644
--- a/tools/perf/util/trace-event-read.c
+++ b/tools/perf/util/trace-event-read.c
@@ -458,9 +458,8 @@ struct record *trace_read_data(int cpu)
458 return data; 458 return data;
459} 459}
460 460
461void trace_report(void) 461void trace_report(int fd)
462{ 462{
463 const char *input_file = "trace.info";
464 char buf[BUFSIZ]; 463 char buf[BUFSIZ];
465 char test[] = { 23, 8, 68 }; 464 char test[] = { 23, 8, 68 };
466 char *version; 465 char *version;
@@ -468,9 +467,7 @@ void trace_report(void)
468 int show_funcs = 0; 467 int show_funcs = 0;
469 int show_printk = 0; 468 int show_printk = 0;
470 469
471 input_fd = open(input_file, O_RDONLY); 470 input_fd = fd;
472 if (input_fd < 0)
473 die("opening '%s'\n", input_file);
474 471
475 read_or_die(buf, 3); 472 read_or_die(buf, 3);
476 if (memcmp(buf, test, 3) != 0) 473 if (memcmp(buf, test, 3) != 0)
diff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h
index 5f59a39fb88b..da77e073c867 100644
--- a/tools/perf/util/trace-event.h
+++ b/tools/perf/util/trace-event.h
@@ -158,7 +158,7 @@ struct record *trace_read_data(int cpu);
158 158
159void parse_set_info(int nr_cpus, int long_sz); 159void parse_set_info(int nr_cpus, int long_sz);
160 160
161void trace_report(void); 161void trace_report(int fd);
162 162
163void *malloc_or_die(unsigned int size); 163void *malloc_or_die(unsigned int size);
164 164
@@ -244,6 +244,6 @@ unsigned long long
244raw_field_value(struct event *event, const char *name, void *data); 244raw_field_value(struct event *event, const char *name, void *data);
245void *raw_field_ptr(struct event *event, const char *name, void *data); 245void *raw_field_ptr(struct event *event, const char *name, void *data);
246 246
247void read_tracing_data(struct perf_event_attr *pattrs, int nb_events); 247void read_tracing_data(int fd, struct perf_event_attr *pattrs, int nb_events);
248 248
249#endif /* __PERF_TRACE_EVENTS_H */ 249#endif /* __PERF_TRACE_EVENTS_H */