Subversion Repositories shark

Rev

Rev 1655 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1655 giacomo 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 2004-05-24 18:03:44 giacomo Exp $
38
 *
39
 * File:        $File$
40
 * Revision:    $Revision: 1.1.1.1 $
41
 * Last update: $Date: 2004-05-24 18:03:44 $
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
 * This filter converts trace file formats from SHARK to JTRACER
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 10000
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_DISABLE:
317
 
318
    return 0;    
319
 
320
  case TRC_DELAY:
321
    prevtask=-1;
322
    evt.p.type=TASK_DESCHEDULE;
323
    break;
324
 
325
  case TRC_SLEEP:
326
    prevtask=-1;
327
    evt.p.type=TASK_DESCHEDULE;
328
    break;
329
 
330
  case TRC_ENDCYCLE:
331
    prevtask=-1;
332
    evt.p.type=TASK_END;
333
    break;
334
 
335
  case TRC_SCHEDULE:
336
    if (prevtask!=-1) {
337
      struct j_evt_task evt2;
338
      int res;
339
      evt2.p.time=ptr->time;
340
      evt2.p.type=TASK_DESCHEDULE;
341
      evt2.task=prevtask;
342
      res=writeEvent(h,&evt2);  
343
      if (res!=0) return -1;
344
    }
345
 
346
    /*
347
      if (!activated[ptr->x.sys.task]) {
348
      struct j_evt_task evt2;
349
 
350
      evt2.p.time=ptr->time-1;
351
      evt2.task=ptr->x.sys.task;
352
      evt2.p.type=TASK_ARRIVAL;
353
 
354
      writeEvent(h,&evt2);  
355
 
356
      activated[ptr->x.sys.task]=1;
357
      }
358
    */
359
 
360
    evt.p.type=TASK_SCHEDULE;
361
    prevtask=ptr->x.sys.task;
362
    break;
363
 
364
  default:
365
    return 0;
366
  }
367
 
368
  cxx++;
369
  if (cxx==MAXC) return -1;
370
 
371
  return writeEvent(h,&evt);  
372
}
373
 
374
 
375
int sem_event(int h,void *param)
376
{
377
  //trc_event_t *ptr=(trc_event_t *)param;
378
  //struct j_evt_semaph evt;
379
 
380
  return 0;
381
  /*  
382
  evt.t.p.time=ptr->x.norm.when;
383
  evt.t.task=ptr->x.norm.who;
384
  switch(ptr->what) {
385
    case TRC_SEM_WAIT:   evt.t.p.type=TASK_WAIT; break;
386
    case TRC_SEM_SIGNAL: evt.t.p.type=TASK_SIGNAL; break;
387
    case TRC_SEM_WAITNB: return 0;
388
    default:             return 0;
389
  }
390
  evt.res=1;
391
  evt.name="NoName";
392
  return j_write_semaph(h,&evt);
393
  */
394
}
395
 
396
/* -- */
397
 
398
#define MAX_PROC 150
399
int names[MAX_PROC];
400
 
401
int outfile;
402
 
403
int dumpfunc(trc_event_t *ptr)
404
{
405
  //printf("{%i}",ptr->event);
406
 
407
  if (!names[ptr->x.sys.task]) {
408
    struct j_evt_name evtname;
409
    static char name[24];
410
 
411
    cxx++;
412
    if (cxx==MAXC) return -1;
413
 
414
    evtname.t.p.time=lasttime;
415
    evtname.t.task=ptr->x.sys.task;
416
    evtname.t.p.type=TASK_NAME;
417
    sprintf(name,"task%03i",ptr->x.sys.task);
418
    evtname.name=name;
419
    writeEvent(outfile,&evtname);
420
    names[ptr->x.sys.task]=1;
421
 
422
  }
423
 
424
  switch(event_class(ptr->event)) {
425
    case TRC_CLASS_SYSTEM:
426
      return sys_event(outfile,ptr);
427
    case TRC_CLASS_SEM:
428
      return 0;
429
      return sem_event(outfile,ptr);
430
    case TRC_CLASS_USER:
431
      return 0;
432
  }
433
  return 0;
434
}
435
 
436
/*
437
 *
438
 */
439
 
440
#ifndef O_BINARY
441
#define O_BINARY 0
442
#endif
443
 
444
int main(int argc, char *argv[])
445
{
446
  int res;
447
  int i;
448
 
449
  if (argc!=3) {
450
    fprintf(stderr,"missing filenames\n");
451
    fprintf(stderr,"usage: jdump SHARKtracefilename JTRACERtracefilename\n");
452
    return -1;
453
  }
454
 
455
  for (i=0;i<MAX_PROC;i++) {
456
    names[i]=0;
457
    //activated[i]=0;
458
  }
459
 
460
  outfile=open(argv[2],O_WRONLY|O_CREAT|O_TRUNC|O_BINARY,0777);
461
  if (outfile==-1) {
462
    perror("can't open outfile");
463
    return -1;
464
  }  
465
  res=read_trace(argv[1],dumpfunc);
466
  close(outfile);
467
 
468
  //fprintf(stderr,"result=%i",res);
469
  return 0;
470
}