summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjoern B. Brandenburg <bbb@cs.unc.edu>2008-10-29 23:00:41 -0400
committerBjoern B. Brandenburg <bbb@cs.unc.edu>2008-10-29 23:00:41 -0400
commitb1c9e03d3c0a7eaf584b62454b941e06e2c2f5fa (patch)
treec458feace3b90c1825437a674a5b4144eb621b7c
parentbc6590c49544eac227831152d472a9b61bb69369 (diff)
move showst
-rw-r--r--.gitignore6
-rw-r--r--Makefile5
-rw-r--r--src/showst.c117
3 files changed, 127 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..5bba9a2
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,6 @@
1*.o
2*.a
3showst
4st2asy
5\#*
6.\#* \ No newline at end of file
diff --git a/Makefile b/Makefile
index ae4a453..4a9450f 100644
--- a/Makefile
+++ b/Makefile
@@ -17,13 +17,16 @@ LIB = ${LITMUS_LIB}
17vpath %.h include/ 17vpath %.h include/
18vpath %.c src/ 18vpath %.c src/
19 19
20APPS = st2asy 20APPS = st2asy showst
21 21
22all: ${APPS} 22all: ${APPS}
23 23
24st2asy: st2asy.o ${LIB} 24st2asy: st2asy.o ${LIB}
25 gcc ${CFLAGS} -lpthread -o st2asy st2asy.o ${LIB} 25 gcc ${CFLAGS} -lpthread -o st2asy st2asy.o ${LIB}
26 26
27showst: showst.o ${LIB}
28 gcc ${CFLAGS} -lpthread -o showst showst.o ${LIB}
29
27clean: 30clean:
28 rm -f *.o ${APPS} 31 rm -f *.o ${APPS}
29 32
diff --git a/src/showst.c b/src/showst.c
new file mode 100644
index 0000000..ee256ff
--- /dev/null
+++ b/src/showst.c
@@ -0,0 +1,117 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include <sys/types.h>
4#include <sys/stat.h>
5#include <sys/mman.h>
6#include <fcntl.h>
7#include <unistd.h>
8
9#include "sched_trace.h"
10
11static int map_file(const char* filename, void **addr, size_t *size)
12{
13 struct stat info;
14 int error = 0;
15 int fd;
16
17 error = stat(filename, &info);
18 if (!error) {
19 *size = info.st_size;
20 if (info.st_size > 0) {
21 fd = open(filename, O_RDONLY);
22 if (fd >= 0) {
23 *addr = mmap(NULL, *size,
24 PROT_READ | PROT_WRITE,
25 MAP_PRIVATE, fd, 0);
26 if (*addr == MAP_FAILED)
27 error = -1;
28 close(fd);
29 } else
30 error = fd;
31 } else
32 *addr = NULL;
33 }
34 return error;
35}
36
37static int map_trace(const char *name, void **start, void **end, size_t *size)
38{
39 int ret;
40
41 ret = map_file(name, start, size);
42 if (!ret)
43 *end = *start + *size;
44 return ret;
45}
46
47
48static void show(char* file)
49{
50 size_t s;
51 struct st_event_record *rec, *end;
52 if (map_trace(file, &rec, &end, &s) == 0) {
53 print_all(rec,
54 ((unsigned int)((char*) end - (char*) rec))
55 / sizeof(struct st_event_record));
56 } else
57 perror("mmap");
58}
59
60
61static struct heap* file2heap(char* file, unsigned int* count)
62{
63 size_t s;
64 struct st_event_record *rec, *end;
65 if (map_trace(file, &rec, &end, &s) == 0) {
66 *count = ((unsigned int)((char*) end - (char*) rec))
67 / sizeof(struct st_event_record);
68 return heapify_events(rec, *count);
69 } else
70 perror("mmap");
71 return NULL;
72}
73
74
75/*
76int main(int argc, char** argv)
77{
78 int i;
79 for (i = 1; i < argc; i++)
80 show(argv[i]);
81 return 0;
82}
83*/
84
85int main(int argc, char** argv)
86{
87 int i;
88 unsigned int count;
89 struct heap h, *h2;
90 struct heap_node *hn;
91 u64 start_time = 0, time;
92
93 heap_init(&h);
94
95 for (i = 1; i < argc; i++) {
96 printf("Heapify %s ", argv[i]);
97 h2 = file2heap(argv[i], &count);
98 if (h2) {
99 printf("merging ");
100 heap_union(earlier_event, &h, h2);
101 printf("done [%u events].\n", count);
102 } else
103 printf("failed.\n");
104 }
105
106 while ((hn = heap_take(earlier_event, &h))) {
107 time = event_time(heap_node_value(hn));
108 if (!start_time && time)
109 start_time = time;
110 time -= start_time;
111 time /= 1000000; /* convert to milliseconds */
112 printf("[%10llu] ", time);
113 print_event(heap_node_value(hn));
114 }
115
116 return 0;
117}