Subversion Repositories shark

Rev

Blame | Last modification | View Log | RSS feed


#include <netinet/in.h>

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

/* distribuzione del delta schedule_time - arrival_time */

#define MAXX 50
#define PREC 100
#define DELTA ((double)MAXX/(double)PREC)

#include "distr.c"

int task;
long a=-1;
long s;

int safunc(trc_event_t *ev)
{
  if (event_class(ev->event)!=TRC_CLASS_SYSTEM) return 0;
 
  if (ev->x.sys.task!=task) return 0;

  if (a==-1) {
    if (ev->event==TRC_ACTIVATE||ev->event==TRC_INTACTIVATION)
      a=ev->time;
  } else {
    if (ev->event==TRC_SCHEDULE) {
      s=ev->time;
      d_insert(s-a);
      a=-1;
    }    
  }
  return 0;
}

/* -- */

int main(int argc, char *argv[])
{
  int res;
 
  if (argc!=4) {
    fprintf(stderr,"usage: sa [tracefile] [pid] [outputfile]\n");
    return -1;
  }

  d_init();

  task=atoi(argv[2]);
  res=read_trace(argv[1],safunc);

  if (res==0) {
    FILE *fout;
    fout=fopen(argv[3],"wt");
    if (fout==NULL) {
      fprintf(stderr,"error writing output file!\n");
      return 0;
    }
    d_dump(fout);
    fclose(fout);
  }

  if (res!=0) {
    fprintf(stderr,"error=%i\n",res);
    perror("ERROR");
  }

  return 0;
}