diff options
| author | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2008-09-16 15:13:43 -0400 |
|---|---|---|
| committer | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2008-09-16 15:13:43 -0400 |
| commit | 59e67e78312843793f299dbd9554afe09c23cad8 (patch) | |
| tree | 23491748b60efb2759d6d74c801e6dd9702dac35 /src | |
| parent | 3bc3a229f237fd62820efdbf7d5eb9dc8b2f8cb3 (diff) | |
sched_trace: remove old definitions, include kernel header
Diffstat (limited to 'src')
| -rw-r--r-- | src/sched_trace.c | 126 |
1 files changed, 8 insertions, 118 deletions
diff --git a/src/sched_trace.c b/src/sched_trace.c index c3a603b..17d3d06 100644 --- a/src/sched_trace.c +++ b/src/sched_trace.c | |||
| @@ -10,148 +10,38 @@ | |||
| 10 | #include "litmus.h" | 10 | #include "litmus.h" |
| 11 | #include "sched_trace.h" | 11 | #include "sched_trace.h" |
| 12 | 12 | ||
| 13 | 13 | static int map_file(const char* filename, void **addr, size_t *size) | |
| 14 | int walk_sched_trace(void* start, void* end, record_callback_t *cb) | ||
| 15 | { | ||
| 16 | void* pos = start; | ||
| 17 | trace_header_t* header; | ||
| 18 | int ret = 0; | ||
| 19 | |||
| 20 | while (pos < end) { | ||
| 21 | header = (trace_header_t*) pos; | ||
| 22 | if (header->trace >= ST_MAX) | ||
| 23 | return INVALID_HEADER; | ||
| 24 | if (cb->handler[header->trace]) | ||
| 25 | ret = cb->handler[header->trace](header); | ||
| 26 | if (ret) | ||
| 27 | return ret; | ||
| 28 | pos += header->size; | ||
| 29 | } | ||
| 30 | return 0; | ||
| 31 | } | ||
| 32 | |||
| 33 | int walk_sched_traces_ordered(void** start, void** end, unsigned int count, | ||
| 34 | record_callback_t *cb) | ||
| 35 | { | ||
| 36 | void** pos; | ||
| 37 | trace_header_t* header; | ||
| 38 | int ret = 0, i, adv; | ||
| 39 | |||
| 40 | pos = malloc(sizeof(void*) * count); | ||
| 41 | |||
| 42 | for (i = 0; i < count; i++) | ||
| 43 | pos[i] = start[i]; | ||
| 44 | |||
| 45 | do { | ||
| 46 | header = NULL; | ||
| 47 | for (i = 0; i < count; i++) | ||
| 48 | if (pos[i] < end[i] && | ||
| 49 | (!header || header->timestamp > | ||
| 50 | ((trace_header_t*) pos[i])->timestamp)) { | ||
| 51 | header = (trace_header_t*) pos[i]; | ||
| 52 | adv = i; | ||
| 53 | } | ||
| 54 | if (header) { | ||
| 55 | pos[adv] += header->size; | ||
| 56 | /* printf("header id: %d pos=%p adv=%d\n", | ||
| 57 | header->trace, pos[adv], adv); | ||
| 58 | */ | ||
| 59 | if (header->trace >= ST_MAX) | ||
| 60 | return INVALID_HEADER; | ||
| 61 | if (cb->handler[header->trace]) | ||
| 62 | ret = cb->handler[header->trace](header); | ||
| 63 | } | ||
| 64 | } while (header != NULL && !ret); | ||
| 65 | |||
| 66 | free(pos); | ||
| 67 | return 0; | ||
| 68 | } | ||
| 69 | |||
| 70 | static int map_file(const char* filename, void **addr, size_t *size) | ||
| 71 | { | 14 | { |
| 72 | struct stat info; | 15 | struct stat info; |
| 73 | int error = 0; | 16 | int error = 0; |
| 74 | int fd; | 17 | int fd; |
| 75 | 18 | ||
| 76 | error = stat(filename, &info); | 19 | error = stat(filename, &info); |
| 77 | if (!error) { | 20 | if (!error) { |
| 78 | *size = info.st_size; | 21 | *size = info.st_size; |
| 79 | if (info.st_size > 0) { | 22 | if (info.st_size > 0) { |
| 80 | fd = open(filename, O_RDONLY); | 23 | fd = open(filename, O_RDONLY); |
| 81 | if (fd >= 0) { | 24 | if (fd >= 0) { |
| 82 | *addr = mmap(NULL, *size, | 25 | *addr = mmap(NULL, *size, |
| 83 | PROT_READ | PROT_WRITE, | 26 | PROT_READ | PROT_WRITE, |
| 84 | MAP_PRIVATE, fd, 0); | 27 | MAP_PRIVATE, fd, 0); |
| 85 | if (*addr == MAP_FAILED) | 28 | if (*addr == MAP_FAILED) |
| 86 | error = -1; | 29 | error = -1; |
| 87 | close(fd); | 30 | close(fd); |
| 88 | } else | 31 | } else |
| 89 | error = fd; | 32 | error = fd; |
| 90 | } else | 33 | } else |
| 91 | *addr = NULL; | 34 | *addr = NULL; |
| 92 | } | 35 | } |
| 93 | return error; | 36 | return error; |
| 94 | } | 37 | } |
| 95 | 38 | ||
| 96 | static int map_trace(const char *name, void **start, void **end, size_t *size) | 39 | static int map_trace(const char *name, void **start, void **end, size_t *size) |
| 97 | { | 40 | { |
| 98 | int ret; | 41 | int ret; |
| 99 | 42 | ||
| 100 | ret = map_file(name, start, size); | 43 | ret = map_file(name, start, size); |
| 101 | if (!ret) | 44 | if (!ret) |
| 102 | *end = *start + *size; | 45 | *end = *start + *size; |
| 103 | return ret; | 46 | return ret; |
| 104 | } | 47 | } |
| 105 | |||
| 106 | int walk_sched_trace_file(const char* name, int keep_mapped, | ||
| 107 | record_callback_t *cb) | ||
| 108 | { | ||
| 109 | int ret; | ||
| 110 | size_t size; | ||
| 111 | void *start, *end; | ||
| 112 | |||
| 113 | ret = map_trace(name, &start, &end, &size); | ||
| 114 | if (!ret) | ||
| 115 | ret = walk_sched_trace(start, end, cb); | ||
| 116 | |||
| 117 | if (!keep_mapped) | ||
| 118 | munmap(start, size); | ||
| 119 | return ret; | ||
| 120 | } | ||
| 121 | |||
| 122 | |||
| 123 | int walk_sched_trace_files_ordered(const char** names, unsigned int count, | ||
| 124 | int keep_mapped, record_callback_t *cb) | ||
| 125 | { | ||
| 126 | void **start, **end; | ||
| 127 | size_t *size; | ||
| 128 | int i; | ||
| 129 | int ret = 0; | ||
| 130 | |||
| 131 | /* printf("count=%d\n", count); */ | ||
| 132 | |||
| 133 | start = malloc(sizeof(void*) * count); | ||
| 134 | end = malloc(sizeof(void*) * count); | ||
| 135 | size = malloc(sizeof(size_t) * count); | ||
| 136 | |||
| 137 | for (i = 0; i < count; i++) | ||
| 138 | size[i] = 0; | ||
| 139 | for (i = 0; i < count && !ret; i++) { | ||
| 140 | /* printf("mapping %s\n", names[i]); */ | ||
| 141 | ret = map_trace(names[i], start + i, end + i, size + i); | ||
| 142 | } | ||
| 143 | |||
| 144 | if (!ret) | ||
| 145 | /* everything mapped, now walk it */ | ||
| 146 | ret = walk_sched_traces_ordered(start, end, count, cb); | ||
| 147 | |||
| 148 | if (!keep_mapped) | ||
| 149 | for (i = 0; i < count; i++) | ||
| 150 | if (size[i]) | ||
| 151 | munmap(start[i], size[i]); | ||
| 152 | |||
| 153 | free(start); | ||
| 154 | free(end); | ||
| 155 | free(size); | ||
| 156 | return ret; | ||
| 157 | } | ||
