From df66a909dbd545cac08776da18b166ab847c08e9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Mon, 29 Nov 2010 13:24:20 +0000 Subject: [PATCH] Measure frame rate. --- CMakeLists.txt | 7 ++++++- glretrace.py | 48 +++++++++++++++++++++++++++++++++++------------- os.hpp | 5 +++++ os_posix.cpp | 17 ++++++++++------- os_win32.cpp | 32 ++++++++++---------------------- trace_write.cpp | 30 ++++++++++++++++++++++++++++++ 6 files changed, 96 insertions(+), 43 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a1ce86d..914c12a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -152,6 +152,11 @@ endif () add_executable (dump dump.cpp trace_model.cpp) +if (WIN32) + set (os os_win32.cpp) +else (WIN32) + set (os os_posix.cpp) +endif (WIN32) if (GLUT_INCLUDE_DIR) add_custom_command ( @@ -172,7 +177,7 @@ if (GLUT_INCLUDE_DIR) ${GLUT_INCLUDE_DIR} ) - add_executable (glretrace glretrace.cpp trace_model.cpp ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp) + add_executable (glretrace glretrace.cpp trace_model.cpp ${os} ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp) target_link_libraries (glretrace ${OPENGL_gl_LIBRARY} diff --git a/glretrace.py b/glretrace.py index c5ec3ae..8bdb1ad 100644 --- a/glretrace.py +++ b/glretrace.py @@ -89,19 +89,22 @@ class GlRetracer(Retracer): if __name__ == '__main__': - print - print '#include ' - print '#include ' - print - print '#include "glproc.hpp"' - print '#include ' - print - print 'static bool double_buffer = false;' - print 'static bool insideGlBeginEnd = false;' - print 'static int __window_width = 256, __window_height = 256;' - print 'bool __reshape_window = false;' - print print ''' +#include +#include + +#include "glproc.hpp" +#include + +static bool double_buffer = false; +static bool insideGlBeginEnd = false; + +static int __window_width = 256, __window_height = 256; +bool __reshape_window = false; + +unsigned __frame = 0; +long long __startTime = 0; + static void checkGlError(void) { if (insideGlBeginEnd) { @@ -153,13 +156,19 @@ checkGlError(void) { static Trace::Parser parser; +static void display_noop(void) { +} + static void display(void) { Trace::Call *call; while ((call = parser.parse_call())) { if (call->name() == "glFlush") { glFlush(); - return; + if (!double_buffer) { + ++__frame; + return; + } } if (!retrace_call(*call)) { @@ -169,12 +178,24 @@ static void display(void) { glutSwapBuffers(); else glFlush(); + ++__frame; return; } } } + // Reached the end of trace glFlush(); + + long long endTime = OS::GetTime(); + float timeInterval = (endTime - __startTime) * 1.0E-6; + + std::cout << + "Rendered " << __frame << " frames" + " in " << timeInterval << " secs," + " average of " << (__frame/timeInterval) << " fps\\n"; + + glutDisplayFunc(&display_noop); glutIdleFunc(NULL); } @@ -226,6 +247,7 @@ int main(int argc, char **argv) for ( ; i < argc; ++i) { if (parser.open(argv[i])) { + __startTime = OS::GetTime(); glutMainLoop(); parser.close(); } diff --git a/os.hpp b/os.hpp index 52f70eb..dbe8deb 100644 --- a/os.hpp +++ b/os.hpp @@ -56,6 +56,11 @@ bool GetCurrentDir(char *str, size_t size); void DebugMessage(const char *format, ...); +/** + * Get the current time in microseconds from an unknown base. + */ +long long GetTime(void); + void Abort(void); } /* namespace OS */ diff --git a/os_posix.cpp b/os_posix.cpp index f4dbaab..3f54da2 100644 --- a/os_posix.cpp +++ b/os_posix.cpp @@ -25,12 +25,13 @@ #include #include -#include #include + +#include +#include #include #include "os.hpp" -#include "trace_write.hpp" namespace OS { @@ -97,6 +98,13 @@ DebugMessage(const char *format, ...) va_end(ap); } +long long GetTime(void) +{ + struct timeval tv; + gettimeofday(&tv, NULL); + return tv.tv_usec + tv.tv_sec*1000000LL; +} + void Abort(void) { @@ -106,8 +114,3 @@ Abort(void) } /* namespace OS */ -static void _uninit(void) __attribute__((destructor)); -static void _uninit(void) { - Trace::Close(); -} - diff --git a/os_win32.cpp b/os_win32.cpp index f9fb56a..8077bd9 100644 --- a/os_win32.cpp +++ b/os_win32.cpp @@ -28,7 +28,6 @@ #include #include "os.hpp" -#include "trace_write.hpp" namespace OS { @@ -107,6 +106,16 @@ DebugMessage(const char *format, ...) } } +long long GetTime(void) +{ + static LARGE_INTEGER frequency; + LARGE_INTEGER counter; + if(!frequency.QuadPart) + QueryPerformanceFrequency(&frequency); + QueryPerformanceCounter(&counter); + return counter.QuadPart*1000000LL/frequency.QuadPart; +} + void Abort(void) { @@ -117,25 +126,4 @@ Abort(void) #endif } - - } /* namespace OS */ - - -#if 0 -BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { - switch(fdwReason) { - case DLL_PROCESS_ATTACH: - case DLL_THREAD_ATTACH: - return TRUE; - case DLL_THREAD_DETACH: - return TRUE; - case DLL_PROCESS_DETACH: - Trace::Close(); - return TRUE; - } - (void)hinstDLL; - (void)lpvReserved; - return TRUE; -} -#endif diff --git a/trace_write.cpp b/trace_write.cpp index 3de3bae..854db10 100644 --- a/trace_write.cpp +++ b/trace_write.cpp @@ -342,3 +342,33 @@ void Abort(void) { } } /* namespace Trace */ + + +#ifdef WIN32 + +#if 0 +BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { + switch(fdwReason) { + case DLL_PROCESS_ATTACH: + case DLL_THREAD_ATTACH: + return TRUE; + case DLL_THREAD_DETACH: + return TRUE; + case DLL_PROCESS_DETACH: + Trace::Close(); + return TRUE; + } + (void)hinstDLL; + (void)lpvReserved; + return TRUE; +} +#endif + +#else + +static void _uninit(void) __attribute__((destructor)); +static void _uninit(void) { + Trace::Close(); +} + +#endif -- 2.43.0