Exemple #1
0
void
ruadd(struct rusage *ru, struct rusage *ru2)
{
	long *lp, *lp2;
	int cnt;
	/*
	 * The SunOS 4.x <sys/rusage.h> has ru_first and ru_last #defines
	 * as below.
	 * The SVR4/POSIX <sys/resource.h> does not have these defined for
	 * struct rusage
	 * The #defines below are here so that the original csh logic
	 * for ruadd remains clear now that there is no longer a private copy
	 * of the old <sys/resource.h>
	 */
#define	ru_first ru_ixrss
#define	ru_last ru_nivcsw

#ifdef TRACE
	tprintf("TRACE- ruadd()\n");
#endif
	tvadd(&ru->ru_utime, &ru2->ru_utime);
	tvadd(&ru->ru_stime, &ru2->ru_stime);
	if (ru2->ru_maxrss > ru->ru_maxrss) {
		ru->ru_maxrss = ru2->ru_maxrss;
	}
	cnt = &ru->ru_last - &ru->ru_first + 1;
	lp = &ru->ru_first;
	lp2 = &ru2->ru_first;
	do {
		*lp++ += *lp2++;
	} while (--cnt > 0);
}
Exemple #2
0
/*
 *			R E A D _ T I M E R
 * 
 */
double
read_timer(char *str, int len)
{
	struct timeval timedol;
	struct rusage ru1;
	struct timeval td;
	struct timeval tend, tstart;
	char line[132];

	getrusage(RUSAGE_SELF, &ru1);
	gettimeofday(&timedol, (struct timezone *)0);
	prusage(&ru0, &ru1, &timedol, &time0, line);
	/* XXX: buffer overflow if len > sizeof(line) */
	(void)strncpy(str, line, len);

	/* Get real time */
	tvsub(&td, &timedol, &time0);
	realt = td.tv_sec + ((double)td.tv_usec) / 1000000;

	/* Get CPU time (user+sys) */
	tvadd(&tend, &ru1.ru_utime, &ru1.ru_stime);
	tvadd(&tstart, &ru0.ru_utime, &ru0.ru_stime);
	tvsub(&td, &tend, &tstart);
	cput = td.tv_sec + ((double)td.tv_usec) / 1000000;
	if (cput < 0.00001)
		cput = 0.00001;
	return(cput);
}
/*
 *                    R E A D _ T I M E R
 */
double
read_timer (char *str, int len)
{
  struct itimerval itimedol;
  struct rusage ru1;
  struct timeval td;
  struct timeval tend, tstart;
  char line[132];

  getrusage (RUSAGE_SELF, &ru1);
  fprintf(stdout, "final user time = %d sec and %d usec\n", ru1.ru_utime.tv_sec, ru1.ru_utime.tv_usec);
  fprintf(stdout, "final sys time = %d sec and %d usec\n", ru1.ru_stime.tv_sec, ru1.ru_stime.tv_usec);

  if (getitimer (ITIMER_REAL, &itimedol))
    {
      perror ("Getting 'itimer' REAL failed");
      return (0.0);

    }
  fprintf(stdout, "End transaction time = %d sec and %d usec\n", itimedol.it_value.tv_sec, itimedol.it_value.tv_usec);
  prusage (&ru0, &ru1, &itime0.it_value, &itimedol.it_value, line);
  (void) strncpy (str, line, len);

  /* Get real time */
  tvsub (&td, &itime0.it_value, &itimedol.it_value);
  realt = td.tv_sec + ((double) td.tv_usec) / 1000000;

  /* Get CPU time (user+sys) */
  tvadd (&tend, &ru1.ru_utime, &ru1.ru_stime);
  tvadd (&tstart, &ru0.ru_utime, &ru0.ru_stime);
  tvsub (&td, &tend, &tstart);
  cput = td.tv_sec + ((double) td.tv_usec) / 1000000;
  if (cput < 0.00001)
    cput = 0.00001;
  return (cput);
}
void print_statistics(int socktype, struct timeval start, struct timeval end, int total_bytes, int io) {
	int i;
	struct s_time_record *record;
	struct timeval tdiff, total_delay, avg_delay, sqrsum;// sdiv, tmp;
	int npackets = 0;
	double t_delay, t_avg, t_total;

	record = time_record_head.next;

	int last_seq = 1;
	struct s_seqlist *seqlist;

	total_delay.tv_sec = 0;
	total_delay.tv_usec = 0;
	sqrsum.tv_sec = 0;
	sqrsum.tv_usec = 0;

	while(record != NULL) {

		/*
		printf("%i ", record->seq);
		if(seqformat++ == 10) {
			printf("\n");
			seqformat = 0;
		}*/

		if(socktype == SOCK_DGRAM) {

			/* save potentially lost sequence numbers */
			for(i = last_seq + 1; i < record->seq; i++)
				insert_seq(i);

			/* saved sequence number found. Delete it from lost-seq-number list */
			if(last_seq > record->seq)
				delete_seq(record->seq);

			last_seq = record->seq;
		}



		tvsub(&tdiff, &(record->my_time), &(record->his_time)); /* delay */
		tvadd(&total_delay, &total_delay, &tdiff);	/* sum delay */


		npackets++;
		record = record->next;
	}

	avg_delay.tv_sec = total_delay.tv_sec / npackets;
	avg_delay.tv_usec = total_delay.tv_usec / npackets;

	/*
	//standard diviation:
	record = time_record_head.next;
	while(record != NULL) {
		tvsub(&tdiff, &(record->my_time), &(record->his_time)); //delay
		tvsub(&tmp, &tdiff, &avg_delay); // x1 - mü
		tvsqr(&tmp); // (x - mü)^2

		tvadd(&sdiv, &tmp);


		record = record->next;
	}*/

	tvsub(&tdiff, &end, &start);
	t_avg = tvtosec(&avg_delay);
	t_total = tvtosec(&tdiff);
	t_delay = tvtosec(&total_delay);

	printf("\n\nprinting statistics:\n" \
	       "--------------------------\n");
	printf("%i bytes received in %.2f seconds\n", total_bytes, t_total);
	printf("I/O calls: %i\n", io);
	printf("packets received: %i\n", npackets);
	printf("total delay: %.2f seconds\n", t_delay);
	printf("average delay: %f seconds\n", t_avg);

	/* printf("standard diviation: %ld seconds, %ld microseconds\n", sdiv.tv_sec / npackets,
							     sdiv.tv_usec / npackets); */



	/* print lost packets (only UDP) */
	if(socktype == SOCK_DGRAM) {

		seqlist = seqlist_head.next;
		if(seqlist == NULL)
			printf("No packet loss\n");
		else {
			int format = 0;
			int packetloss = 0;
			printf("\nPackets with the following sequence numbers are lost:\n\n");
			while(seqlist != NULL) {
				packetloss++;
				printf("%i ", seqlist->val);
				seqlist = seqlist->next;
				if(format++ == 10) {
					printf("\n");
					format = 0;
				}
			}
			printf("\n\nNumber of packets lost: %i\n", packetloss);

		}
	}
	printf("\n\n");

}
Exemple #5
0
/* called on every vsync */
void pl_frame_limit(void)
{
	static struct timeval tv_old, tv_expect;
	static int vsync_cnt_prev;
	struct timeval now;
	int diff, usadj;

	vsync_cnt++;

	/* doing input here because the pad is polled
	 * thousands of times per frame for some reason */
	update_input();

	pcnt_end(PCNT_ALL);
	gettimeofday(&now, 0);

	if (now.tv_sec != tv_old.tv_sec) {
		diff = tvdiff(now, tv_old);
		vsps_cur = 0.0f;
		if (0 < diff && diff < 2000000)
			vsps_cur = 1000000.0f * (vsync_cnt - vsync_cnt_prev) / diff;
		vsync_cnt_prev = vsync_cnt;
		flips_per_sec = flip_cnt;
		flip_cnt = 0;
		tv_old = now;
		if (g_opts & OPT_SHOWCPU)
			tick_per_sec = get_cpu_ticks();

		if (hud_new_msg > 0) {
			hud_new_msg--;
			if (hud_new_msg == 0)
				hud_msg[0] = 0;
		}
	}
#ifdef PCNT
	static int ya_vsync_count;
	if (++ya_vsync_count == PCNT_FRAMES) {
		pcnt_print(vsps_cur);
		ya_vsync_count = 0;
	}
#endif

	tvadd(tv_expect, pl_frame_interval);
	diff = tvdiff(tv_expect, now);
	if (diff > MAX_LAG_FRAMES * pl_frame_interval || diff < -MAX_LAG_FRAMES * pl_frame_interval) {
		//printf("pl_frame_limit reset, diff=%d, iv %d\n", diff, pl_frame_interval);
		tv_expect = now;
		diff = 0;
		// try to align with vsync
		usadj = vsync_usec_time;
		while (usadj < tv_expect.tv_usec - pl_frame_interval)
			usadj += pl_frame_interval;
		tv_expect.tv_usec = usadj;
	}

	if (!(g_opts & OPT_NO_FRAMELIM) && diff > pl_frame_interval) {
		// yay for working usleep on pandora!
		//printf("usleep %d\n", diff - pl_frame_interval / 2);
		usleep(diff - pl_frame_interval / 2);
	}

	if (UseFrameSkip) {
		if (diff < -pl_frame_interval) {
			// P.E.Op.S. makes skip decision based on this
			fps_skip = 1.0f;
			plugin_skip_advice = 1;
		}
		else if (diff >= 0) {
			fps_skip = 100.0f;
			plugin_skip_advice = 0;
		}
	}

	pcnt_start(PCNT_ALL);
}