Subversion Repositories shark

Rev

Rev 1520 | Rev 1558 | 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
 
1510 giacomo 64
        switch (*(unsigned short int *)(p) & 0x00FF) {
1491 giacomo 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
 
1508 giacomo 127
          /* Task Context - PID declaration */
128
          case FTrace_EVT_id:
129
                printf("9 ");
130
                tsc = 1;
131
                break;
132
 
1517 giacomo 133
          case FTrace_EVT_cycles_per_msec:
134
                printf("10 ");
135
                tsc = 1;
136
                break;
137
 
1523 giacomo 138
          case FTrace_EVT_task_deadline_miss:
139
                printf("20 ");
140
                tsc = 1;
141
                break;
142
 
143
          case FTrace_EVT_task_wcet_violation:
144
                printf("21 ");
145
                tsc = 1;
146
                break;
147
 
1491 giacomo 148
        }
149
 
150
        tsc_value = (unsigned long long)(*(unsigned int *)(p+4)) << 32;
151
        tsc_value += (unsigned long long)(*(unsigned int *)(p+8));
152
 
1492 giacomo 153
        if (tsc == 1) {
1491 giacomo 154
 
1492 giacomo 155
          printf("%llu ",tsc_value);
156
 
1510 giacomo 157
          switch (*(unsigned short int *)(p) & 0x00FF) {
1492 giacomo 158
 
1520 giacomo 159
            case FTrace_EVT_trace_start:
160
                printf("%d %d ",*(unsigned short int *)(p+2),*(unsigned int *)(p+12));
161
                break;
162
 
1492 giacomo 163
            case FTrace_EVT_interrupt_start:
164
                printf("%d ",*(unsigned short int *)(p+2));
165
                break;
166
 
167
            case FTrace_EVT_timer_wakeup_start:
168
                printf("%d ",0);
169
                break;
170
 
171
            case FTrace_EVT_timer_wakeup_end:
172
            case FTrace_EVT_interrupt_end:
173
                printf("%d ",*(unsigned short int *)(p+2));
174
                break;
175
 
176
            case FTrace_EVT_context_switch:
177
                printf("%d ",*(unsigned short int *)(p+2));
178
                break;
179
 
1494 giacomo 180
            case FTrace_EVT_task_create:
181
                printf("%d %d",*(unsigned short int *)(p+2),*(unsigned int *)(p+12));
182
                break;
183
 
1523 giacomo 184
            case FTrace_EVT_task_deadline_miss:
185
                printf("%d %d",*(unsigned short int *)(p+2),*(unsigned int *)(p+12));
186
                break;
187
 
188
            case FTrace_EVT_task_wcet_violation:
189
                printf("%d %d",*(unsigned short int *)(p+2),*(unsigned int *)(p+12));
190
                break;
191
 
1494 giacomo 192
            case FTrace_EVT_task_activate:
193
                printf("%d ",*(unsigned short int *)(p+2));
194
                break;
195
 
196
            case FTrace_EVT_task_end_cycle:
197
                printf("%d ",*(unsigned short int *)(p+2));
198
                break;
199
 
200
            case FTrace_EVT_task_end:
201
                printf("%d ",*(unsigned short int *)(p+2));
202
                break;
203
 
1508 giacomo 204
            case FTrace_EVT_id:
205
                printf("%d %d",*(unsigned short int *)(p+2),*(unsigned int *)(p+12));
206
                break;
207
 
1517 giacomo 208
            case FTrace_EVT_cycles_per_msec:
209
                printf("%d ",*(unsigned int *)(p+12));
210
                break;
211
 
1492 giacomo 212
          }
213
 
214
          printf("\n");
215
 
216
        }
217
 
1491 giacomo 218
        size = 16;
219
 
220
      ev++;
221
 
222
      p += 16;
223
 
224
      if ((unsigned int)(p) + 10 > (unsigned int)(buffer + n + delta)) break;
225
 
226
      last = p;
227
 
228
    }
229
 
230
    if ((unsigned int)(p) + 10 > (unsigned int)(buffer + n + delta)) break;
231
 
232
  }
233
 
234
  fclose(input_file);
235
 
236
  return 0;
237
 
238
}
239