Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1301 | giacomo | 1 | /* |
2 | * Project: S.Ha.R.K. |
||
3 | * |
||
4 | * Coordinators: |
||
5 | * Giorgio Buttazzo <giorgio@sssup.it> |
||
6 | * Paolo Gai <pj@gandalf.sssup.it> |
||
7 | * |
||
8 | * Authors : |
||
9 | * Giacomo Guidi <giacomo@gandalf.sssup.it> |
||
10 | * |
||
11 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
12 | * |
||
13 | * http://www.sssup.it |
||
14 | * http://retis.sssup.it |
||
15 | * http://shark.sssup.it |
||
16 | */ |
||
17 | |||
18 | #include <stdio.h> |
||
19 | #include <unistd.h> |
||
20 | #include <stdlib.h> |
||
21 | #include <string.h> |
||
22 | |||
23 | #define READ_BUFFER 2000 |
||
24 | #define DELTA_BUFFER 100 |
||
25 | |||
26 | struct event_type { |
||
27 | int type; |
||
28 | unsigned long long tsc; |
||
29 | int par[10]; |
||
30 | }; |
||
31 | |||
32 | struct ctx_time_type { |
||
33 | int ctx; |
||
34 | unsigned long long start_time; |
||
35 | unsigned long long total_time; |
||
36 | }; |
||
37 | |||
38 | struct ctx_time_type ctx_time[256]; |
||
39 | unsigned long long last_time; |
||
40 | int total_ctx = 0; |
||
41 | int last_ctx = -1; |
||
42 | |||
43 | void analyze_event(struct event_type *e) { |
||
44 | |||
45 | int i; |
||
46 | |||
47 | if (e->type == 0x3B || e->type == 0x15) { |
||
48 | |||
49 | i = 0; |
||
50 | while (ctx_time[i].ctx != e->par[0] && i < total_ctx) { |
||
51 | i++; |
||
52 | } |
||
53 | |||
54 | if (ctx_time[i].start_time == 0) { |
||
55 | ctx_time[i].ctx = e->par[0]; |
||
56 | ctx_time[i].start_time = e->tsc; |
||
57 | ctx_time[i].total_time = 0; |
||
58 | |||
59 | if (e->tsc < last_time) { |
||
60 | printf("Error events sequence\n"); |
||
61 | exit(2); |
||
62 | } |
||
63 | |||
64 | if (last_ctx != -1) ctx_time[last_ctx].total_time += (e->tsc - last_time); |
||
65 | |||
66 | last_time = e->tsc; |
||
67 | last_ctx = i; |
||
68 | total_ctx++; |
||
69 | |||
70 | } else { |
||
71 | |||
72 | if (e->tsc < last_time) { |
||
73 | printf("Error events sequence\n"); |
||
74 | exit(2); |
||
75 | } |
||
76 | |||
77 | ctx_time[last_ctx].total_time += (e->tsc - last_time); |
||
78 | last_time = e->tsc; |
||
79 | last_ctx = i; |
||
80 | |||
81 | } |
||
82 | |||
83 | } |
||
84 | |||
85 | if (e->type == 0x2b || e->type == 0x03) { |
||
86 | |||
87 | if (last_ctx == -1) return; |
||
88 | |||
89 | if (e->tsc < last_time) { |
||
90 | printf("Error events sequence\n"); |
||
91 | exit(2); |
||
92 | } |
||
93 | |||
94 | ctx_time[last_ctx].total_time += (e->tsc - last_time); |
||
95 | last_time = e->tsc; |
||
96 | |||
97 | } |
||
98 | |||
99 | if (e->type == 0x13) { |
||
100 | |||
101 | if (e->tsc < last_time) { |
||
102 | printf("Error events sequence\n"); |
||
103 | exit(2); |
||
104 | } |
||
105 | |||
106 | last_time = e->tsc; |
||
107 | |||
108 | } |
||
109 | |||
110 | |||
111 | } |
||
112 | |||
113 | int main(int argc, char *argv[]) |
||
114 | { |
||
115 | |||
116 | char buffer[READ_BUFFER+DELTA_BUFFER]; |
||
117 | void *p, *last; |
||
118 | int n,i,delta,size; |
||
119 | struct event_type evt; |
||
120 | |||
121 | unsigned long long ev = 0,start,stop; |
||
122 | unsigned int total_simulation = 0; |
||
123 | |||
124 | FILE *input_file; |
||
125 | |||
126 | if (argc < 2) { |
||
127 | printf("%s: Enter the input file name [%s filename]\n",argv[0],argv[0]); |
||
128 | exit(1); |
||
129 | } |
||
130 | |||
131 | memset(ctx_time,0,sizeof(ctx_time)); |
||
132 | total_ctx = 0; |
||
133 | |||
134 | input_file = fopen(argv[1],"rb"); |
||
135 | |||
136 | last = buffer + READ_BUFFER; |
||
137 | |||
138 | while(!feof(input_file)) { |
||
139 | |||
140 | //move remaining byte |
||
141 | delta = (unsigned int)(buffer) + READ_BUFFER - (unsigned int)(last); |
||
142 | if (delta > 0) memcpy(buffer,last,delta); |
||
143 | |||
144 | n = fread(buffer+delta,1,READ_BUFFER+10,input_file); |
||
145 | |||
146 | fseek(input_file,-(delta+10),SEEK_CUR); |
||
147 | |||
148 | p = buffer; |
||
149 | |||
150 | while ((unsigned int)(p) + *(unsigned char *)(p+9) <= (unsigned int)(buffer + READ_BUFFER) && |
||
151 | (unsigned int)(p) + *(unsigned char *)(p+9) <= (unsigned int)(buffer + n + delta)) { |
||
152 | |||
153 | evt.type = (int)(*(unsigned char *)(p)); |
||
154 | evt.tsc = (unsigned long long)(*(unsigned int *)(p+1)); |
||
155 | evt.tsc <<= 32; |
||
156 | evt.tsc += (unsigned long long)(*(unsigned int *)(p+5)); |
||
157 | |||
158 | size = *(unsigned char *)(p+9); |
||
159 | |||
160 | if (evt.type == 0x20) { |
||
161 | printf("Start Simulation\n"); |
||
162 | start = evt.tsc; |
||
163 | } |
||
164 | |||
165 | if (evt.type == 0x30) { |
||
166 | printf("Stop Simulation\n"); |
||
167 | stop = evt.tsc; |
||
168 | } |
||
169 | |||
170 | size -= 10; |
||
171 | i = 0; |
||
172 | while (size > 0) { |
||
173 | evt.par[i] = (int)(*(unsigned int *)(p+10+i*4)); |
||
174 | i++; |
||
175 | size -= 4; |
||
176 | } |
||
177 | |||
178 | ev++; |
||
179 | |||
180 | analyze_event(&evt); |
||
181 | |||
182 | p += *(unsigned char *)(p+9); |
||
183 | |||
184 | if ((unsigned int)p + 10 > (unsigned int)(buffer + n + delta)) break; |
||
185 | |||
186 | last = p; |
||
187 | |||
188 | } |
||
189 | |||
190 | if ((unsigned int)p + 10 > (unsigned int)(buffer + n + delta)) break; |
||
191 | |||
192 | } |
||
193 | |||
194 | fclose(input_file); |
||
195 | |||
196 | printf("Total Time %d\n",(unsigned int)((stop-start) * 1000 / 501162)); |
||
197 | |||
198 | printf ("Total Ctx = %d\n",total_ctx); |
||
199 | |||
200 | total_simulation = 0; |
||
201 | for (i=0;i<total_ctx;i++) { |
||
202 | printf("Total Time Ctx %d => %d\n",ctx_time[i].ctx,(unsigned int)(ctx_time[i].total_time * 1000 / 501162)); |
||
203 | total_simulation += (unsigned int)(ctx_time[i].total_time * 1000 / 501162); |
||
204 | } |
||
205 | |||
206 | printf ("Total Simulation %d\n",total_simulation); |
||
207 | |||
208 | return 0; |
||
209 | |||
210 | } |
||
211 |