diff options
author | Jordan Justen <jordan.l.justen@intel.com> | 2013-10-10 17:04:10 -0700 |
---|---|---|
committer | Jordan Justen <jordan.l.justen@intel.com> | 2013-10-14 15:01:44 -0700 |
commit | d1a9c3fb23d119d5678521f0e578c81e87117343 (patch) | |
tree | 4e126ab8a4a9336e2095daa9550c53dabffd872d | |
parent | 31450c71aeddbfc9e8748a31b9aa91819d1ce229 (diff) |
piglit-util: add piglit_get_microseconds
Signed-off-by: Jordan Justen <jordan.l.justen@intel.com>
-rw-r--r-- | CMakeLists.txt | 6 | ||||
-rw-r--r-- | tests/util/piglit-util.c | 17 | ||||
-rw-r--r-- | tests/util/piglit-util.h | 8 |
3 files changed, 31 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ec5ddfb6..c876a053c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,7 @@ INCLUDE (CheckCCompilerFlag) INCLUDE (CheckCXXCompilerFlag) INCLUDE (CheckFunctionExists) INCLUDE (CheckIncludeFile) +INCLUDE (CheckLibraryExists) INCLUDE (FindPkgConfig) project (piglit) @@ -294,6 +295,11 @@ check_function_exists(strchrnul HAVE_STRCHRNUL) check_function_exists(strndup HAVE_STRNDUP) check_function_exists(fopen_s HAVE_FOPEN_S) check_function_exists(setrlimit HAVE_SETRLIMIT) +check_function_exists(clock_gettime HAVE_CLOCK_GETTIME_FUNC) +check_library_exists(rt clock_gettime "time.h" HAVE_CLOCK_GETTIME_RT) +if(HAVE_CLOCK_GETTIME_FUNC OR HAVE_CLOCK_GETTIME_RT) + add_definitions(-DHAVE_CLOCK_GETTIME) +endif() check_include_file(sys/time.h HAVE_SYS_TIME_H) check_include_file(sys/types.h HAVE_SYS_TYPES_H) diff --git a/tests/util/piglit-util.c b/tests/util/piglit-util.c index 71d55a73e..18df0b62a 100644 --- a/tests/util/piglit-util.c +++ b/tests/util/piglit-util.c @@ -33,6 +33,10 @@ #include <string.h> #include <errno.h> +#ifdef HAVE_CLOCK_GETTIME +#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,16 @@ write_null: va_end(va); return size_written; } + +uint64_t +piglit_get_microseconds(void) +{ +#ifdef HAVE_CLOCK_GETTIME + struct timespec t; + clock_gettime(CLOCK_MONOTONIC, &t); + return (t.tv_sec * 1000000) + (t.tv_nsec / 1000); +#else + return (uint64_t) 0; +#endif +} + diff --git a/tests/util/piglit-util.h b/tests/util/piglit-util.h index 52f053ef8..6f64ccf5a 100644 --- a/tests/util/piglit-util.h +++ b/tests/util/piglit-util.h @@ -174,6 +174,14 @@ 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. + */ +uint64_t +piglit_get_microseconds(void); + #ifdef __cplusplus } /* end extern "C" */ #endif |