Example #1
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);
}
Example #2
0
static void
ptransfer(const char *direction, long bytes, 
	  const struct timeval *t0, 
	  const struct timeval *t1)
{
	struct timeval td;
#ifdef EMBED
	/* Use all ints for embedded targets */
	unsigned long s, bs;

	if (ftpverbose) {
		tvsub(&td, t1, t0);
		s = (td.tv_sec * 1000) + (td.tv_usec / 1000);
#define	nz(x)	((x) == 0 ? 1 : (x))
		bs = bytes / nz(s);
		printf("%ld bytes %s in %d secs (%d Kbytes/sec)\n",
		    bytes, direction, (s/1000), bs);
	}
#else
	float s, bs;

	if (ftpverbose) {
		tvsub(&td, t1, t0);
		s = td.tv_sec + (td.tv_usec / 1000000.);
#define	nz(x)	((x) == 0 ? 1 : (x))
		bs = bytes / nz(s);
		printf("%ld bytes %s in %.3g secs (%.2g Kbytes/sec)\n",
		    bytes, direction, s, bs / 1024.0);
	}
#endif
}
Example #3
0
void
latency(uint64 xfers, uint64 size)
{
	struct timeval td;
	double  s;

	if (!ftiming) ftiming = stderr;
	tvsub(&td, &stop_tv, &start_tv);
	s = td.tv_sec + td.tv_usec / 1000000.0;
	if (s == 0.0) return;
	if (xfers > 1) {
		fprintf(ftiming, "%d %dKB xfers in %.2f secs, ",
		    (int) xfers, (int) (size / KB), s);
	} else {
		fprintf(ftiming, "%.1fKB in ", size / KB);
	}
	if ((s * 1000 / xfers) > 100) {
		fprintf(ftiming, "%.0f millisec%s, ",
		    s * 1000 / xfers, xfers > 1 ? "/xfer" : "s");
	} else {
		fprintf(ftiming, "%.4f millisec%s, ",
		    s * 1000 / xfers, xfers > 1 ? "/xfer" : "s");
	}
	if (((xfers * size) / (MB * s)) > 1) {
		fprintf(ftiming, "%.2f MB/sec\n", (xfers * size) / (MB * s));
	} else {
		fprintf(ftiming, "%.2f KB/sec\n", (xfers * size) / (KB * s));
	}
}
Example #4
0
//detect and save detected boxes
static FLOAT *detect(IplImage *IM,GPUModel *MO,FLOAT thresh,int *D_NUMS,FLOAT *A_SCORE)
{
	/* for measurement */
	struct timeval tv, tv_calc_f_pyramid_start, tv_calc_f_pyramid_end;
	float time_calc_f_pyramid = 0;

	//initialize scale information for hierachical detection
	FLOAT *scales = gpu_init_scales(MO->MI,IM,IM->width,IM->height);

	//initialize feature-size matrix
	int *featsize = gpu_init_featsize(MO->MI);

	//calculate feature pyramid
	gettimeofday(&tv_calc_f_pyramid_start, NULL);
	FLOAT **feature = gpu_calc_f_pyramid(IM,MO->MI,featsize,scales);
	gettimeofday(&tv_calc_f_pyramid_end, NULL);
	tvsub(&tv_calc_f_pyramid_end, &tv_calc_f_pyramid_start, &tv);

	time_kernel += tv.tv_sec * 1000.0 + (float)tv.tv_usec / 1000.0;
	time_calc_f_pyramid += tv.tv_sec * 1000.0 + (float)tv.tv_usec / 1000.0;
#ifdef PRINT_INFO
	printf("\n");
	printf("calc_f_pyramid %f[ms]\n", time_calc_f_pyramid);
#endif

	//detect boundary boxes
	FLOAT *boxes = dpm_ttic_gpu_get_boxes(feature,scales,featsize,MO,D_NUMS,A_SCORE,thresh);

	free(scales);
	free(featsize);
	gpu_free_features(feature,MO->MI);

	return boxes;
}
Example #5
0
void
bandwidth(uint64 bytes, uint64 times, int verbose)
{
	struct timeval tdiff;
	double  mb, secs;

	tvsub(&tdiff, &stop_tv, &start_tv);
	secs = tdiff.tv_sec;
	secs *= 1000000;
	secs += tdiff.tv_usec;
	secs /= 1000000;
	secs /= times;
	mb = bytes / MB;
	if (!ftiming) ftiming = stderr;
	if (verbose) {
		(void) fprintf(ftiming,
		    "%.4f MB in %.4f secs, %.4f MB/sec\n",
		    mb, secs, mb/secs);
	} else {
		if (mb < 1) {
			(void) fprintf(ftiming, "%.6f ", mb);
		} else {
			(void) fprintf(ftiming, "%.2f ", mb);
		}
		if (mb / secs < 1) {
			(void) fprintf(ftiming, "%.6f\n", mb/secs);
		} else {
			(void) fprintf(ftiming, "%.2f\n", mb/secs);
		}
	}
}
Example #6
0
double
timespent(void)
{
	struct timeval td;

	tvsub(&td, &stop_tv, &start_tv);
	return (td.tv_sec + td.tv_usec / 1000000.0);
}
Example #7
0
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//detect car-boundary-boxes
RESULT *car_detection(IplImage *IM,MODEL *MO,FLOAT thresh,int *D_NUMS,FLOAT *A_SCORE,FLOAT overlap)
{
  /* for measurement */
  struct timeval tv;
  struct timeval tv_detect_start, tv_detect_end;
  float time_detect;
  struct timeval tv_nms_start, tv_nms_end;
  float time_nms;
  struct timeval tv_get_new_rects_start, tv_get_new_rects_end;
  float time_get_new_rects;
  
  gettimeofday(&tv_detect_start, NULL);
  FLOAT *boxes = detect(IM,MO,thresh,D_NUMS,A_SCORE);	//detect high-score region
  gettimeofday(&tv_detect_end, NULL);

  gettimeofday(&tv_nms_start, NULL);
  FLOAT *rects = nms(boxes,overlap,D_NUMS,MO);			//get boundary-rectangles of car
  gettimeofday(&tv_nms_end, NULL);

  gettimeofday(&tv_get_new_rects_start, NULL);
  RESULT *CUR = get_new_rects(IM,MO,rects,D_NUMS);		//get current result
  gettimeofday(&tv_get_new_rects_end, NULL);


#if 0
  tvsub(&tv_detect_end, &tv_detect_start, &tv);
  time_detect = tv.tv_sec * 1000.0 + (float)tv.tv_usec / 1000.0;

  tvsub(&tv_nms_end, &tv_nms_start, &tv);
  time_nms = tv.tv_sec * 1000.0 + (float)tv.tv_usec / 1000.0;

  tvsub(&tv_get_new_rects_end, &tv_get_new_rects_start, &tv);
  time_get_new_rects = tv.tv_sec * 1000.0 + (float)tv.tv_usec / 1000.0;

  printf("detect : %f\n", time_detect);
  printf("nms : %f\n", time_nms);
  printf("get_new_rects : %f\n", time_get_new_rects);
#endif

    
  s_free(boxes);
  s_free(rects);
  
  return CUR;
}
Example #8
0
/*
 * finish --
 *	Print out statistics, and give up.
 */
void finish(void)
{
	struct timeval tv = cur_time;
	char *comma = "";

	tvsub(&tv, &start_time);

	putchar('\n');
	fflush(stdout);
	printf("--- %s ping statistics ---\n", hostname);
	printf("%ld packets transmitted, ", ntransmitted);
	printf("%ld received", nreceived);
	if (nrepeats)
		printf(", +%ld duplicates", nrepeats);
	if (nchecksum)
		printf(", +%ld corrupted", nchecksum);
	if (nerrors)
		printf(", +%ld errors", nerrors);
	if (ntransmitted) {
#ifdef USE_IDN
	setlocale(LC_ALL, "C");
#endif
		printf(", %g%% packet loss",
		       (float) ((((long long)(ntransmitted - nreceived)) * 100.0) /
			      ntransmitted));
		printf(", time %ldms", 1000*tv.tv_sec+tv.tv_usec/1000);
	}
	putchar('\n');

	if (nreceived && timing) {
		long tmdev;

		tsum /= nreceived + nrepeats;
		tsum2 /= nreceived + nrepeats;
		tmdev = llsqrt(tsum2 - tsum * tsum);

		printf("rtt min/avg/max/mdev = %ld.%03ld/%lu.%03ld/%ld.%03ld/%ld.%03ld ms",
		       (long)tmin/1000, (long)tmin%1000,
		       (unsigned long)(tsum/1000), (long)(tsum%1000),
		       (long)tmax/1000, (long)tmax%1000,
		       (long)tmdev/1000, (long)tmdev%1000
		       );
		comma = ", ";
	}
	if (pipesize > 1) {
		printf("%spipe %d", comma, pipesize);
		comma = ", ";
	}
	if (nreceived && (!interval || (options&(F_FLOOD|F_ADAPTIVE))) && ntransmitted > 1) {
		int ipg = (1000000*(long long)tv.tv_sec+tv.tv_usec)/(ntransmitted-1);
		printf("%sipg/ewma %d.%03d/%d.%03d ms",
		       comma, ipg/1000, ipg%1000, rtt/8000, (rtt/8)%1000);
	}
	putchar('\n');
	exit(!nreceived || (deadline && nreceived < npackets));
}
Example #9
0
unsigned long stoptime(struct timeval tv_start)
{
        unsigned long  clockus;
        struct timeval tv_stop;
        if (gettimeofday(&tv_stop, NULL) == -1)
                return 0;
        tvsub(&tv_stop, &tv_start);
        clockus = tv_stop.tv_sec * 1000000 + tv_stop.tv_usec;
        return(clockus); //return unit "us"
}
Example #10
0
double
Delta(void)
{
	struct timeval t;
	struct timeval diff;

	(void) gettimeofday(&t, (struct timezone *) 0);
	tvsub(&diff, &t, &start_tv);
	return (diff.tv_sec + diff.tv_usec / 1000000.0);
}
Example #11
0
double
ys_calculate_elapsed_time(const struct timeval *t0, 
	  const struct timeval *t1)
{
	struct timeval td;
	double s;

	tvsub(&td, t1, t0);
	s = td.tv_sec + (td.tv_usec / 1000000.);
	return s;
}
Example #12
0
uint64 tvdelta(struct timeval *start, struct timeval *stop)
{
	struct timeval td;
	uint64	usecs;

	tvsub(&td, stop, start);
	usecs = td.tv_sec;
	usecs *= 1000000;
	usecs += td.tv_usec;
	return (usecs);
}
Example #13
0
void time_measure_end(struct timeval *tv)
{
	struct timeval tv_now, tv_diff;
	double d;

	gettimeofday(&tv_now, NULL);
	tvsub(&tv_now, tv, &tv_diff);

	d = (double) tv_diff.tv_sec * 1000.0 + (double) tv_diff.tv_usec / 1000.0;
	printf("Time (Memory Copy and Launch) = %f (ms)\n", d);
}
Example #14
0
void
pdeltat(struct timeval *t1, struct timeval *t0)
{
	struct timeval td;

#ifdef TRACE
	tprintf("TRACE- pdeltat()\n");
#endif
	tvsub(&td, t1, t0);
	/* change printf formats */
	printf("%d.%01d", td.tv_sec, td.tv_usec / 100000);
}
Example #15
0
void
milli(char *s, uint64 n)
{
    struct timeval td;
    uint64 milli;

    tvsub(&td, &stop_tv, &start_tv);
    milli = td.tv_sec * 1000 + td.tv_usec / 1000;
    milli /= n;
    if (!ftiming) ftiming = stderr;
    fprintf(ftiming, "%s: %d milliseconds\n", s, (int)milli);
}
Example #16
0
void
mb(uint64 bytes)
{
    struct timeval td;
    double  s, bs;

    tvsub(&td, &stop_tv, &start_tv);
    s = td.tv_sec + td.tv_usec / 1000000.0;
    bs = bytes / nz(s);
    if (!ftiming) ftiming = stderr;
    (void) fprintf(ftiming, "%.2f MB/sec\n", bs / MB);
}
Example #17
0
void
nano(char *s, uint64 n)
{
    struct timeval td;
    double  micro;

    tvsub(&td, &stop_tv, &start_tv);
    micro = td.tv_sec * 1000000 + td.tv_usec;
    micro *= 1000;
    if (!ftiming) ftiming = stderr;
    fprintf(ftiming, "%s: %.0f nanoseconds\n", s, micro / n);
}
Example #18
0
void
ptime(uint64 n)
{
    struct timeval td;
    double  s;

    tvsub(&td, &stop_tv, &start_tv);
    s = td.tv_sec + td.tv_usec / 1000000.0;
    if (!ftiming) ftiming = stderr;
    fprintf(ftiming,
            "%d in %.2f secs, %.0f microseconds each\n",
            (int)n, s, s * 1000000 / n);
}
Example #19
0
void
nano(char *s, uint64 n)
{
	struct timeval td;
	double  micro;

	tvsub(&td, &stop_tv, &start_tv);
	micro = td.tv_sec * 1000000 + td.tv_usec;
	micro *= 1000;
	if (micro == 0.0) return;
	if (!ftiming) ftiming = stderr;
	fprintf(ftiming, "<name>%s</name><measurement units=\"nanoseconds\">%.2f</measurement>\n", s, micro / n);
}
Example #20
0
void
mb(uint64 bytes)
{
	struct timeval td;
	double  s, bs;

	tvsub(&td, &stop_tv, &start_tv);
	s = td.tv_sec + td.tv_usec / 1000000.0;
	bs = bytes / nz(s);
	if (s == 0.0) return;
	if (!ftiming) ftiming = stderr;
	(void) fprintf(ftiming, "<measurement units=\"MB/sec\">%.2f</measurement>\n", bs / MB);
}
Example #21
0
void
milli(char *s, uint64 n)
{
	struct timeval td;
	uint64 milli;

	tvsub(&td, &stop_tv, &start_tv);
	milli = td.tv_sec * 1000 + td.tv_usec / 1000;
	milli /= n;
	if (milli == 0.0) return;
	if (!ftiming) ftiming = stderr;
	fprintf(ftiming, "<name>%s</name> <measurement units=\"milliseconds\">%d</measurement>\n", s, (int)milli);
}
Example #22
0
int
ping_timeout_p (struct timeval *start_time, int timeout)
{
  struct timeval now;
  gettimeofday (&now, NULL);
  if (timeout != -1)
    {
      tvsub (&now, start_time);
      if (now.tv_sec >= timeout)
        return 1;
    }
  return 0;
}
Example #23
0
void
context(uint64 xfers)
{
    struct timeval td;
    double  s;

    tvsub(&td, &stop_tv, &start_tv);
    s = td.tv_sec + td.tv_usec / 1000000.0;
    if (!ftiming) ftiming = stderr;
    fprintf(ftiming,
            "%d context switches in %.2f secs, %.0f microsec/switch\n",
            (int)xfers, s, s * 1000000 / xfers);
}
Example #24
0
/*
 *                    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);
}
Example #25
0
int main(int argc, char* argv[])
{
	int i;
	unsigned long prio;
	struct timespec period, runtime, timeout;
	struct timeval tv1, tv2, tv3;

	if (argc != 3) {
		printf("Error: invalid option\n");
	}
	prio = atoi(argv[1]);					/* priority. */
	period = ms_to_timespec(atoi(argv[2]));	/* period. */
	runtime = ms_to_timespec(1000);			/* execution time. */
	timeout = ms_to_timespec(1000);			/* timeout. */

	/* bannar. */
	printf("sample program\n");

	rt_init(); 
	rt_set_period(period);
	rt_set_runtime(runtime);
	rt_set_scheduler(SCHED_FP); /* you can also set SCHED_EDF. */
	rt_set_priority(prio);
	rt_reserve_start(runtime, NULL); /* QoS is guaranteed. */
	rt_run(timeout);

	for (i = 0; i < 20; i++) {
		gettimeofday(&tv1, NULL);
		printf("start %lu:%06lu\n", tv1.tv_sec, tv1.tv_usec);
		fflush(stdout);
		do  {
			gettimeofday(&tv2, NULL);
			/* tv2 - tv1 = tv3 */
			tvsub(&tv2, &tv1, &tv3);
		} while (tv3.tv_sec < 2);
		printf("finish %lu:%06lu\n", tv2.tv_sec, tv2.tv_usec);
		fflush(stdout);

		if (!rt_wait_period()) {
			printf("deadline is missed!\n");
		}
	}
	rt_reserve_stop();
	rt_exit();
	
	return 0;
}
Example #26
0
static void
ptransfer(const char *direction, long bytes, 
	  const struct timeval *t0, 
	  const struct timeval *t1)
{
	struct timeval td;
	float s, bs;

	if (verbose) {
		tvsub(&td, t1, t0);
		s = td.tv_sec + (td.tv_usec / 1000000.);
#define	nz(x)	((x) == 0 ? 1 : (x))
		bs = bytes / nz(s);
		printf("%ld bytes %s in %.3g secs (%.2g Kbytes/sec)\n",
		    bytes, direction, s, bs / 1024.0);
	}
}
Example #27
0
void
micromb(uint64 sz, uint64 n)
{
    struct timeval td;
    double	mb, micro;

    tvsub(&td, &stop_tv, &start_tv);
    micro = td.tv_sec * 1000000 + td.tv_usec;
    micro /= n;
    mb = sz;
    mb /= MB;
    if (!ftiming) ftiming = stderr;
    if (micro >= 10) {
        fprintf(ftiming, "%.6f %.0f\n", mb, micro);
    } else {
        fprintf(ftiming, "%.6f %.3f\n", mb, micro);
    }
}
void store_pcm(phmstream_t *s, char *buf, int len)
{
  int lg;

  g_mutex_lock(s->synclock);
  if (len <= (PCM_TRACE_LEN - s->pcm_wr))
  {
    memcpy(s->pcm_sent + s->pcm_wr, buf, len);
    s->pcm_wr += len;
    if (s->pcm_wr == PCM_TRACE_LEN)
      s->pcm_wr = 0;
  }
  else
  {
    lg = PCM_TRACE_LEN - s->pcm_wr;
    memcpy(s->pcm_sent + s->pcm_wr, buf, lg);
    memcpy(s->pcm_sent, buf+lg, len-lg);
    s->pcm_wr = len-lg;
  }
  s->sent_cnt += len;
	if(s->pcm_need_resync && s->sent_cnt > 0)
	{
		int skip=0;
		struct timeval now;

		// compute the time elapsed since the moment application got something
		// from audio diver
		gettimeofday(&now, 0);
		AEC_MUTEX_LOCK(s);

		tvsub(&now, &s->last_audio_read);

	   
	    skip = 8*2 * now.tv_usec/1000;   // number of bytes waiting in the system buffers

		s->bytes_to_throw = skip;

		s->pcm_need_resync = 0;
		AEC_MUTEX_UNLOCK(s);
		printf("EC:Resync OK %d bytes to throw\n", skip);

  }
  g_mutex_unlock(s->synclock);
}
Example #29
0
void
micro(char *s, uint64 n)
{
    struct timeval td;
    double	micro, mean, var;

    tvsub(&td, &stop_tv, &start_tv);
    micro = td.tv_sec * 1000000 + td.tv_usec;
    micro /= n;

    if (micro == 0.0) return;

    mean = getmeantime();
    var = getvariancetime();

    if (!ftiming) ftiming = stderr;
    fprintf(ftiming, "%s median=%.4f [mean=%.4f +/-%.4f] microseconds\n",
            s, micro, mean,	ci_width(sqrt(var), TRIES));
}
Example #30
0
uint64
delta(void)
{
	static struct timeval last;
	struct timeval t;
	struct timeval diff;
	uint64	m;

	(void) gettimeofday(&t, (struct timezone *) 0);
	if (last.tv_usec) {
		tvsub(&diff, &t, &last);
		last = t;
		m = diff.tv_sec;
		m *= 1000000;
		m += diff.tv_usec;
		return (m);
	} else {
		last = t;
		return (0);
	}
}