timefn.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. /*-****************************************
  13. * Types
  14. ******************************************/
  15. #if !defined (__VMS) && (defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) )
  16. # if defined(_AIX)
  17. # include <inttypes.h>
  18. # else
  19. # include <stdint.h> /* uint64_t */
  20. # endif
  21. typedef uint64_t PTime; /* Precise Time */
  22. #else
  23. typedef unsigned long long PTime; /* does not support compilers without long long support */
  24. #endif
  25. /* UTIL_time_t contains a nanosecond time counter.
  26. * The absolute value is not meaningful.
  27. * It's only valid to compute the difference between 2 measurements. */
  28. typedef struct { PTime t; } UTIL_time_t;
  29. #define UTIL_TIME_INITIALIZER { 0 }
  30. /*-****************************************
  31. * Time functions
  32. ******************************************/
  33. UTIL_time_t UTIL_getTime(void);
  34. /* Timer resolution can be low on some platforms.
  35. * To improve accuracy, it's recommended to wait for a new tick
  36. * before starting benchmark measurements */
  37. void UTIL_waitForNextTick(void);
  38. /* tells if timefn will return correct time measurements
  39. * in presence of multi-threaded workload.
  40. * note : this is not the case if only C90 clock_t measurements are available */
  41. int UTIL_support_MT_measurements(void);
  42. PTime UTIL_getSpanTimeNano(UTIL_time_t clockStart, UTIL_time_t clockEnd);
  43. PTime UTIL_clockSpanNano(UTIL_time_t clockStart);
  44. PTime UTIL_getSpanTimeMicro(UTIL_time_t clockStart, UTIL_time_t clockEnd);
  45. PTime UTIL_clockSpanMicro(UTIL_time_t clockStart);
  46. #define SEC_TO_MICRO ((PTime)1000000) /* nb of microseconds in a second */
  47. #endif /* TIME_FN_H_MODULE_287987 */