diff options
author | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2008-09-24 17:14:09 -0400 |
---|---|---|
committer | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2008-09-24 17:14:09 -0400 |
commit | 4a8b806b5f13df589a4800051b84f062efc2951d (patch) | |
tree | cd628039a6bbd6b48975e7cbf2d154a9681287d8 /bin | |
parent | 4f4d1a3992af845d0751962759aceb44e0050e22 (diff) |
add tool to dump sched_trace fiels
Diffstat (limited to 'bin')
-rw-r--r-- | bin/showst.c | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/bin/showst.c b/bin/showst.c new file mode 100644 index 0000000..1580adf --- /dev/null +++ b/bin/showst.c | |||
@@ -0,0 +1,67 @@ | |||
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 | |||
11 | static 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 | |||
37 | static 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 | |||
48 | static void show(char* file) | ||
49 | { | ||
50 | size_t s; | ||
51 | struct st_event_record *rec, *end; | ||
52 | unsigned int count; | ||
53 | if (map_trace(file, &rec, &end, &s) == 0) { | ||
54 | print_all(rec, | ||
55 | ((unsigned int)((char*) end - (char*) rec)) | ||
56 | / sizeof(struct st_event_record)); | ||
57 | } else | ||
58 | perror("mmap"); | ||
59 | } | ||
60 | |||
61 | int main(int argc, char** argv) | ||
62 | { | ||
63 | int i; | ||
64 | for (i = 1; i < argc; i++) | ||
65 | show(argv[i]); | ||
66 | return 0; | ||
67 | } | ||