Rev 1492 | Rev 1508 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1491 | 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 | #include <FTrace.h> |
||
24 | |||
25 | #define READ_BUFFER 2000 |
||
26 | #define DELTA_BUFFER 100 |
||
27 | |||
28 | int main(int argc, char *argv[]) |
||
29 | { |
||
30 | |||
31 | char buffer[READ_BUFFER+DELTA_BUFFER]; |
||
32 | void *p, *last; |
||
1492 | giacomo | 33 | int n,delta,size,tsc; |
1491 | giacomo | 34 | |
35 | unsigned long long ev = 0, tsc_value; |
||
36 | |||
37 | FILE *input_file; |
||
38 | |||
39 | if (argc < 2) { |
||
40 | printf("%s: Enter the input file name [%s filename]\n",argv[0],argv[0]); |
||
41 | exit(1); |
||
42 | } |
||
43 | |||
44 | input_file = fopen(argv[1],"rb"); |
||
45 | |||
46 | last = buffer + READ_BUFFER; |
||
47 | |||
48 | while(!feof(input_file)) { |
||
49 | |||
50 | //move remaining byte |
||
51 | delta = (unsigned int)(buffer) + READ_BUFFER - (unsigned int)(last); |
||
52 | if (delta > 0) memcpy(buffer,last,delta); |
||
53 | |||
54 | n = fread(buffer+delta,1,READ_BUFFER+10,input_file); |
||
55 | fseek(input_file,-(delta+10),SEEK_CUR); |
||
56 | |||
57 | p = buffer; |
||
58 | |||
59 | while ((unsigned int)(p) + 16 <= (unsigned int)(buffer + READ_BUFFER) && |
||
60 | (unsigned int)(p) + 16 <= (unsigned int)(buffer + n + delta)) { |
||
61 | |||
1492 | giacomo | 62 | tsc = 0; |
63 | |||
1491 | giacomo | 64 | switch (*(unsigned short int *)(p)) { |
65 | |||
66 | case FTrace_EVT_ipoint: |
||
67 | printf("%d ",*(unsigned short int *)(p+2)); |
||
1492 | giacomo | 68 | tsc = 1; |
1491 | giacomo | 69 | break; |
70 | |||
1494 | giacomo | 71 | /* Tracer start */ |
1491 | giacomo | 72 | case FTrace_EVT_trace_start: |
73 | printf("0 "); |
||
1492 | giacomo | 74 | tsc = 1; |
1491 | giacomo | 75 | break; |
76 | |||
1494 | giacomo | 77 | /* Tracer stop */ |
1491 | giacomo | 78 | case FTrace_EVT_trace_stop: |
79 | printf("1 "); |
||
1492 | giacomo | 80 | tsc = 1; |
1491 | giacomo | 81 | break; |
82 | |||
1494 | giacomo | 83 | /* Interrupt start (int num) */ |
1491 | giacomo | 84 | case FTrace_EVT_timer_wakeup_start: |
85 | case FTrace_EVT_interrupt_start: |
||
86 | printf("2 "); |
||
1492 | giacomo | 87 | tsc = 1; |
1491 | giacomo | 88 | break; |
89 | |||
1494 | giacomo | 90 | /* Interrupt Stop (int num, or context num is int 3) */ |
91 | case FTrace_EVT_timer_wakeup_end: |
||
1491 | giacomo | 92 | case FTrace_EVT_interrupt_end: |
93 | printf("3 "); |
||
1492 | giacomo | 94 | tsc = 1; |
1491 | giacomo | 95 | break; |
96 | |||
1494 | giacomo | 97 | /* Context to (context num) */ |
1491 | giacomo | 98 | case FTrace_EVT_context_switch: |
99 | printf("4 "); |
||
1492 | giacomo | 100 | tsc = 1; |
1491 | giacomo | 101 | break; |
102 | |||
1494 | giacomo | 103 | /* Task Create (context num, pid num) */ |
104 | case FTrace_EVT_task_create: |
||
105 | printf("5 "); |
||
106 | tsc = 1; |
||
107 | break; |
||
108 | |||
109 | /* Task Activate (context num) */ |
||
110 | case FTrace_EVT_task_activate: |
||
111 | printf("6 "); |
||
112 | tsc = 1; |
||
113 | break; |
||
114 | |||
115 | /* Task End (context num) */ |
||
116 | case FTrace_EVT_task_end: |
||
117 | printf("7 "); |
||
118 | tsc = 1; |
||
119 | break; |
||
120 | |||
121 | /* Task End-Cycle (context num) */ |
||
122 | case FTrace_EVT_task_end_cycle: |
||
123 | printf("8 "); |
||
124 | tsc = 1; |
||
125 | break; |
||
126 | |||
1491 | giacomo | 127 | } |
128 | |||
129 | tsc_value = (unsigned long long)(*(unsigned int *)(p+4)) << 32; |
||
130 | tsc_value += (unsigned long long)(*(unsigned int *)(p+8)); |
||
131 | |||
1492 | giacomo | 132 | if (tsc == 1) { |
1491 | giacomo | 133 | |
1492 | giacomo | 134 | printf("%llu ",tsc_value); |
135 | |||
136 | switch (*(unsigned short int *)(p)) { |
||
137 | |||
138 | case FTrace_EVT_interrupt_start: |
||
139 | printf("%d ",*(unsigned short int *)(p+2)); |
||
140 | break; |
||
141 | |||
142 | case FTrace_EVT_timer_wakeup_start: |
||
143 | printf("%d ",0); |
||
144 | break; |
||
145 | |||
146 | case FTrace_EVT_timer_wakeup_end: |
||
147 | case FTrace_EVT_interrupt_end: |
||
148 | printf("%d ",*(unsigned short int *)(p+2)); |
||
149 | break; |
||
150 | |||
151 | case FTrace_EVT_context_switch: |
||
152 | printf("%d ",*(unsigned short int *)(p+2)); |
||
153 | break; |
||
154 | |||
1494 | giacomo | 155 | case FTrace_EVT_task_create: |
156 | printf("%d %d",*(unsigned short int *)(p+2),*(unsigned int *)(p+12)); |
||
157 | break; |
||
158 | |||
159 | case FTrace_EVT_task_activate: |
||
160 | printf("%d ",*(unsigned short int *)(p+2)); |
||
161 | break; |
||
162 | |||
163 | case FTrace_EVT_task_end_cycle: |
||
164 | printf("%d ",*(unsigned short int *)(p+2)); |
||
165 | break; |
||
166 | |||
167 | case FTrace_EVT_task_end: |
||
168 | printf("%d ",*(unsigned short int *)(p+2)); |
||
169 | break; |
||
170 | |||
1492 | giacomo | 171 | } |
172 | |||
173 | printf("\n"); |
||
174 | |||
175 | } |
||
176 | |||
1491 | giacomo | 177 | size = 16; |
178 | |||
179 | ev++; |
||
180 | |||
181 | p += 16; |
||
182 | |||
183 | if ((unsigned int)(p) + 10 > (unsigned int)(buffer + n + delta)) break; |
||
184 | |||
185 | last = p; |
||
186 | |||
187 | } |
||
188 | |||
189 | if ((unsigned int)(p) + 10 > (unsigned int)(buffer + n + delta)) break; |
||
190 | |||
191 | } |
||
192 | |||
193 | fclose(input_file); |
||
194 | |||
195 | return 0; |
||
196 | |||
197 | } |
||
198 |