aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBjoern B. Brandenburg <bbb@cs.unc.edu>2008-10-29 23:10:19 -0400
committerBjoern B. Brandenburg <bbb@cs.unc.edu>2008-10-29 23:10:19 -0400
commitaa387e17f6d5dcd2847ba142c6d4a8d7e5b5054d (patch)
treeb41b3d5b44867c5f647be0c165517bdaa8b319fd /src
parent61c4835ed40d6a168ada3f62c7cc11420b5e3f39 (diff)
add event_time(), remove cruft
Diffstat (limited to 'src')
-rw-r--r--src/sched_trace.c63
1 files changed, 25 insertions, 38 deletions
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
13static 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
39static 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
49static const char* event_names[] = { 14static 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
39u64 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
73void print_header(struct st_trace_header* hdr) 62void 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
130void print_all(struct st_event_record *rec, unsigned int count) 117void print_all(struct st_event_record *rec, unsigned int count)
131{ 118{
132 unsigned int i; 119 unsigned int i;