Subversion Repositories shark

Rev

Blame | Last modification | View Log | RSS feed

/*
 * Project: HARTIK (HA-rd R-eal TI-me K-ernel)
 *
 * Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
 *               Gerardo Lamastra <gerardo@sssup.it>
 *
 * Authors     : Massimiliano Giorgi <massy@hartik.sssup.it>
 * (see authors.txt for full list of hartik's authors)
 *
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
 *
 * http://www.sssup.it
 * http://retis.sssup.it
 * http://hartik.sssup.it
 */


/*
 * Copyright (C) 1999 Massimiliano Giorgi
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */


/*
 * CVS :        $Id: jdump.c,v 1.1.1.1 2004-05-24 18:03:44 giacomo Exp $
 *
 * File:        $File$
 * Revision:    $Revision: 1.1.1.1 $
 * Last update: $Date: 2004-05-24 18:03:44 $
 */


#include <netinet/in.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>

#include "types.h"
#include <trace.h>
#include "util.h"

/*
 *
 * This filter converts trace file formats from SHARK to JTRACER
 *
 */


/* All times are dived by this costant. */
#define TIMESCALE 1

/* If defined dump on stdout the packets (in ascii) that will be written
 * on the output file (the file of the tracer).
 */


#define DUMPOUT

/*
 *
 *
 *
 */


int pippo=0;

int writeInt(int h, int x)
{
  int y,res;
  y=htonl(x);
  res=write(h,&y,sizeof(int));
  return res!=sizeof(int);
}


int writeStr(int h, char *s)
{
  int res,size;
  size=strlen(s);
  writeInt(h,size);
  res=write(h,s,size);
  return res!=size;
}

/*
 *
 */


#define TASK_ARRIVAL      0
#define TASK_SCHEDULE     1
#define TASK_DESCHEDULE   2
#define TASK_END          3
#define TASK_DLINEPOST    4
#define TASK_DLINESET     5
#define TASK_WAIT         6
#define TASK_SIGNAL       7
#define TASK_IDLE         8
#define TASK_NAME         9

#define EVT_NUMBER       10

char *eventsname[]={
  "task_arrival",
  "task_schedule",
  "task_deschedule",
  "task_end",
  "task_dlinepost",
  "task_dlineset",
  "task_wait",
  "task_signal",
  "task_idle",
  "task_name"
};

struct j_evt_prolog {
  int                 type;
  int                 time;
};

struct j_evt_task {
  struct j_evt_prolog p;
  int                 task;
};

struct j_evt_dlinepost {
  struct j_evt_task   t;
  int                 taskD;
  int                 taskD2;
};

struct j_evt_dlineset {
  struct j_evt_task   t;
  int                 taskD;
};

struct j_evt_semaph {
  struct j_evt_task   t;
  int                 res;
  char                *name;
};

struct j_evt_name {
  struct j_evt_task   t;
  char                *name;
};

/*
 *
 */


int j_write_prolog(int h, void *ptr)
{
#ifdef DUMPOUT
  printf("%10i ",((struct j_evt_prolog *)ptr)->time);
  printf("%-18s ",eventsname[((struct j_evt_prolog *)ptr)->type]);
#endif
  if (writeInt(h,((struct j_evt_prolog *)ptr)->type)) return -2;
  if (writeInt(h,((struct j_evt_prolog *)ptr)->time)) return -3;
  return 0;
}

int j_write_task(int h, void *ptr)
{
  int res;
  res=j_write_prolog(h,ptr);
#ifdef DUMPOUT
  printf("tsk=%i ",((struct j_evt_task *)ptr)->task);
#endif
  if (res) return res;
  if (writeInt(h,((struct j_evt_task *)ptr)->task)) return -4;
  return 0;
}

int j_write_dlinepost(int h, void *ptr)
{
  int res;
  res=j_write_task(h,ptr);
  if (res) return res;
  if (writeInt(h,((struct j_evt_dlinepost *)ptr)->taskD)) return -5;
  if (writeInt(h,((struct j_evt_dlinepost *)ptr)->taskD2)) return -6;
  return 0;
}

int j_write_dlineset(int h, void *ptr)
{
  int res;
  res=j_write_task(h,ptr);
  if (res) return res;
  if (writeInt(h,((struct j_evt_dlineset *)ptr)->taskD)) return -7;
  return 0;
}

int j_write_semaph(int h, void *ptr)
{
  int res;
  res=j_write_task(h,ptr);
  if (res) return res;
  if (writeInt(h,((struct j_evt_semaph *)ptr)->res)) return -8;
  if (writeStr(h,((struct j_evt_semaph *)ptr)->name)) return -9;
  return 0;
}

int j_write_name(int h, void *ptr)
{
  int res;
  res=j_write_task(h,ptr);
#ifdef DUMPOUT
  printf("name='%s' ",((struct j_evt_name *)ptr)->name);
#endif
  if (res) return res;
  if (writeStr(h,((struct j_evt_name *)ptr)->name)) return -10;
  return 0;
}
 
int writeEvent(int h, void *ptr)
{
  int res;
   
  //printf("<%i>",((struct j_evt_prolog*)ptr)->type);
   
  ((struct j_evt_prolog*)ptr)->time/=TIMESCALE;

  switch(((struct j_evt_prolog*)ptr)->type) {
  case TASK_ARRIVAL:
  case TASK_SCHEDULE:
  case TASK_DESCHEDULE:
  case TASK_END:
  case TASK_IDLE:
    res=j_write_task(h,ptr);
    break;
  case TASK_DLINEPOST:
    res=j_write_dlinepost(h,ptr);
    break;
  case TASK_DLINESET:
    res=j_write_dlineset(h,ptr);
    break;
  case TASK_WAIT:
  case TASK_SIGNAL:
    res=j_write_semaph(h,ptr);
    break;
  case TASK_NAME:
    res=j_write_name(h,ptr);
    break;
  default:
    return -1;
   
  }

#ifdef DUMPOUT
  printf(" \n");
#endif

  return res;
}

/*
 *
 *
 *
 */


#define MAX_PROC 150

//int activated[MAX_PROC];

int cxx=0;
/* write MAXC-1 events */
#define MAXC 10000

long lasttime;

int sys_event(int h, void *param)
{
  static int prevtask=-1;
  trc_event_t *ptr=(trc_event_t *)param;
  struct j_evt_task evt;

  evt.p.time=ptr->time;
  evt.task=ptr->x.sys.task;

  lasttime=ptr->time;
  switch(ptr->event) {
     
  case TRC_CREATE:
    return 0;

  case TRC_ACTIVATE:
  case TRC_INTACTIVATION:


    //activated[ptr->x.sys.task]=1;


    evt.p.type=TASK_ARRIVAL;
    break;
     
  case TRC_DESTROY:


    //activated[ptr->x.sys.task]=0;



    return 0;

  case TRC_DISABLE:

    return 0;    
     
  case TRC_DELAY:
    prevtask=-1;
    evt.p.type=TASK_DESCHEDULE;
    break;
     
  case TRC_SLEEP:
    prevtask=-1;
    evt.p.type=TASK_DESCHEDULE;
    break;
     
  case TRC_ENDCYCLE:
    prevtask=-1;
    evt.p.type=TASK_END;
    break;

  case TRC_SCHEDULE:
    if (prevtask!=-1) {
      struct j_evt_task evt2;
      int res;
      evt2.p.time=ptr->time;
      evt2.p.type=TASK_DESCHEDULE;
      evt2.task=prevtask;
      res=writeEvent(h,&evt2);  
      if (res!=0) return -1;
    }

    /*
      if (!activated[ptr->x.sys.task]) {
      struct j_evt_task evt2;

      evt2.p.time=ptr->time-1;
      evt2.task=ptr->x.sys.task;
      evt2.p.type=TASK_ARRIVAL;

      writeEvent(h,&evt2);  
       
      activated[ptr->x.sys.task]=1;
      }
    */


    evt.p.type=TASK_SCHEDULE;
    prevtask=ptr->x.sys.task;
    break;

  default:
    return 0;
  }

  cxx++;
  if (cxx==MAXC) return -1;

  return writeEvent(h,&evt);  
}


int sem_event(int h,void *param)
{
  //trc_event_t *ptr=(trc_event_t *)param;
  //struct j_evt_semaph evt;

  return 0;
  /*  
  evt.t.p.time=ptr->x.norm.when;
  evt.t.task=ptr->x.norm.who;
  switch(ptr->what) {
    case TRC_SEM_WAIT:   evt.t.p.type=TASK_WAIT; break;
    case TRC_SEM_SIGNAL: evt.t.p.type=TASK_SIGNAL; break;
    case TRC_SEM_WAITNB: return 0;
    default:             return 0;
  }
  evt.res=1;
  evt.name="NoName";
  return j_write_semaph(h,&evt);
  */

}

/* -- */

#define MAX_PROC 150
int names[MAX_PROC];

int outfile;

int dumpfunc(trc_event_t *ptr)
{
  //printf("{%i}",ptr->event);

  if (!names[ptr->x.sys.task]) {
    struct j_evt_name evtname;
    static char name[24];

    cxx++;
    if (cxx==MAXC) return -1;
 
    evtname.t.p.time=lasttime;
    evtname.t.task=ptr->x.sys.task;
    evtname.t.p.type=TASK_NAME;
    sprintf(name,"task%03i",ptr->x.sys.task);
    evtname.name=name;
    writeEvent(outfile,&evtname);
    names[ptr->x.sys.task]=1;

  }

  switch(event_class(ptr->event)) {
    case TRC_CLASS_SYSTEM:
      return sys_event(outfile,ptr);
    case TRC_CLASS_SEM:
      return 0;
      return sem_event(outfile,ptr);
    case TRC_CLASS_USER:
      return 0;
  }
  return 0;
}

/*
 *
 */


#ifndef O_BINARY
#define O_BINARY 0
#endif

int main(int argc, char *argv[])
{
  int res;
  int i;

  if (argc!=3) {
    fprintf(stderr,"missing filenames\n");
    fprintf(stderr,"usage: jdump SHARKtracefilename JTRACERtracefilename\n");
    return -1;
  }

  for (i=0;i<MAX_PROC;i++) {
    names[i]=0;
    //activated[i]=0;
  }

  outfile=open(argv[2],O_WRONLY|O_CREAT|O_TRUNC|O_BINARY,0777);
  if (outfile==-1) {
    perror("can't open outfile");
    return -1;
  }  
  res=read_trace(argv[1],dumpfunc);
  close(outfile);
 
  //fprintf(stderr,"result=%i",res);
  return 0;
}