aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft2csv.c
diff options
context:
space:
mode:
authorBjoern B. Brandenburg <bbb@cs.unc.edu>2007-05-16 14:53:42 -0400
committerBjoern B. Brandenburg <bbb@cs.unc.edu>2007-05-16 14:53:42 -0400
commit4d337d4d7a3c1e6a65b090251c4e41592740b0d0 (patch)
tree11a951fbd6fd3cc3dea8e102bd57a00acc94e852 /src/ft2csv.c
parent9bee556de7489579c3bdd0d2d4d457ffa72168eb (diff)
event naming
Diffstat (limited to 'src/ft2csv.c')
-rw-r--r--src/ft2csv.c117
1 files changed, 117 insertions, 0 deletions
diff --git a/src/ft2csv.c b/src/ft2csv.c
new file mode 100644
index 0000000..a5fdf0a
--- /dev/null
+++ b/src/ft2csv.c
@@ -0,0 +1,117 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <errno.h>
5
6#include "mapping.h"
7
8#include "timestamp.h"
9
10static unsigned int incomplete = 0;
11
12static struct timestamp* next(struct timestamp** pos, size_t* count, int cpu)
13{
14 while (*count--)
15 if ((++(*pos))->cpu == cpu)
16 return *pos;
17 return NULL;
18}
19
20static struct timestamp* next_id(struct timestamp** pos, size_t* count,
21 int cpu, unsigned long id)
22{
23 struct timestamp* ret;
24 while ((ret = next(pos, count, cpu)) && (*pos)->event != id);
25 return ret;
26}
27
28static int find_pair(struct timestamp* start,
29 struct timestamp** end,
30 size_t count)
31{
32 struct timestamp *pos = start;
33 /* convention: the end->event is start->event + 1 */
34 *end = next_id(&pos, &count, start->cpu, start->event + 1);
35 return *end != NULL;
36}
37
38static void show_csv(struct timestamp* ts, size_t count)
39{
40 struct timestamp* start = ts;
41 struct timestamp* stop;
42
43 if (find_pair(start, &stop, count)) {
44 printf("%llu, %llu, %llu\n",
45 start->timestamp, stop->timestamp,
46 stop->timestamp - start->timestamp);
47 } else
48 incomplete++;
49
50}
51
52/*static void show_all_per_cpu(struct timestamp* ts, size_t count)
53{
54 struct timestamp* _ts = ts;
55 size_t _count = count;
56 int cpu;
57
58 for (cpu = 0; cpu < 4; cpu++) {
59 count = _count;
60 ts = _ts;
61 while (count--) {
62 if (ts->cpu == cpu)
63 show(ts, count);
64 ts++;
65 }
66 }
67}*/
68
69static void show_id(struct timestamp* ts, size_t count, unsigned long id)
70{
71 while (count--)
72 if (ts->event == id)
73 show_csv(ts++, count);
74 else
75 ts++;
76}
77
78
79static void dump(struct timestamp* ts, size_t count, unsigned long id)
80{
81 while (count--)
82 printf("%lu\n", (ts++)->event);
83}
84
85
86static void die(char* msg)
87{
88 if (errno)
89 perror("error: ");
90 fprintf(stderr, "%s\n", msg);
91 exit(1);
92}
93
94int main(int argc, char** argv)
95{
96 void* mapped;
97 size_t size, count;
98 struct timestamp* ts;
99 unsigned long id;
100
101 if (argc != 3)
102 die("Usage: ft2csv <event_name> <logfile>");
103 if (map_file(argv[2], &mapped, &size))
104 die("could not map file");
105
106 if (!str2event(argv[1], &id))
107 die("Unknown event!");
108
109 ts = (struct timestamp*) mapped;
110 count = size / sizeof(struct timestamp);
111
112 show_id(ts, count, id);
113
114 fprintf(stderr, "Incomplete: %d\n", incomplete);
115
116 return 0;
117}