monoclock.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #ifndef MONOCLOCK_H_
  2. #define MONOCLOCK_H_
  3. #include <sys/time.h>
  4. /* Macro to simplify benchmarks. */
  5. #define timeval_diff(x, y) ((double)((y).tv_sec - (x).tv_sec) + \
  6. (double)((y).tv_usec - (x).tv_usec) * 0.000001)
  7. /**
  8. * monoclock_get(tv):
  9. * Store the current time in ${tv}. If CLOCK_MONOTONIC is available, use
  10. * that clock; if CLOCK_MONOTONIC is unavailable, use CLOCK_REALTIME (if
  11. * available) or gettimeofday(2).
  12. */
  13. int monoclock_get(struct timeval *);
  14. /**
  15. * monoclock_get_cputime(tv):
  16. * Store in ${tv} the duration the process has been running if
  17. * CLOCK_PROCESS_CPUTIME_ID is available; fall back to monoclock_get()
  18. * otherwise.
  19. */
  20. int monoclock_get_cputime(struct timeval *);
  21. /**
  22. * monoclock_getres(resd):
  23. * Store an upper limit on timer granularity in ${resd}. If CLOCK_MONOTONIC
  24. * is available, use that clock; if CLOCK_MONOTONIC is unavailable, use
  25. * CLOCK_REALTIME (if available) or gettimeofday(2). For this value to be
  26. * meaningful, we assume that clock_getres(x) succeeds iff clock_gettime(x)
  27. * succeeds.
  28. */
  29. int monoclock_getres(double *);
  30. #endif /* !MONOCLOCK_H_ */