aboutsummaryrefslogtreecommitdiffstats
path: root/src/ftdump.c
blob: 1462c4d40fa1d0b3fe17ca094332345e7b62e703 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
 *    ftdump -- Dump raw event data from a Feather-Trace event stream.
 *    Copyright (C) 2007, 2008  B. Brandenburg.
 *
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 2 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License along
 *    with this program; if not, write to the Free Software Foundation, Inc.,
 *    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

#include "mapping.h"

#include "timestamp.h"

static void dump(struct timestamp* ts, size_t count)
{
	struct timestamp *x;
	unsigned int last_seq = 0;
	const char* name;
	while (count--) {
		x = ts++;
		name = event2str(x->event);
		if (last_seq && last_seq + 1 != x->seq_no)
			printf("==== non-consecutive sequence number ====\n");
		last_seq = x->seq_no;
		if (name)
			printf("%-20s seq:%u  timestamp:%llu  cpu:%d  type:%-8s irq:%u irqc:%02u \n",
			       name,  x->seq_no,
			       (unsigned long long)  x->timestamp,
			       x->cpu,
			       task_type2str(x->task_type),
			       x->irq_flag,
			       x->irq_count);
		else
			printf("%16s:%3u seq:%u  timestamp:%llu  cpu:%u  type:%-8s irq:%u irqc:%02u\n",
			       "event",
			       (unsigned int) x->event, x->seq_no,
			       (unsigned long long)  x->timestamp,
			       x->cpu,
			       task_type2str(x->task_type),
			       x->irq_flag,
			       x->irq_count);
	}
}

static void die(char* msg)
{
	if (errno)
		perror("error: ");
	fprintf(stderr, "%s\n", msg);
	exit(1);
}

#define offset(type, member)  ((unsigned long) &((type *) 0)->member)

int main(int argc, char** argv)
{
	void* mapped;
	size_t size, count;
	struct timestamp* ts;

	printf("struct timestamp:\n"
	       "\t size              = %3lu\n"
	       "\t offset(timestamp) = %3lu\n"
	       "\t offset(seq_no)    = %3lu\n"
	       "\t offset(cpu)       = %3lu\n"
	       "\t offset(event)     = %3lu\n",
	       (unsigned long) sizeof(struct timestamp),
	       offset(struct timestamp, timestamp),
	       offset(struct timestamp, seq_no),
	       offset(struct timestamp, cpu),
	       offset(struct timestamp, event));

	if (argc != 2)
		die("Usage: ftdump  <logfile>");
	if (map_file(argv[1], &mapped, &size))
		die("could not map file");

	ts    = (struct timestamp*) mapped;
	count = size / sizeof(struct timestamp);

	dump(ts, count);
	return 0;
}