aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBjoern B. Brandenburg <bbb@cs.unc.edu>2007-10-18 13:10:15 -0400
committerBjoern B. Brandenburg <bbb@cs.unc.edu>2007-10-18 13:10:15 -0400
commitf3545b2e8720a7116fec377c8b748b45cc3c5fa2 (patch)
treefb2f35af7297495f6a7cd571d6e4416794b097e1 /src
parent3d07fc5c31dafaadecfea2b338471d9df648b00c (diff)
implement sched_trace multifile walking support
Diffstat (limited to 'src')
-rw-r--r--src/sched_trace.c124
1 files changed, 100 insertions, 24 deletions
diff --git a/src/sched_trace.c b/src/sched_trace.c
index 011b13b..5dfbba4 100644
--- a/src/sched_trace.c
+++ b/src/sched_trace.c
@@ -31,28 +31,74 @@ int walk_sched_trace(void* start, void* end, record_callback_t *cb)
31 return 0; 31 return 0;
32} 32}
33 33
34int walk_sched_traces_ordered(void** start, void** end, unsigned int count,
35 record_callback_t *cb)
36{
37 void** pos;
38 trace_header_t* header;
39 int ret, i, adv;
40
41 pos = malloc(sizeof(void*) * count);
42
43 for (i = 0; i < count; i++)
44 pos[i] = start[i];
45
46 do {
47 header = NULL;
48 for (i = 0; i < count; i++)
49 if (pos[i] < end[i] &&
50 (!header || header->timestamp >
51 ((trace_header_t*) pos[i])->timestamp)) {
52 header = (trace_header_t*) pos[i];
53 adv = i;
54 }
55 if (header) {
56 pos[i] += header->size;
57 if (header->trace >= ST_MAX)
58 return INVALID_HEADER;
59 if (cb->handler[header->trace])
60 ret = cb->handler[header->trace](header);
61 }
62 } while (header != NULL && !ret);
63
64 free(pos);
65 return 0;
66}
67
34static int map_file(const char* filename, void **addr, size_t *size) 68static int map_file(const char* filename, void **addr, size_t *size)
35{ 69{
36 struct stat info; 70 struct stat info;
37 int error = 0; 71 int error = 0;
38 int fd; 72 int fd;
39 73
40 error = stat(filename, &info); 74 error = stat(filename, &info);
41 if (!error) { 75 if (!error) {
42 *size = info.st_size; 76 *size = info.st_size;
43 if (info.st_size > 0) { 77 if (info.st_size > 0) {
44 fd = open(filename, O_RDONLY); 78 fd = open(filename, O_RDONLY);
45 if (fd >= 0) { 79 if (fd >= 0) {
46 *addr = mmap(NULL, *size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); 80 *addr = mmap(NULL, *size,
47 if (*addr == MAP_FAILED) 81 PROT_READ | PROT_WRITE,
48 error = -1; 82 MAP_PRIVATE, fd, 0);
49 close(fd); 83 if (*addr == MAP_FAILED)
50 } else 84 error = -1;
51 error = fd; 85 close(fd);
52 } else 86 } else
53 *addr = NULL; 87 error = fd;
54 } 88 } else
55 return error; 89 *addr = NULL;
90 }
91 return error;
92}
93
94static int map_trace(const char *name, void **start, void **end, size_t *size)
95{
96 int ret;
97
98 ret = map_file(name, start, size);
99 if (!ret)
100 *end = *start + *size;
101 return ret;
56} 102}
57 103
58int walk_sched_trace_file(const char* name, int keep_mapped, 104int walk_sched_trace_file(const char* name, int keep_mapped,
@@ -62,14 +108,44 @@ int walk_sched_trace_file(const char* name, int keep_mapped,
62 size_t size; 108 size_t size;
63 void *start, *end; 109 void *start, *end;
64 110
65 ret = map_file(name, &start, &size); 111 ret = map_trace(name, &start, &end, &size);
66 if (!ret) { 112 if (!ret)
67 end = start + size;
68 ret = walk_sched_trace(start, end, cb); 113 ret = walk_sched_trace(start, end, cb);
69 } 114
70 if (!keep_mapped) 115 if (!keep_mapped)
71 munmap(start, size); 116 munmap(start, size);
72 return ret; 117 return ret;
73} 118}
74 119
75 120
121int walk_sched_trace_files_ordered(const char** names, unsigned int count,
122 int keep_mapped, record_callback_t *cb)
123{
124 void **start, **end;
125 size_t *size;
126 int i;
127 int ret;
128
129 start = malloc(sizeof(void*) * count);
130 end = malloc(sizeof(void*) * count);
131 size = malloc(sizeof(size_t) * count);
132
133 for (i = 0; i < count; i++)
134 size[i] = 0;
135 for (i = 0; i < count && !ret; i++)
136 ret = map_trace(names[i], start + i, end + i, size + i);
137
138 if (!ret)
139 /* everything mapped, now walk it */
140 ret = walk_sched_traces_ordered(start, end, count, cb);
141
142 if (!keep_mapped)
143 for (i = 0; i < count; i++)
144 if (size[i])
145 munmap(start[i], size[i]);
146
147 free(start);
148 free(end);
149 free(size);
150 return ret;
151}