diff options
author | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2008-10-30 00:39:28 -0400 |
---|---|---|
committer | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2008-10-30 00:39:28 -0400 |
commit | 3afce680c89f2737003665d086f9746f5520d1d4 (patch) | |
tree | 2012b16153c645f4e7d38b1985fbbf4ea0ec9d76 | |
parent | a737d9da343cb5667d0bbc47404ee3abe6d572d2 (diff) |
add splitting of event stream
-rw-r--r-- | src/st2asy.c | 130 |
1 files changed, 118 insertions, 12 deletions
diff --git a/src/st2asy.c b/src/st2asy.c index 090b374..d3c7ca5 100644 --- a/src/st2asy.c +++ b/src/st2asy.c | |||
@@ -5,27 +5,133 @@ | |||
5 | #include "sched_trace.h" | 5 | #include "sched_trace.h" |
6 | #include "eheap.h" | 6 | #include "eheap.h" |
7 | 7 | ||
8 | #define MAX_TASKS 100 | ||
8 | 9 | ||
9 | int main(int argc, char** argv) | 10 | struct evlink { |
11 | struct evlink *next; | ||
12 | struct st_event_record* rec; | ||
13 | }; | ||
14 | |||
15 | struct task { | ||
16 | int pid; | ||
17 | unsigned int no_events; | ||
18 | struct st_event_record* name; | ||
19 | struct st_event_record* param; | ||
20 | struct evlink* events; | ||
21 | struct evlink** next; | ||
22 | }; | ||
23 | |||
24 | static struct task tasks[MAX_TASKS]; | ||
25 | |||
26 | static struct task* by_pid(int pid) | ||
10 | { | 27 | { |
11 | unsigned int count; | 28 | int i = 0; |
12 | struct heap *h; | 29 | /* slow, don't care for now */ |
30 | for (i = 0; i < MAX_TASKS; i++) { | ||
31 | if (!tasks[i].pid) /* end, allocate */ | ||
32 | tasks[i].pid = pid; | ||
33 | if (tasks[i].pid == pid) | ||
34 | return tasks + i; | ||
35 | } | ||
36 | return NULL; | ||
37 | } | ||
38 | |||
39 | static void split(struct heap* h, unsigned int count) | ||
40 | { | ||
41 | struct evlink *lnk = malloc(count * sizeof(struct evlink)); | ||
13 | struct heap_node *hn; | 42 | struct heap_node *hn; |
14 | u64 start_time = 0, time; | 43 | u64 start_time = 0, time; |
44 | struct st_event_record *rec; | ||
45 | struct task* t; | ||
46 | |||
47 | if (!lnk) { | ||
48 | perror("malloc"); | ||
49 | return; | ||
50 | } | ||
15 | 51 | ||
16 | h = load(argv + 1, argc - 1, &count); | ||
17 | if (!h) | ||
18 | return 1; | ||
19 | printf("Loaded %u events.\n", count); | ||
20 | while ((hn = heap_take(earlier_event, h))) { | 52 | while ((hn = heap_take(earlier_event, h))) { |
21 | time = event_time(heap_node_value(hn)); | 53 | rec = heap_node_value(hn); |
54 | time = event_time(rec); | ||
22 | if (!start_time && time) | 55 | if (!start_time && time) |
23 | start_time = time; | 56 | start_time = time; |
24 | time -= start_time; | 57 | t = by_pid(rec->hdr.pid); |
25 | time /= 1000000; /* convert to milliseconds */ | 58 | if (!t) { |
26 | printf("[%10llu] ", time); | 59 | printf("dropped %d\n", rec->hdr.pid); |
27 | print_event(heap_node_value(hn)); | 60 | continue; |
61 | } | ||
62 | switch (rec->hdr.type) { | ||
63 | case ST_PARAM: | ||
64 | t->param = rec; | ||
65 | break; | ||
66 | case ST_NAME: | ||
67 | t->name = rec; | ||
68 | break; | ||
69 | default: | ||
70 | lnk->rec = rec; | ||
71 | lnk->next = NULL; | ||
72 | *(t->next) = lnk; | ||
73 | t->next = &lnk->next; | ||
74 | lnk++; | ||
75 | t->no_events++; | ||
76 | break; | ||
77 | } | ||
28 | } | 78 | } |
79 | } | ||
29 | 80 | ||
81 | static const char* tsk_name(struct task* t) | ||
82 | { | ||
83 | if (t->name) | ||
84 | return t->name->data.name.cmd; | ||
85 | else | ||
86 | return "<unknown>"; | ||
87 | } | ||
88 | |||
89 | static u32 per(struct task* t) | ||
90 | { | ||
91 | if (t->param) | ||
92 | return t->param->data.param.period; | ||
93 | else | ||
94 | return 0; | ||
95 | } | ||
96 | |||
97 | static u32 exe(struct task* t) | ||
98 | { | ||
99 | if (t->param) | ||
100 | return t->param->data.param.wcet; | ||
101 | else | ||
102 | return 0; | ||
103 | } | ||
104 | |||
105 | |||
106 | static void show_tasks(void) | ||
107 | { | ||
108 | int i; | ||
109 | for (i = 0; i < MAX_TASKS; i++) | ||
110 | if (tasks[i].pid) { | ||
111 | printf("%5d:%20s (%10u,%10u) [%6u events]\n", tasks[i].pid, | ||
112 | tsk_name(tasks + i), | ||
113 | exe(tasks + i), | ||
114 | per(tasks + i), | ||
115 | tasks[i].no_events); | ||
116 | } | ||
117 | } | ||
118 | |||
119 | int main(int argc, char** argv) | ||
120 | { | ||
121 | int i; | ||
122 | unsigned int count; | ||
123 | struct heap *h; | ||
124 | |||
125 | for (i = 0; i < MAX_TASKS; i++) { | ||
126 | tasks[i] = (struct task) {0, 0, NULL, NULL, NULL, NULL}; | ||
127 | tasks[i].next = &tasks[i].events; | ||
128 | } | ||
129 | |||
130 | h = load(argv + 1, argc - 1, &count); | ||
131 | if (!h) | ||
132 | return 1; | ||
133 | printf("Loaded %u events.\n", count); | ||
134 | split(h, count); | ||
135 | show_tasks(); | ||
30 | return 0; | 136 | return 0; |
31 | } | 137 | } |