diff options
-rwxr-xr-x | CMakeLists.txt | 9 | ||||
-rw-r--r-- | common/os_posix.cpp | 9 | ||||
-rw-r--r-- | common/os_time.hpp | 85 | ||||
-rw-r--r-- | common/os_win32.cpp | 11 | ||||
-rw-r--r-- | glretrace_main.cpp | 3 |
5 files changed, 97 insertions, 20 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 3fa8e454..24e2afc0 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -573,6 +573,11 @@ if (WIN32 OR APPLE OR X11_FOUND) pthread dl ) + + if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") + target_link_libraries (glretrace rt) + endif () + endif () install (TARGETS glretrace RUNTIME DESTINATION bin) @@ -601,6 +606,10 @@ if (EGL_FOUND AND X11_FOUND AND NOT WIN32 AND NOT APPLE) dl ) + if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") + target_link_libraries (eglretrace rt) + endif () + install (TARGETS eglretrace RUNTIME DESTINATION bin) endif () diff --git a/common/os_posix.cpp b/common/os_posix.cpp index e6af7383..261fe88c 100644 --- a/common/os_posix.cpp +++ b/common/os_posix.cpp @@ -30,7 +30,6 @@ #include <stdlib.h> #include <unistd.h> -#include <sys/time.h> #include <sys/wait.h> #include <sys/stat.h> #include <fcntl.h> @@ -159,14 +158,6 @@ log(const char *format, ...) logging = false; } -long long -getTime(void) -{ - struct timeval tv; - gettimeofday(&tv, NULL); - return tv.tv_usec + tv.tv_sec*1000000LL; -} - void abort(void) { diff --git a/common/os_time.hpp b/common/os_time.hpp new file mode 100644 index 00000000..a4f52093 --- /dev/null +++ b/common/os_time.hpp @@ -0,0 +1,85 @@ +/************************************************************************** + * + * Copyright 2011 Jose Fonseca + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + **************************************************************************/ + +/* + * Simple OS time measurement abstraction. + */ + +#ifndef _OS_TIME_HPP_ +#define _OS_TIME_HPP_ + + +#if defined(_WIN32) +#include <windows.h> +#elif defined(__linux__) +#include <time.h> +#else +#include <sys/time.h> +#endif + + +namespace os { + + // OS dependent time frequency +#if defined(_WIN32) + // runtime variable on Windows + extern long long timeFrequency; +#elif defined(__linux__) + // nanoseconds + static const long long timeFrequency = 1000000000; +#else + // microseconds on + static const long long timeFrequency = 1000000; +#endif + + // Time from an unknown base in a unit determined by timeFrequency + inline long long + getTime(void) { +#if defined(_WIN32) + if (!timeFrequency) { + LARGE_INTEGER frequency; + QueryPerformanceFrequency(&frequency); + timeFrequency = frequency.QuadPart; + } + LARGE_INTEGER counter; + QueryPerformanceCounter(&counter); + return counter.QuadPart; +#elif defined(__linux__) + struct timespec tp; + if (clock_gettime(CLOCK_REALTIME, &tp) == -1) { + return 0; + } + return tp.tv_sec * 1000000000LL + tp.tv_nsec; +#else + struct timeval tv; + gettimeofday(&tv, NULL); + return tv.tv_sec * 1000000LL + tv.tv_usec; +#endif + } + + +} /* namespace os */ + +#endif /* _OS_TIME_HPP_ */ diff --git a/common/os_win32.cpp b/common/os_win32.cpp index 7b35ccf8..199ae5a7 100644 --- a/common/os_win32.cpp +++ b/common/os_win32.cpp @@ -213,16 +213,7 @@ log(const char *format, ...) #endif } -long long -getTime(void) -{ - static LARGE_INTEGER frequency; - LARGE_INTEGER counter; - if (!frequency.QuadPart) - QueryPerformanceFrequency(&frequency); - QueryPerformanceCounter(&counter); - return counter.QuadPart*1000000LL/frequency.QuadPart; -} +long long timeFrequency = 0LL; void abort(void) diff --git a/glretrace_main.cpp b/glretrace_main.cpp index 978a34ee..c2ca6642 100644 --- a/glretrace_main.cpp +++ b/glretrace_main.cpp @@ -27,6 +27,7 @@ #include <string.h> #include "os_string.hpp" +#include "os_time.hpp" #include "image.hpp" #include "retrace.hpp" #include "glproc.hpp" @@ -230,7 +231,7 @@ static void display(void) { glFlush(); long long endTime = os::getTime(); - float timeInterval = (endTime - startTime) * 1.0E-6; + float timeInterval = (endTime - startTime) * (1.0 / os::timeFrequency); if (retrace::verbosity >= -1) { std::cout << |