home *** CD-ROM | disk | FTP | other *** search
- #include <bsd43/sys/syscall.h>
- #include <bsd43/sys/time.h>
- #include <bsd43/sys/resource.h>
- #include <stdio.h>
- #include "res.h"
-
- #define USE_GETTIMEOFDAY 1
-
- extern FILE *outfp;
-
- #if USE_GETTIMEOFDAY
- static struct bsd43_timeval starttd;
- static struct bsd43_timeval stoptd;
- #else /* USE_GETTIMEOFDAY */
- static struct bsd43_rusage start;
- static struct bsd43_rusage stop;
- #endif /* USE_GETTIMEOFDAY */
-
- int
- res_sys_start()
- {
- #if USE_GETTIMEOFDAY
- if (syscall(BSD43_SYS_gettimeofday, &starttd, (struct bsd43_timezone *)0) == -1)
- {
- vcouldnot("gettimeofday(): start");
- return -1;
- }
- #else /* USE_GETTIMEOFDAY */
- if (syscall(BSD43_SYS_getrusage, BSD43_RUSAGE_SELF, &start) == -1)
- {
- vcouldnot("getrusage(): start");
- return -1;
- }
- #endif /* USE_GETTIMEOFDAY */
-
- return 0;
- }
-
- int
- res_sys_stop()
- {
- #if USE_GETTIMEOFDAY
- if (syscall(BSD43_SYS_gettimeofday, &stoptd, (struct bsd43_timezone *)0) == -1)
- {
- vcouldnot("gettimeofday(): stop");
- return -1;
- }
- #else /* USE_GETTIMEOFDAY */
- if (syscall(BSD43_SYS_getrusage, BSD43_RUSAGE_SELF, &stop) == -1)
- {
- vcouldnot("getrusage(): stop");
- return -1;
- }
- #endif /* USE_GETTIMEOFDAY */
-
- return 0;
- }
-
- void
- res_print()
- {
- fprintf
- (
- outfp,
- " <Ds=%dus>",
- #if USE_GETTIMEOFDAY
- (stoptd.tv_sec - starttd.tv_sec) * 1000000 +
- (stoptd.tv_usec - starttd.tv_usec)
- #else /* USE_GETTIMEOFDAY */
- (stop.ru_stime.tv_sec - start.ru_stime.tv_sec) * 1000000 +
- (stop.ru_stime.tv_usec - start.ru_stime.tv_usec)
- #endif /* USE_GETTIMEOFDAY */
- );
-
- #if USE_GETTIMEOFDAY
- stoptd.tv_sec = starttd.tv_sec;
- stoptd.tv_usec = starttd.tv_usec;
- #else /* USE_GETTIMEOFDAY */
- stop.ru_stime.tv_sec = start.ru_stime.tv_sec;
- stop.ru_stime.tv_usec = start.ru_stime.tv_usec;
- #endif /* USE_GETTIMEOFDAY */
- }
-