v2: * Use Chad's cmake detection * return value is signed, and a negative indicates an error
Signed-off-by: Jordan Justen <[email protected]> Cc: Chad Versace <[email protected]> Cc: Ian Romanick <[email protected]> --- tests/util/piglit-util.c | 20 ++++++++++++++++++++ tests/util/piglit-util.h | 10 ++++++++++ 2 files changed, 30 insertions(+) diff --git a/tests/util/piglit-util.c b/tests/util/piglit-util.c index 71d55a7..8836978 100644 --- a/tests/util/piglit-util.c +++ b/tests/util/piglit-util.c @@ -33,6 +33,10 @@ #include <string.h> #include <errno.h> +#ifdef PIGLIT_HAS_POSIX_CLOCK_MONOTONIC +#include <time.h> +#endif + #include "config.h" #if defined(HAVE_SYS_TIME_H) && defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_SETRLIMIT) #include <sys/time.h> @@ -462,3 +466,19 @@ write_null: va_end(va); return size_written; } + +int64_t +piglit_get_microseconds(void) +{ +#ifdef PIGLIT_HAS_POSIX_CLOCK_MONOTONIC + struct timespec t; + int r = clock_gettime(CLOCK_MONOTONIC, &t); + if (r >= 0) + return (t.tv_sec * 1000000) + (t.tv_nsec / 1000); + else + return -1LL; +#else + return (int64_t) -1; +#endif +} + diff --git a/tests/util/piglit-util.h b/tests/util/piglit-util.h index 52f053e..7bccce8 100644 --- a/tests/util/piglit-util.h +++ b/tests/util/piglit-util.h @@ -174,6 +174,16 @@ piglit_source_dir(void); size_t piglit_join_paths(char buf[], size_t buf_size, int n, ...); +/** + * \brief Get a monotonically increasing time in microseconds + * + * This time can be used for relative time measurements. + * + * A -1 return value indicates an error. + */ +int64_t +piglit_get_microseconds(void); + #ifdef __cplusplus } /* end extern "C" */ #endif -- 1.7.10.4 _______________________________________________ Piglit mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/piglit
