6 #if defined(__linux__) || defined(__APPLE__)
18 #if defined(i686) || defined(i386)
19 typedef unsigned long long RTS_CPUCYCLE;
20 #include <I386/i386Lib.h>
21 #elif defined(vxworks)
22 typedef unsigned int RTS_CPUCYCLE;
23 #include <MVME/mvmeFastTickerLib.h>
25 typedef unsigned long long RTS_CPUCYCLE;
53 gettimeofday(&ts_old,NULL);
55 clock_gettime(CLOCK_REALTIME, &ts_old);
63 gettimeofday(&ts_new, NULL);
65 clock_gettime(CLOCK_REALTIME, &ts_new);
67 t = ts_new.tv_sec - ts_old.tv_sec;
70 t += ((double)(ts_new.tv_usec - ts_old.tv_usec))/1000000.0;
72 t += ((double)(ts_new.tv_nsec - ts_old.tv_nsec))/1000000000.0;
80 gettimeofday(&ts_new, NULL);
82 clock_gettime(CLOCK_REALTIME, &ts_new);
87 t += ((double)(ts_new.tv_usec))/1000000.0;
89 t += ((double)(ts_new.tv_nsec))/1000000000.0;
94 double record_time() {
96 gettimeofday(&ts_new, NULL);
98 clock_gettime(CLOCK_REALTIME, &ts_new);
100 t = ts_new.tv_sec - ts_last.tv_sec;
103 t += ((double)(ts_new.tv_usec - ts_last.tv_usec))/1000000.0;
105 t += ((double)(ts_new.tv_nsec - ts_last.tv_nsec))/1000000000.0;
112 int stopwatchcounting;
114 void StopWatchReset() {
115 stopwatchcounting = 0;
119 double StopWatchStop() {
120 if(stopwatchcounting) stopwatch += record_time();
121 stopwatchcounting = 0;
125 double StopWatchStart() {
126 if(stopwatchcounting) stopwatch += record_time();
128 stopwatchcounting = 1;
134 if(ref_cnt == 1)
return record_time();
140 if(ref_cnt < 0) ref_cnt = 0;
141 if(ref_cnt == 0)
return record_time();
151 inline double record_time()
153 static bool nfirst =
false;
155 static timeval ts_old;
156 static timeval ts_new;
158 static timespec ts_old;
159 static timespec ts_new;
166 gettimeofday(&ts_new, NULL);
168 clock_gettime(CLOCK_REALTIME, &ts_new);
170 t = ts_new.tv_sec - ts_old.tv_sec;
173 t += ((double)(ts_new.tv_usec - ts_old.tv_usec))/1000000.0;
175 t += ((double)(ts_new.tv_nsec - ts_old.tv_nsec))/1000000000.0;
183 gettimeofday(&ts_old,NULL);
185 clock_gettime(CLOCK_REALTIME, &ts_old);
190 inline double record_abs_time(
int set)
192 static bool nfirst =
false;
194 static timeval ts_old;
195 static timeval ts_new;
197 static timespec ts_old;
198 static timespec ts_new;
205 gettimeofday(&ts_new, NULL);
207 clock_gettime(CLOCK_REALTIME, &ts_new);
209 t = ts_new.tv_sec - ts_old.tv_sec;
212 t += ((double)(ts_new.tv_usec - ts_old.tv_usec))/1000000.0;
214 t += ((double)(ts_new.tv_nsec - ts_old.tv_nsec))/1000000000.0;
223 gettimeofday(&ts_old,NULL);
225 clock_gettime(CLOCK_REALTIME, &ts_old);
238 static float cycle_mult = 0.0;
240 inline void getCpuCycle_init()
243 mvmeFastTickerInit();
247 inline void setCpuCycleTime(
float m)
252 inline float getCpuCycleTime()
258 inline RTS_CPUCYCLE getCpuCycle64()
260 #if defined(i686) || defined(i386)
261 return (RTS_CPUCYCLE)getfast_l();
262 #elif defined(vxworks)
263 return (RTS_CPUCYCLE)mvmeFastTickerGet();
274 gettimeofday(&ts,NULL);
276 clock_gettime(CLOCK_REALTIME, &ts);
282 x += ts.tv_usec*1000;
290 inline unsigned int getCpuCycle()
292 #if defined(i686) || defined(i386)
294 #elif defined(vxworks)
295 return mvmeFastTickerGet();
297 RTS_CPUCYCLE x = getCpuCycle64();
298 return (
unsigned int)(x & 0xffffffff);
302 inline void timeCpuCycle()
309 #ifdef vxworks // 1 second either way....
315 usleep((
unsigned long)1000000);
320 cycle_mult = 1e6 / (float)(t2 - t1);
322 }
while((t1 > t2) || (i>3));
325 inline float cpu2usec(RTS_CPUCYCLE x)
328 return ((
float)x) * cycle_mult;
333 #if defined linux && defined i686
335 inline double hrecord_time()
339 static unsigned long long lt=0;
340 unsigned long long t;
341 unsigned long long et;
342 static double clockpersec;
353 clockpersec = t + (0xffffffffffffffffLL - lt);
365 et = t + (0xffffffffffffffffLL - lt);
369 return (((
double)et) / clockpersec);