Exemple #1
0
int main(int argc, char **argv)
{
	FILE *swp;
	struct cache *c;
	struct matrix *m;	
	FILE *matrix_shared;

	readargs(argc, argv);

	if ((swp = fopen(swapfile, "w+")) == NULL)
		error("cannot open swap file");

	c = cache_create(&access_info, swp, CACHE_SIZE);

	/* Read traces. */
	for (int i = 0; i < ntraces; i++)
	{
		FILE *trace;
		
		if ((trace = fopen(tracefiles[i], "r")) == NULL)
			error("cannot open trace file");
		
		trace_read(c, trace, i);
		fclose(trace);
		
		fprintf(stderr, "\nFechado arquivo de trace da thread %d\n\n", i);
		
	}
	
	/* Flushe traces on swap file. */
	cache_flush(c);
	
	/* Create communication matrix. */
	fseek(swp, 0, SEEK_SET); 
	m  = matrix_create(QTD_THREADS, QTD_THREADS);
	
	fprintf(stderr, "\nMatriz criada\n");
	
	matrix_generate(swp, m);
	
	
	if ((matrix_shared = fopen(outfile, "w")) == NULL)
		error("cannot open output file");
	
	fprintf(stderr, "\nGravar matriz no arquivo\n");
	
	for (int i = 0; i < ntraces; i++)
	{
		for(int j = 0; j < ntraces; j++)
			fprintf(matrix_shared, "%d;%d;%d\n", i, j, (int) matrix_get(m, i, j));	
	}

	/* House keeping. */
	fclose(matrix_shared);
	fclose(swp);
	
	fprintf(stderr, "\n\n FIM!\n");
		
	return (EXIT_SUCCESS);
}
Exemple #2
0
Fichier : main.c Projet : 4n3w/dump
int main(int argc, char **argv) {
	if (argc < 2) {
		fprintf(stderr, "Usage: %s command [arguments ...]\n", argv[0]);
		exit(EXIT_FAILURE);
	}

	struct trace *trace = trace_new(process_new, NULL);

	int pid = trace_execvp(trace, &argv[1]);
	char buf[1024];
	argv_join(buf, sizeof(buf), &argv[1], " ");
	fprintf(stderr, "[+] pid=%i, running: %s\n", pid, buf);

	while (trace_process_count(trace) > 0) {
		trace_read(trace);
	}

	trace_free(trace);

	return 0;
}
Exemple #3
0
void
do_try (trace_t * trace, const int hop,
	const int max_hops, const int max_tries)
{
  fd_set readset;
  int ret, tries, readonly = 0;
  struct timeval now, time;
  double triptime = 0.0;
  uint32_t prev_addr = 0;

  printf (" %d  ", hop);

  for (tries = 0; tries < max_tries; tries++)
    {
      FD_ZERO (&readset);
      FD_SET (trace_icmp_sock (trace), &readset);

      time.tv_sec = TIME_INTERVAL;
      time.tv_usec = 0;

      if (!readonly)
	trace_write (trace);

      ret = select (FD_SETSIZE, &readset, NULL, NULL, &time);

      gettimeofday (&now, NULL);

      now.tv_usec -= trace->tsent.tv_usec;
      now.tv_sec -= trace->tsent.tv_sec;

      if (ret < 0)
	{
	  switch (errno)
	    {
	    case EINTR:
	      /* was interrupted */
	      break;
	    default:
              error (EXIT_FAILURE, EPERM, "select failed");
	      break;
	    }
	}
      else if (ret == 0)
	{
	  /* time expired */
	  printf (" * ");
	  fflush (stdout);
	}
      else
	{
	  if (FD_ISSET (trace_icmp_sock (trace), &readset))
	    {
	      triptime = ((double) now.tv_sec) * 1000.0 +
		((double) now.tv_usec) / 1000.0;

	      if (trace_read (trace))
		{
		  /* FIXME: printf ("Some error ocurred\n"); */
		  tries--;
		  readonly = 1;
		  continue;
		}
	      else
		{
		  if (tries == 0 || prev_addr != trace->from.sin_addr.s_addr)
		    printf (" %s (%s) ",
			    inet_ntoa (trace->from.sin_addr),
			    get_hostname (&trace->from.sin_addr));
		  printf ("%.3fms ", triptime);

		}
	      prev_addr = trace->from.sin_addr.s_addr;
	    }
	}
      readonly = 0;
      fflush (stdout);
    }
  printf ("\n");
}
Exemple #4
0
int
do_try (trace_t * trace, const int hop,
        const int max_hops, const int max_tries, const int wait_time, tracert_cfg_item_t *item)
{
    fd_set readset;
    int ret=0, tries, readonly = 0;
    struct timeval now, time;
    double triptime = 0.0;
    uint32_t prev_addr = 0;

    item->num = max_tries;
    if(NULL == (item->time = malloc(sizeof(double)*max_tries)))
    {
        return -1;
    }
    for (tries = 0; tries < max_tries; tries++)
    {
        FD_ZERO (&readset);
        FD_SET (trace_icmp_sock (trace), &readset);

        time.tv_sec = wait_time;
        time.tv_usec = 0;


        if (!readonly)
            ret = trace_write (trace);

        if (ret == 2)
            return 1;

        if (ret < 0)
            return -1;

        ret = select (FD_SETSIZE, &readset, NULL, NULL, &time);

        gettimeofday (&now, NULL);

        now.tv_usec -= trace->tsent.tv_usec;
        now.tv_sec -= trace->tsent.tv_sec;

        if (ret < 0)
        {
            return -1;
        }
        else if (ret == 0)
        {
            /* time expired */
            strcpy(item->dstIp,"*");
            strcpy(item->Ip,"*");
            item->time[tries] = 0.000;
            //fflush (stdout);
        }
        else
        {
            if (FD_ISSET (trace_icmp_sock (trace), &readset))
            {
                triptime = ((double) now.tv_sec) * 1000.0 +
                           ((double) now.tv_usec) / 1000.0;

                if (trace_read (trace))
                {
                    /* FIXME: printf ("Some error ocurred\n"); */
                    tries--;
                    readonly = 1;
                    continue;
                }
                else
                {
                    if (tries == 0 || prev_addr != trace->from.sin_addr.s_addr)
                    {
                        strcpy(item->dstIp,inet_ntoa (trace->from.sin_addr));
                        strcpy(item->Ip,get_hostname (&trace->from.sin_addr));
                    }
                    item->time[tries] = triptime;
                }
                prev_addr = trace->from.sin_addr.s_addr;
            }
        }
        readonly = 0;
        //fflush (stdout);
    }
    return 0;
}
Exemple #5
0
/* Receive (the next part of) a msg (fragment).
   A message is complete when msg->read == msg->size; the data is then available in msg->buffer.
   It is assumed that fd is set to nonblocking beforehand.
   Returns:
     0: success (the read(s) went well, msg not necessarilly complete).
    -1: Some problem with read (see ERRNO for details). Connection should most
        probably be closed. */
static int tcp_receive_message_fragment (int fd, TCP_MSG *msg)
{
	unsigned char	*dp;
	size_t		max;
	ssize_t		n;
	uint32_t	l;

	if (!msg->size) {
		/* Start of a new message. Expect at least a message header */
		msg->used = 0;
		msg->size = sizeof (CtrlHeader);
	}
	ctrc_begind (TCPS_ID, TCPS_RX_FRAG, &fd, sizeof (fd));
	ctrc_contd (&msg->used, sizeof (msg->used));
	ctrc_contd (&msg->size, sizeof (msg->size));
	ctrc_endd ();

	if (msg->used < sizeof (CtrlHeader))
		/* (Still) reading the msg header */
		dp = (unsigned char*) &msg->header + msg->used;
	else
		/* Continue reading 'til the end of the message */
		dp = msg->buffer + msg->used;
	
    continue_reading:

	while (msg->used < msg->size) {
		max = msg->size - msg->used;
		n = read (fd, dp, max);

		ctrc_begind (TCPS_ID, TCPS_RX_CHUNK, &fd, sizeof (fd));
		ctrc_contd (&max, sizeof (max));
		ctrc_contd (&n, sizeof (n));
		ctrc_endd ();

		trace_read (n, fd, max);
		if (n < 0) {
			if (ERRNO == EINTR)
				goto continue_reading;

			if ((ERRNO == EAGAIN) || (ERRNO == EWOULDBLOCK))
				return (0); /* try again later */
			/*perror ("tcp_receive_message_fragment()");*/
			log_printf (RTPS_ID, 0, "TCP: error reading from connection [%d] (%s)!\r\n", fd, strerror (ERRNO));
			return (-1);
		}
		else if (n == 0)
			return (-1); /* end-of-stream encountered */

		msg->used += n;
		dp += n;
	}
	if (!msg->buffer) {
		/* Just received a CtrlHeader - see what else is needed? */
		if (ctrl_protocol_valid (&msg->header)
#ifdef TCP_SUSPEND
		 || bgcp_protocol_valid (&msg->header)
#endif
		 				      )
			msg->size += TTOHS (msg->header.length);
		else if (protocol_valid (&msg->header)) {
			memcpy (&l, &msg->header.msg_kind, sizeof (l));
			l = TTOHL (l);
			msg->size += l;
		}
		else {
			/* Data not recognized as either a RTPS nor a RPSC message */
			ctrc_printd (TCPS_ID, TCPS_RX_BADMSG, &fd, sizeof (fd));
			msg->size = msg->used = 0;
			return (-1);
		}
		msg->buffer = xmalloc (msg->size);
		if (!msg->buffer) {
			msg->size = msg->used = 0;
			ctrc_printd (TCPS_ID, TCPS_RX_NOMEM, &fd, sizeof (fd));
			return (-1);
		}
		memcpy (msg->buffer, &msg->header, sizeof (CtrlHeader));
		dp = msg->buffer + msg->used;
		goto continue_reading;
	}
	ctrc_printd (TCPS_ID, TCPS_RX_COMPL, &fd, sizeof (fd));
	return (0);
}
Exemple #6
0
int main(int argc, char *argv[])
{
  FILE *f;
  //int start = 0, fc = 0, fo = 0, opt, i;
  long long int res = 0, done = 0;
  int first_param;

  first_param = param(argc, argv);
  if (argc - first_param < 1) {
    help(argv[0]);
  }

  createPidsFilter(relevant_pids);

  if (strcmp(argv[first_param], "-")) {
    f = fopen(argv[first_param], "r");
  } else {
    f = stdin;
  }
  if (f == NULL) {
    perror("Cannot open input file");

    return -1;
  }

  while (!done) {
    struct event *e;

    switch (trace_type) {
      case FTRACE:
	res = ftrace_parse(f);
	break;
      case OFTRACE:
	res = oftrace_parse(f);
	break;
      case JTRACE:
	res = jtrace_read(f);
	break;
      case L4TRACE:
        res = l4trace_parse(f);
	break;
      case TRCUTILS:
	res = trace_read(f, 0);
	break;
      case XTRACE:
	res = trace_read(f, 1);
	break;
      default:
	fprintf(stderr,
		"Unknown trace type: this shouldn't have happened...\n");
	exit(-1);
    }
    while (e = evt_get()) {
      filterEvent(e);
      trc_write(e);
      free(e);
    }
    done = feof(f) || (res < 0);
  }

//    endAllTask(time);

  destroyPidsFilter();

  return 0;
}