Mercurial > hg > Members > koba > t_dandy
view profile.c @ 17:927401604461
add spe object
author | koba <koba@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 17 Dec 2010 04:16:25 +0900 |
parents | 435ac1cdb64e |
children |
line wrap: on
line source
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<sys/time.h> #include<unistd.h> #include"profile.h" static unsigned long timeprof_overhead; #define timeprof_get_time(t) {\ struct timeval t0;\ gettimeofday(&t0,NULL);\ (t).sec=t0.tv_sec;\ (t).usec=t0.tv_usec;} void timeprof_begin(Timeprof t) { timeprof_get_time(t->begin); } int timeprof_end(Timeprof t) { unsigned int etime; timeprof_get_time(t->end); if (t->begin.usec > t->end.usec) { t->end.usec += 1000000; t->end.sec--; } etime = ((t->end.sec - t->begin.sec) * 1000000 + (t->end.usec - t->begin.usec)) - timeprof_overhead; if (etime > t->peak) { t->peak = etime; } if (t->average > 0) { t->average += etime; t->average /= 2; } else { t->average = etime; } return etime; } void timeprof_sprint(char *s, const char *profname, Timeprof t) { sprintf(s, "%s: average:%dusec, peak:%dusec", profname, t->average, t->peak); } void timeprof_init() { struct time_profile t; timeprof_begin(&t); timeprof_overhead = timeprof_end(&t); } Timeprof timeprof_new() { Timeprof t = (Timeprof) malloc(sizeof(struct time_profile)); memset(t, 0, sizeof(struct time_profile)); return t; }