Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1085 pj 1
/*
2
 * Project: HARTIK (HA-rd R-eal TI-me K-ernel)
3
 *
4
 * Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
5
 *               Gerardo Lamastra <gerardo@sssup.it>
6
 *
7
 * Authors     : Massimiliano Giorgi <massy@hartik.sssup.it>
8
 * (see authors.txt for full list of hartik's authors)
9
 *
10
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
11
 *
12
 * http://www.sssup.it
13
 * http://retis.sssup.it
14
 * http://hartik.sssup.it
15
 */
16
 
17
/*
18
 * Copyright (C) 1999 Massimiliano Giorgi
19
 *
20
 * This program is free software; you can redistribute it and/or modify
21
 * it under the terms of the GNU General Public License as published by
22
 * the Free Software Foundation; either version 2 of the License, or
23
 * (at your option) any later version.
24
 *
25
 * This program is distributed in the hope that it will be useful,
26
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28
 * GNU General Public License for more details.
29
 *
30
 * You should have received a copy of the GNU General Public License
31
 * along with this program; if not, write to the Free Software
32
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
33
 *
34
 */
35
 
36
/*
37
 * CVS :        $Id: jdump.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
38
 *
39
 * File:        $File$
40
 * Revision:    $Revision: 1.1.1.1 $
41
 * Last update: $Date: 2002-09-02 09:37:48 $
42
 */
43
 
44
#include <netinet/in.h>
45
#include <stdio.h>
46
#include <string.h>
47
#include <unistd.h>
48
#include <fcntl.h>
49
 
50
#include "types.h"
51
#include <trace.h>
52
#include "util.h"
53
 
54
/*
55
 *
56
 *
57
 *
58
 */
59
 
60
/* All times are dived by this costant. */
61
#define TIMESCALE 1
62
 
63
/* If defined dump on stdout the packets (in ascii) that will be written
64
 * on the output file (the file of the tracer).
65
 */
66
 
67
#define DUMPOUT
68
 
69
/*
70
 *
71
 *
72
 *
73
 */
74
 
75
int pippo=0;
76
 
77
int writeInt(int h, int x)
78
{
79
  int y,res;
80
  y=htonl(x);
81
  res=write(h,&y,sizeof(int));
82
  return res!=sizeof(int);
83
}
84
 
85
 
86
int writeStr(int h, char *s)
87
{
88
  int res,size;
89
  size=strlen(s);
90
  writeInt(h,size);
91
  res=write(h,s,size);
92
  return res!=size;
93
}
94
 
95
/*
96
 *
97
 */
98
 
99
#define TASK_ARRIVAL      0
100
#define TASK_SCHEDULE     1
101
#define TASK_DESCHEDULE   2
102
#define TASK_END          3
103
#define TASK_DLINEPOST    4
104
#define TASK_DLINESET     5
105
#define TASK_WAIT         6
106
#define TASK_SIGNAL       7
107
#define TASK_IDLE         8
108
#define TASK_NAME         9
109
 
110
#define EVT_NUMBER       10
111
 
112
char *eventsname[]={
113
  "task_arrival",
114
  "task_schedule",
115
  "task_deschedule",
116
  "task_end",
117
  "task_dlinepost",
118
  "task_dlineset",
119
  "task_wait",
120
  "task_signal",
121
  "task_idle",
122
  "task_name"
123
};
124
 
125
struct j_evt_prolog {
126
  int                 type;
127
  int                 time;
128
};
129
 
130
struct j_evt_task {
131
  struct j_evt_prolog p;
132
  int                 task;
133
};
134
 
135
struct j_evt_dlinepost {
136
  struct j_evt_task   t;
137
  int                 taskD;
138
  int                 taskD2;
139
};
140
 
141
struct j_evt_dlineset {
142
  struct j_evt_task   t;
143
  int                 taskD;
144
};
145
 
146
struct j_evt_semaph {
147
  struct j_evt_task   t;
148
  int                 res;
149
  char                *name;
150
};
151
 
152
struct j_evt_name {
153
  struct j_evt_task   t;
154
  char                *name;
155
};
156
 
157
/*
158
 *
159
 */
160
 
161
int j_write_prolog(int h, void *ptr)
162
{
163
#ifdef DUMPOUT
164
  printf("%10i ",((struct j_evt_prolog *)ptr)->time);
165
  printf("%-18s ",eventsname[((struct j_evt_prolog *)ptr)->type]);
166
#endif
167
  if (writeInt(h,((struct j_evt_prolog *)ptr)->type)) return -2;
168
  if (writeInt(h,((struct j_evt_prolog *)ptr)->time)) return -3;
169
  return 0;
170
}
171
 
172
int j_write_task(int h, void *ptr)
173
{
174
  int res;
175
  res=j_write_prolog(h,ptr);
176
#ifdef DUMPOUT
177
  printf("tsk=%i ",((struct j_evt_task *)ptr)->task);
178
#endif
179
  if (res) return res;
180
  if (writeInt(h,((struct j_evt_task *)ptr)->task)) return -4;
181
  return 0;
182
}
183
 
184
int j_write_dlinepost(int h, void *ptr)
185
{
186
  int res;
187
  res=j_write_task(h,ptr);
188
  if (res) return res;
189
  if (writeInt(h,((struct j_evt_dlinepost *)ptr)->taskD)) return -5;
190
  if (writeInt(h,((struct j_evt_dlinepost *)ptr)->taskD2)) return -6;
191
  return 0;
192
}
193
 
194
int j_write_dlineset(int h, void *ptr)
195
{
196
  int res;
197
  res=j_write_task(h,ptr);
198
  if (res) return res;
199
  if (writeInt(h,((struct j_evt_dlineset *)ptr)->taskD)) return -7;
200
  return 0;
201
}
202
 
203
int j_write_semaph(int h, void *ptr)
204
{
205
  int res;
206
  res=j_write_task(h,ptr);
207
  if (res) return res;
208
  if (writeInt(h,((struct j_evt_semaph *)ptr)->res)) return -8;
209
  if (writeStr(h,((struct j_evt_semaph *)ptr)->name)) return -9;
210
  return 0;
211
}
212
 
213
int j_write_name(int h, void *ptr)
214
{
215
  int res;
216
  res=j_write_task(h,ptr);
217
#ifdef DUMPOUT
218
  printf("name='%s' ",((struct j_evt_name *)ptr)->name);
219
#endif
220
  if (res) return res;
221
  if (writeStr(h,((struct j_evt_name *)ptr)->name)) return -10;
222
  return 0;
223
}
224
 
225
int writeEvent(int h, void *ptr)
226
{
227
  int res;
228
 
229
  //printf("<%i>",((struct j_evt_prolog*)ptr)->type);
230
 
231
  ((struct j_evt_prolog*)ptr)->time/=TIMESCALE;
232
 
233
  switch(((struct j_evt_prolog*)ptr)->type) {
234
  case TASK_ARRIVAL:
235
  case TASK_SCHEDULE:
236
  case TASK_DESCHEDULE:
237
  case TASK_END:
238
  case TASK_IDLE:
239
    res=j_write_task(h,ptr);
240
    break;
241
  case TASK_DLINEPOST:
242
    res=j_write_dlinepost(h,ptr);
243
    break;
244
  case TASK_DLINESET:
245
    res=j_write_dlineset(h,ptr);
246
    break;
247
  case TASK_WAIT:
248
  case TASK_SIGNAL:
249
    res=j_write_semaph(h,ptr);
250
    break;
251
  case TASK_NAME:
252
    res=j_write_name(h,ptr);
253
    break;
254
  default:
255
    return -1;
256
 
257
  }
258
 
259
#ifdef DUMPOUT
260
  printf(" \n");
261
#endif
262
 
263
  return res;
264
}
265
 
266
/*
267
 *
268
 *
269
 *
270
 */
271
 
272
#define MAX_PROC 150
273
 
274
//int activated[MAX_PROC];
275
 
276
int cxx=0;
277
/* write MAXC-1 events */
278
#define MAXC 14
279
 
280
long lasttime;
281
 
282
int sys_event(int h, void *param)
283
{
284
  static int prevtask=-1;
285
  trc_event_t *ptr=(trc_event_t *)param;
286
  struct j_evt_task evt;
287
 
288
  evt.p.time=ptr->time;
289
  evt.task=ptr->x.sys.task;
290
 
291
  lasttime=ptr->time;
292
  switch(ptr->event) {
293
 
294
  case TRC_CREATE:
295
    return 0;
296
 
297
  case TRC_ACTIVATE:
298
  case TRC_INTACTIVATION:
299
 
300
 
301
    //activated[ptr->x.sys.task]=1;
302
 
303
 
304
    evt.p.type=TASK_ARRIVAL;
305
    break;
306
 
307
  case TRC_DESTROY:
308
 
309
 
310
    //activated[ptr->x.sys.task]=0;
311
 
312
 
313
 
314
    return 0;                    
315
 
316
  case TRC_DELAY:
317
    prevtask=-1;
318
    evt.p.type=TASK_DESCHEDULE;
319
    break;
320
 
321
  case TRC_SLEEP:
322
    prevtask=-1;
323
    evt.p.type=TASK_DESCHEDULE;
324
    break;
325
 
326
  case TRC_ENDCYCLE:
327
    evt.p.type=TASK_END;
328
    break;
329
 
330
  case TRC_SCHEDULE:
331
    if (prevtask!=-1) {
332
      struct j_evt_task evt2;
333
      int res;
334
      evt2.p.time=ptr->time;
335
      evt2.p.type=TASK_DESCHEDULE;
336
      evt2.task=prevtask;
337
      res=writeEvent(h,&evt2);  
338
      if (res!=0) return -1;
339
    }
340
 
341
    /*
342
      if (!activated[ptr->x.sys.task]) {
343
      struct j_evt_task evt2;
344
 
345
      evt2.p.time=ptr->time-1;
346
      evt2.task=ptr->x.sys.task;
347
      evt2.p.type=TASK_ARRIVAL;
348
 
349
      writeEvent(h,&evt2);  
350
 
351
      activated[ptr->x.sys.task]=1;
352
      }
353
    */
354
 
355
    evt.p.type=TASK_SCHEDULE;
356
    prevtask=ptr->x.sys.task;
357
    break;
358
 
359
  default:
360
    return 0;
361
  }
362
 
363
  cxx++;
364
  if (cxx==MAXC) return -1;
365
 
366
  return writeEvent(h,&evt);  
367
}
368
 
369
 
370
int sem_event(int h,void *param)
371
{
372
  //trc_event_t *ptr=(trc_event_t *)param;
373
  //struct j_evt_semaph evt;
374
 
375
  return 0;
376
  /*  
377
  evt.t.p.time=ptr->x.norm.when;
378
  evt.t.task=ptr->x.norm.who;
379
  switch(ptr->what) {
380
    case TRC_SEM_WAIT:   evt.t.p.type=TASK_WAIT; break;
381
    case TRC_SEM_SIGNAL: evt.t.p.type=TASK_SIGNAL; break;
382
    case TRC_SEM_WAITNB: return 0;
383
    default:             return 0;
384
  }
385
  evt.res=1;
386
  evt.name="NoName";
387
  return j_write_semaph(h,&evt);
388
  */
389
}
390
 
391
/* -- */
392
 
393
#define MAX_PROC 150
394
int names[MAX_PROC];
395
 
396
int outfile;
397
 
398
int dumpfunc(trc_event_t *ptr)
399
{
400
  //printf("{%i}",ptr->event);
401
 
402
  if (!names[ptr->x.sys.task]) {
403
    struct j_evt_name evtname;
404
    static char name[24];
405
 
406
    cxx++;
407
    if (cxx==MAXC) return -1;
408
 
409
    evtname.t.p.time=lasttime;
410
    evtname.t.task=ptr->x.sys.task;
411
    evtname.t.p.type=TASK_NAME;
412
    sprintf(name,"task%03i",ptr->x.sys.task);
413
    evtname.name=name;
414
    writeEvent(outfile,&evtname);
415
    names[ptr->x.sys.task]=1;
416
 
417
  }
418
 
419
  switch(event_class(ptr->event)) {
420
    case TRC_CLASS_SYSTEM:
421
      return sys_event(outfile,ptr);
422
    case TRC_CLASS_SEM:
423
      return 0;
424
      return sem_event(outfile,ptr);
425
    case TRC_CLASS_USER:
426
      return 0;
427
  }
428
  return 0;
429
}
430
 
431
/*
432
 *
433
 */
434
 
435
#ifndef O_BINARY
436
#define O_BINARY 0
437
#endif
438
 
439
int main(int argc, char *argv[])
440
{
441
  int res;
442
  int i;
443
 
444
  if (argc!=3) {
445
    fprintf(stderr,"missing filenames\n");
446
    fprintf(stderr,"usage: jdump H4tracefilename JTRACERtracefilename\n");
447
    return -1;
448
  }
449
 
450
  for (i=0;i<MAX_PROC;i++) {
451
    names[i]=0;
452
    //activated[i]=0;
453
  }
454
 
455
  outfile=open(argv[2],O_WRONLY|O_CREAT|O_TRUNC|O_BINARY,0777);
456
  if (outfile==-1) {
457
    perror("can't open outfile");
458
    return -1;
459
  }  
460
  res=read_trace(argv[1],dumpfunc);
461
  close(outfile);
462
 
463
  //fprintf(stderr,"result=%i",res);
464
  return 0;
465
}