21 #define _FILE_OFFSET_BITS 64
29 #include <sys/types.h>
76 int retw =
write(STDOUT_FILENO, buf, ret);
78 if (retw <= 0 || retw != ret)
79 die(
"repiping input file");
89 static int read_or_die(
void *
data,
int size)
93 r =
do_read(input_fd, data, size);
95 die(
"reading input file (size expected=%d received=%d)",
105 static void skip(
int size)
111 r = size > BUFSIZ ? BUFSIZ :
size;
121 read_or_die(&data, 4);
122 return __data2host4(pevent, data);
127 unsigned long long data;
129 read_or_die(&data, 8);
130 return __data2host8(pevent, data);
133 static char *read_string(
void)
142 r =
read(input_fd, &c, 1);
144 die(
"reading input file");
150 int retw =
write(STDOUT_FILENO, &c, 1);
152 if (retw <= 0 || retw != r)
153 die(
"repiping input file string");
163 calc_data_size +=
size;
176 size = read4(pevent);
181 read_or_die(buf, size);
189 static void read_ftrace_printk(
struct pevent *pevent)
194 size = read4(pevent);
199 read_or_die(buf, size);
206 static void read_header_files(
struct pevent *pevent)
208 unsigned long long size;
212 read_or_die(buf, 12);
214 if (
memcmp(buf,
"header_page", 12) != 0)
215 die(
"did not read header page");
217 size = read8(pevent);
226 read_or_die(buf, 13);
227 if (
memcmp(buf,
"header_event", 13) != 0)
228 die(
"did not read header event");
230 size = read8(pevent);
232 read_or_die(header_event, size);
236 static void read_ftrace_file(
struct pevent *pevent,
unsigned long long size)
241 read_or_die(buf, size);
246 static void read_event_file(
struct pevent *pevent,
char *
sys,
247 unsigned long long size)
252 read_or_die(buf, size);
257 static void read_ftrace_files(
struct pevent *pevent)
259 unsigned long long size;
263 count = read4(pevent);
265 for (i = 0; i <
count; i++) {
266 size = read8(pevent);
267 read_ftrace_file(pevent, size);
271 static void read_event_files(
struct pevent *pevent)
273 unsigned long long size;
279 systems = read4(pevent);
281 for (i = 0; i < systems; i++) {
284 count = read4(pevent);
285 for (x=0; x <
count; x++) {
286 size = read8(pevent);
287 read_event_file(pevent, sys, size);
305 static void update_cpu_data_index(
int cpu)
312 static void get_next_page(
int cpu)
317 if (!cpu_data[cpu].
page)
322 free(cpu_data[cpu].page);
327 update_cpu_data_index(cpu);
330 save_seek = lseek(input_fd, 0,
SEEK_CUR);
333 if (ret == (
off_t)-1)
334 die(
"failed to lseek");
337 die(
"failed to read page");
340 lseek(input_fd, save_seek,
SEEK_SET);
351 update_cpu_data_index(cpu);
354 input_fd, cpu_data[cpu].
offset);
355 if (cpu_data[cpu].page == MAP_FAILED)
356 die(
"failed to mmap cpu %d at offset 0x%llx",
357 cpu, cpu_data[cpu].
offset);
360 static unsigned int type_len4host(
unsigned int type_len_ts)
363 return (type_len_ts >> 27) & ((1 << 5) - 1);
365 return type_len_ts & ((1 << 5) - 1);
368 static unsigned int ts4host(
unsigned int type_len_ts)
371 return type_len_ts & ((1 << 27) - 1);
373 return type_len_ts >> 5;
376 static int calc_index(
void *
ptr,
int cpu)
378 return (
unsigned long)ptr - (
unsigned long)cpu_data[cpu].page;
384 void *page = cpu_data[
cpu].
page;
386 void *ptr = page +
idx;
387 unsigned long long extend;
388 unsigned int type_len_ts;
389 unsigned int type_len;
393 if (cpu_data[cpu].
next)
402 die(
"expected a long long type for timestamp");
415 die(
"bad long size");
421 idx = calc_index(ptr, cpu);
431 type_len = type_len4host(type_len_ts);
432 delta = ts4host(type_len_ts);
437 die(
"error, hit unexpected end of page");
458 die(
"here! length=%d", length);
461 length = type_len * 4;
468 memset(data, 0,
sizeof(*data));
475 cpu_data[
cpu].
index = calc_index(ptr, cpu);
494 char test[] = { 23, 8, 68 };
496 int show_version = 0;
507 if (
memcmp(buf, test, 3) != 0)
508 die(
"no trace data in the file");
511 if (
memcmp(buf,
"tracing", 7) != 0)
512 die(
"not a trace file (missing 'tracing' tag)");
514 version = read_string();
516 printf(
"version = %s\n", version);
524 if (*ppevent ==
NULL)
525 die(
"read_trace_init failed");
532 read_header_files(*ppevent);
534 read_ftrace_files(*ppevent);
535 read_event_files(*ppevent);
536 read_proc_kallsyms(*ppevent);
537 read_ftrace_printk(*ppevent);
539 size = calc_data_size - 1;