timefn.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright (c) Meta Platforms, Inc. and affiliates.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under both the BSD-style license (found in the
  6. * LICENSE file in the root directory of this source tree) and the GPLv2 (found
  7. * in the COPYING file in the root directory of this source tree).
  8. * You may select, at your option, one of the above-listed licenses.
  9. */
  10. #ifndef TIME_FN_H_MODULE_287987
  11. #define TIME_FN_H_MODULE_287987
  12. #if defined (__cplusplus)
  13. extern "C" {
  14. #endif
  15. /*-****************************************
  16. * Types
  17. ******************************************/
  18. #if !defined (__VMS) && (defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) )
  19. # if defined(_AIX)
  20. # include <inttypes.h>
  21. # else
  22. # include <stdint.h> /* uint64_t */
  23. # endif
  24. typedef uint64_t PTime; /* Precise Time */
  25. #else
  26. typedef unsigned long long PTime; /* does not support compilers without long long support */
  27. #endif
  28. /* UTIL_time_t contains a nanosecond time counter.
  29. * The absolute value is not meaningful.
  30. * It's only valid to compute the difference between 2 measurements. */
  31. typedef struct { PTime t; } UTIL_time_t;
  32. #define UTIL_TIME_INITIALIZER { 0 }
  33. /*-****************************************
  34. * Time functions
  35. ******************************************/
  36. UTIL_time_t UTIL_getTime(void);
  37. /* Timer resolution can be low on some platforms.
  38. * To improve accuracy, it's recommended to wait for a new tick
  39. * before starting benchmark measurements */
  40. void UTIL_waitForNextTick(void);
  41. /* tells if timefn will return correct time measurements
  42. * in presence of multi-threaded workload.
  43. * note : this is not the case if only C90 clock_t measurements are available */
  44. int UTIL_support_MT_measurements(void);
  45. PTime UTIL_getSpanTimeNano(UTIL_time_t clockStart, UTIL_time_t clockEnd);
  46. PTime UTIL_clockSpanNano(UTIL_time_t clockStart);
  47. PTime UTIL_getSpanTimeMicro(UTIL_time_t clockStart, UTIL_time_t clockEnd);
  48. PTime UTIL_clockSpanMicro(UTIL_time_t clockStart);
  49. #define SEC_TO_MICRO ((PTime)1000000) /* nb of microseconds in a second */
  50. #if defined (__cplusplus)
  51. }
  52. #endif
  53. #endif /* TIME_FN_H_MODULE_287987 */