24 #include <hrt_utils.h>
36 #if (HRT_REALTIME_METHOD==HRT_USE_CLOCK_GETTIME)
37 # if (defined(_POSIX_MONOTONIC_CLOCK) && (_POSIX_MONOTONIC_CLOCK+0 >= 0))
38 # define REAL_CLOCK_TYPE CLOCK_MONOTONIC
40 # define REAL_CLOCK_TYPE CLOCK_REALTIME
42 ret = clock_gettime(REAL_CLOCK_TYPE, &x->time);
43 #elif (HRT_REALTIME_METHOD==HRT_USE_GETTIMEOFDAY)
44 ret = gettimeofday(&x->time, NULL);
45 #elif (HRT_REALTIME_METHOD==HRT_USE_TIMES)
47 clock_t r = times(NULL);
55 #elif (HRT_REALTIME_METHOD==HRT_USE_ANSI_TIME)
57 time_t r = time(NULL);
75 #if (HRT_CPUTIME_METHOD==HRT_USE_CLOCK_GETTIME)
76 ret = clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &x->time);
77 #elif (HRT_CPUTIME_METHOD==HRT_USE_GETRUSAGE)
78 ret = getrusage(RUSAGE_SELF, &x->time);
79 #elif (HRT_CPUTIME_METHOD==HRT_USE_TIMES)
81 clock_t r = times(&x->time);
82 ret = (r == -1 ? r : 0);
84 #elif (HRT_CPUTIME_METHOD==HRT_USE_ANSI_CLOCK)
103 ret = hrt_rtnow(&x->rtstamp);
106 ret = hrt_ctnow(&x->ctstamp);
110 #if (HRT_REALTIME_METHOD==HRT_USE_CLOCK_GETTIME \
111 || HRT_CPUTIME_METHOD==HRT_USE_CLOCK_GETTIME)
115 return (((y->tv_sec - x->tv_sec) * 1000000.0)
116 + ((y->tv_nsec - x->tv_nsec) / 1000.0));
120 #if (HRT_REALTIME_METHOD==HRT_USE_GETTIMEOFDAY \
121 || HRT_CPUTIME_METHOD==HRT_USE_GETRUSAGE)
125 return (((y->tv_sec - x->tv_sec) * 1000000.0)
126 + (y->tv_usec - x->tv_usec));
130 #if (HRT_REALTIME_METHOD==HRT_USE_TIMES \
131 || HRT_CPUTIME_METHOD==HRT_USE_TIMES \
132 || HRT_CPUTIME_METHOD==HRT_USE_ANSI_CLOCK)
134 clock_t_diff(clock_t y, clock_t x)
137 return (
double)(y - x);
144 #if (HRT_REALTIME_METHOD==HRT_USE_TIMES)
145 static long clock_ticks = 0;
146 if (clock_ticks == 0) {
147 clock_ticks = sysconf(_SC_CLK_TCK);
148 assert (clock_ticks > 0);
152 #if (HRT_REALTIME_METHOD==HRT_USE_CLOCK_GETTIME)
153 return timespec_diff(&y->time, &x->time);
154 #elif (HRT_REALTIME_METHOD==HRT_USE_GETTIMEOFDAY)
155 return timeval_diff(&y->time, &x->time);
156 #elif (HRT_REALTIME_METHOD==HRT_USE_TIMES)
157 return ((clock_t_diff(y->time, x->time) * 1000000.0) / clock_ticks);
158 #elif (HRT_REALTIME_METHOD==HRT_USE_ANSI_TIME)
159 return (difftime(y->time, x->time) * 1000000.0);
166 #if (HRT_CPUTIME_METHOD==HRT_USE_TIMES)
167 static long clock_ticks = 0;
168 if (clock_ticks == 0) {
169 clock_ticks = sysconf(_SC_CLK_TCK);
170 assert (clock_ticks > 0);
174 #if (HRT_CPUTIME_METHOD==HRT_USE_CLOCK_GETTIME)
175 return timespec_diff(&y->time, &x->time);
176 #elif (HRT_CPUTIME_METHOD==HRT_USE_GETRUSAGE)
177 return (timeval_diff(&y->time.ru_utime, &x->time.ru_utime)
178 + timeval_diff(&y->time.ru_stime, &x->time.ru_stime));
179 #elif (HRT_CPUTIME_METHOD==HRT_USE_TIMES)
180 return (((clock_t_diff(y->time.tms_utime, x->time.tms_utime)
181 + clock_t_diff(y->time.tms_stime, x->time.tms_stime))
182 * 1000000.0) / clock_ticks);
183 #elif (HRT_CPUTIME_METHOD==HRT_USE_ANSI_CLOCK)
184 return ((clock_t_diff(y->time, x->time) * 1000000.0) / CLOCKS_PER_SEC);
191 #if (HRT_REALTIME_METHOD==HRT_USE_CLOCK_GETTIME)
194 #elif (HRT_REALTIME_METHOD==HRT_USE_GETTIMEOFDAY)
197 #elif (HRT_REALTIME_METHOD==HRT_USE_TIMES)
199 #elif (HRT_REALTIME_METHOD==HRT_USE_ANSI_TIME)
207 #if (HRT_CPUTIME_METHOD==HRT_USE_CLOCK_GETTIME)
210 #elif (HRT_CPUTIME_METHOD==HRT_USE_GETRUSAGE)
211 x->time.ru_utime.tv_sec = 0;
212 x->time.ru_utime.tv_usec = 0;
213 x->time.ru_stime.tv_sec = 0;
214 x->time.ru_stime.tv_usec = 0;
215 #elif (HRT_CPUTIME_METHOD==HRT_USE_TIMES)
216 x->time.tms_utime = 0;
217 x->time.tms_stime = 0;
218 #elif (HRT_CPUTIME_METHOD==HRT_USE_ANSI_CLOCK)
226 hrt_rtnull(&x->rtstamp);
227 hrt_ctnull(&x->ctstamp);