diff options
author | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2008-10-29 23:50:00 -0400 |
---|---|---|
committer | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2008-10-29 23:50:00 -0400 |
commit | 78ec4a6186ad56065851e3f3e7ce02e3136c774c (patch) | |
tree | 519c640443a453c8a57d7247232811eafacffc25 | |
parent | 65ca5c2129f50228ce63f2df5ebe79f963e9b4be (diff) |
remove more common code
-rw-r--r-- | include/load.h | 1 | ||||
-rw-r--r-- | src/load.c | 37 | ||||
-rw-r--r-- | src/showst.c | 35 | ||||
-rw-r--r-- | src/st2asy.c | 34 |
4 files changed, 50 insertions, 57 deletions
diff --git a/include/load.h b/include/load.h index a7a242d..0da9886 100644 --- a/include/load.h +++ b/include/load.h | |||
@@ -2,5 +2,6 @@ | |||
2 | #define LOAD_H | 2 | #define LOAD_H |
3 | 3 | ||
4 | int map_trace(const char *name, void **start, void **end, size_t *size); | 4 | int map_trace(const char *name, void **start, void **end, size_t *size); |
5 | struct heap* load(char **files, int no_files, unsigned int *count); | ||
5 | 6 | ||
6 | #endif | 7 | #endif |
@@ -4,6 +4,10 @@ | |||
4 | #include <fcntl.h> | 4 | #include <fcntl.h> |
5 | #include <unistd.h> | 5 | #include <unistd.h> |
6 | 6 | ||
7 | #include <stdio.h> | ||
8 | |||
9 | #include "sched_trace.h" | ||
10 | #include "eheap.h" | ||
7 | 11 | ||
8 | static int map_file(const char* filename, void **addr, size_t *size) | 12 | static int map_file(const char* filename, void **addr, size_t *size) |
9 | { | 13 | { |
@@ -40,3 +44,36 @@ int map_trace(const char *name, void **start, void **end, size_t *size) | |||
40 | *end = *start + *size; | 44 | *end = *start + *size; |
41 | return ret; | 45 | return ret; |
42 | } | 46 | } |
47 | |||
48 | |||
49 | static struct heap* heap_from_file(char* file, unsigned int* count) | ||
50 | { | ||
51 | size_t s; | ||
52 | struct st_event_record *rec, *end; | ||
53 | if (map_trace(file, (void**) &rec, (void**) &end, &s) == 0) { | ||
54 | *count = ((unsigned int)((char*) end - (char*) rec)) | ||
55 | / sizeof(struct st_event_record); | ||
56 | return heapify_events(rec, *count); | ||
57 | } else | ||
58 | perror("mmap"); | ||
59 | return NULL; | ||
60 | } | ||
61 | |||
62 | struct heap* load(char **files, int no_files, unsigned int *count) | ||
63 | { | ||
64 | int i; | ||
65 | unsigned int c; | ||
66 | struct heap *h = NULL, *h2; | ||
67 | for (i = 0; i < no_files; i++) { | ||
68 | h2 = heap_from_file(files[i], &c); | ||
69 | if (!h2) | ||
70 | /* potential memory leak, don't care */ | ||
71 | return NULL; | ||
72 | if (h) | ||
73 | heap_union(earlier_event, h, h2); | ||
74 | else | ||
75 | h = h2; | ||
76 | *count += c; | ||
77 | } | ||
78 | return h; | ||
79 | } | ||
diff --git a/src/showst.c b/src/showst.c index 2767404..6ef3e1f 100644 --- a/src/showst.c +++ b/src/showst.c | |||
@@ -5,41 +5,18 @@ | |||
5 | #include "sched_trace.h" | 5 | #include "sched_trace.h" |
6 | #include "eheap.h" | 6 | #include "eheap.h" |
7 | 7 | ||
8 | static struct heap* file2heap(char* file, unsigned int* count) | ||
9 | { | ||
10 | size_t s; | ||
11 | struct st_event_record *rec, *end; | ||
12 | if (map_trace(file, (void**) &rec, (void**) &end, &s) == 0) { | ||
13 | *count = ((unsigned int)((char*) end - (char*) rec)) | ||
14 | / sizeof(struct st_event_record); | ||
15 | return heapify_events(rec, *count); | ||
16 | } else | ||
17 | perror("mmap"); | ||
18 | return NULL; | ||
19 | } | ||
20 | |||
21 | int main(int argc, char** argv) | 8 | int main(int argc, char** argv) |
22 | { | 9 | { |
23 | int i; | ||
24 | unsigned int count; | 10 | unsigned int count; |
25 | struct heap h, *h2; | 11 | struct heap *h; |
26 | struct heap_node *hn; | 12 | struct heap_node *hn; |
27 | u64 start_time = 0, time; | 13 | u64 start_time = 0, time; |
28 | 14 | ||
29 | heap_init(&h); | 15 | h = load(argv + 1, argc - 1, &count); |
30 | 16 | if (!h) | |
31 | for (i = 1; i < argc; i++) { | 17 | return 1; |
32 | printf("Heapify %s ", argv[i]); | 18 | printf("Loaded %u events.\n", count); |
33 | h2 = file2heap(argv[i], &count); | 19 | while ((hn = heap_take(earlier_event, h))) { |
34 | if (h2) { | ||
35 | printf("merging "); | ||
36 | heap_union(earlier_event, &h, h2); | ||
37 | printf("done [%u events].\n", count); | ||
38 | } else | ||
39 | printf("failed.\n"); | ||
40 | } | ||
41 | |||
42 | while ((hn = heap_take(earlier_event, &h))) { | ||
43 | time = event_time(heap_node_value(hn)); | 20 | time = event_time(heap_node_value(hn)); |
44 | if (!start_time && time) | 21 | if (!start_time && time) |
45 | start_time = time; | 22 | start_time = time; |
diff --git a/src/st2asy.c b/src/st2asy.c index 2767404..090b374 100644 --- a/src/st2asy.c +++ b/src/st2asy.c | |||
@@ -5,41 +5,19 @@ | |||
5 | #include "sched_trace.h" | 5 | #include "sched_trace.h" |
6 | #include "eheap.h" | 6 | #include "eheap.h" |
7 | 7 | ||
8 | static struct heap* file2heap(char* file, unsigned int* count) | ||
9 | { | ||
10 | size_t s; | ||
11 | struct st_event_record *rec, *end; | ||
12 | if (map_trace(file, (void**) &rec, (void**) &end, &s) == 0) { | ||
13 | *count = ((unsigned int)((char*) end - (char*) rec)) | ||
14 | / sizeof(struct st_event_record); | ||
15 | return heapify_events(rec, *count); | ||
16 | } else | ||
17 | perror("mmap"); | ||
18 | return NULL; | ||
19 | } | ||
20 | 8 | ||
21 | int main(int argc, char** argv) | 9 | int main(int argc, char** argv) |
22 | { | 10 | { |
23 | int i; | ||
24 | unsigned int count; | 11 | unsigned int count; |
25 | struct heap h, *h2; | 12 | struct heap *h; |
26 | struct heap_node *hn; | 13 | struct heap_node *hn; |
27 | u64 start_time = 0, time; | 14 | u64 start_time = 0, time; |
28 | 15 | ||
29 | heap_init(&h); | 16 | h = load(argv + 1, argc - 1, &count); |
30 | 17 | if (!h) | |
31 | for (i = 1; i < argc; i++) { | 18 | return 1; |
32 | printf("Heapify %s ", argv[i]); | 19 | printf("Loaded %u events.\n", count); |
33 | h2 = file2heap(argv[i], &count); | 20 | while ((hn = heap_take(earlier_event, h))) { |
34 | if (h2) { | ||
35 | printf("merging "); | ||
36 | heap_union(earlier_event, &h, h2); | ||
37 | printf("done [%u events].\n", count); | ||
38 | } else | ||
39 | printf("failed.\n"); | ||
40 | } | ||
41 | |||
42 | while ((hn = heap_take(earlier_event, &h))) { | ||
43 | time = event_time(heap_node_value(hn)); | 21 | time = event_time(heap_node_value(hn)); |
44 | if (!start_time && time) | 22 | if (!start_time && time) |
45 | start_time = time; | 23 | start_time = time; |