diff options
-rw-r--r-- | include/sched_trace.h | 5 | ||||
-rw-r--r-- | src/sched_trace.c | 63 |
2 files changed, 30 insertions, 38 deletions
diff --git a/include/sched_trace.h b/include/sched_trace.h index 2e6fbb6..1d2b3ac 100644 --- a/include/sched_trace.h +++ b/include/sched_trace.h | |||
@@ -10,6 +10,11 @@ typedef __u64 u64; | |||
10 | 10 | ||
11 | #include <litmus/sched_trace.h> | 11 | #include <litmus/sched_trace.h> |
12 | 12 | ||
13 | const char* event2name(unsigned int id); | ||
14 | u64 event_time(struct st_event_record* rec); | ||
15 | |||
16 | void print_event(struct st_event_record *rec); | ||
13 | void print_all(struct st_event_record *rec, unsigned int count); | 17 | void print_all(struct st_event_record *rec, unsigned int count); |
14 | 18 | ||
19 | |||
15 | #endif | 20 | #endif |
diff --git a/src/sched_trace.c b/src/sched_trace.c index 330ed27..434b0d7 100644 --- a/src/sched_trace.c +++ b/src/sched_trace.c | |||
@@ -1,6 +1,7 @@ | |||
1 | #include <stdio.h> | 1 | #include <stdio.h> |
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | 3 | ||
4 | |||
4 | #include <sys/types.h> | 5 | #include <sys/types.h> |
5 | #include <sys/stat.h> | 6 | #include <sys/stat.h> |
6 | #include <sys/mman.h> | 7 | #include <sys/mman.h> |
@@ -10,42 +11,6 @@ | |||
10 | #include "litmus.h" | 11 | #include "litmus.h" |
11 | #include "sched_trace.h" | 12 | #include "sched_trace.h" |
12 | 13 | ||
13 | static int map_file(const char* filename, void **addr, size_t *size) | ||
14 | { | ||
15 | struct stat info; | ||
16 | int error = 0; | ||
17 | int fd; | ||
18 | |||
19 | error = stat(filename, &info); | ||
20 | if (!error) { | ||
21 | *size = info.st_size; | ||
22 | if (info.st_size > 0) { | ||
23 | fd = open(filename, O_RDONLY); | ||
24 | if (fd >= 0) { | ||
25 | *addr = mmap(NULL, *size, | ||
26 | PROT_READ | PROT_WRITE, | ||
27 | MAP_PRIVATE, fd, 0); | ||
28 | if (*addr == MAP_FAILED) | ||
29 | error = -1; | ||
30 | close(fd); | ||
31 | } else | ||
32 | error = fd; | ||
33 | } else | ||
34 | *addr = NULL; | ||
35 | } | ||
36 | return error; | ||
37 | } | ||
38 | |||
39 | static int map_trace(const char *name, void **start, void **end, size_t *size) | ||
40 | { | ||
41 | int ret; | ||
42 | |||
43 | ret = map_file(name, start, size); | ||
44 | if (!ret) | ||
45 | *end = *start + *size; | ||
46 | return ret; | ||
47 | } | ||
48 | |||
49 | static const char* event_names[] = { | 14 | static const char* event_names[] = { |
50 | "INVALID", | 15 | "INVALID", |
51 | "NAME", | 16 | "NAME", |
@@ -70,6 +35,30 @@ const char* event2name(unsigned int id) | |||
70 | return event_names[id]; | 35 | return event_names[id]; |
71 | } | 36 | } |
72 | 37 | ||
38 | |||
39 | u64 event_time(struct st_event_record* rec) | ||
40 | { | ||
41 | u64 when; | ||
42 | switch (rec->hdr.type) { | ||
43 | /* the time stamp is encoded in the first payload u64 */ | ||
44 | case ST_RELEASE: | ||
45 | case ST_ASSIGNED: | ||
46 | case ST_SWITCH_TO: | ||
47 | case ST_SWITCH_AWAY: | ||
48 | case ST_COMPLETION: | ||
49 | case ST_BLOCK: | ||
50 | case ST_RESUME: | ||
51 | when = rec->data.raw[0]; | ||
52 | break; | ||
53 | default: | ||
54 | /* stuff that doesn't have a time stamp should occur "early" */ | ||
55 | when = 0; | ||
56 | break; | ||
57 | }; | ||
58 | return when; | ||
59 | } | ||
60 | |||
61 | |||
73 | void print_header(struct st_trace_header* hdr) | 62 | void print_header(struct st_trace_header* hdr) |
74 | { | 63 | { |
75 | printf("%-14s %5u/%-5u on CPU%3u ", | 64 | printf("%-14s %5u/%-5u on CPU%3u ", |
@@ -123,10 +112,8 @@ void print_event(struct st_event_record *rec) | |||
123 | print_header(&rec->hdr); | 112 | print_header(&rec->hdr); |
124 | print_detail[id](rec); | 113 | print_detail[id](rec); |
125 | printf("\n"); | 114 | printf("\n"); |
126 | return event_names[id]; | ||
127 | } | 115 | } |
128 | 116 | ||
129 | |||
130 | void print_all(struct st_event_record *rec, unsigned int count) | 117 | void print_all(struct st_event_record *rec, unsigned int count) |
131 | { | 118 | { |
132 | unsigned int i; | 119 | unsigned int i; |