Subversion Repositories shark

Rev

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

/*
 * Project: S.Ha.R.K.
 *
 * Coordinators:
 *   Giorgio Buttazzo    <giorgio@sssup.it>
 *   Paolo Gai           <pj@gandalf.sssup.it>
 *
 * Authors     :
 *   Paolo Gai           <pj@gandalf.sssup.it>
 *   Massimiliano Giorgi <massy@gandalf.sssup.it>
 *   Luca Abeni          <luca@gandalf.sssup.it>
 *   (see the web pages for full authors list)
 *
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
 *
 * http://www.sssup.it
 * http://retis.sssup.it
 * http://shark.sssup.it
 */


/*
 * Copyright (C) 2000 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: sa.c,v 1.1.1.1 2004-05-24 18:03:44 giacomo Exp $
 */


#include <netinet/in.h>

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

/* this file prints the distribution of (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;
}