]> git.cworth.org Git - apitrace/commitdiff
Measure frame rate.
authorJosé Fonseca <jfonseca@vmware.com>
Mon, 29 Nov 2010 13:24:20 +0000 (13:24 +0000)
committerJosé Fonseca <jfonseca@vmware.com>
Mon, 29 Nov 2010 13:24:20 +0000 (13:24 +0000)
CMakeLists.txt
glretrace.py
os.hpp
os_posix.cpp
os_win32.cpp
trace_write.cpp

index a1ce86d2e2723e717899a33e2bf64ef21f0ea44d..914c12a7caa9cf0d9b77f00d3539cfe53af48b42 100644 (file)
@@ -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}
index c5ec3aee463b8638b733e743a680707ef4d34873..8bdb1ad6f96c869810ccd074b6fce088b99fe26c 100644 (file)
@@ -89,19 +89,22 @@ class GlRetracer(Retracer):
 
 
 if __name__ == '__main__':
-    print
-    print '#include <string.h>'
-    print '#include <iostream>'
-    print
-    print '#include "glproc.hpp"'
-    print '#include <GL/glut.h>'
-    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 <string.h>
+#include <iostream>
+
+#include "glproc.hpp"
+#include <GL/glut.h>
+
+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 52f70eb5a772275a5b4992d2a6e20204a6245445..dbe8deb3ec4b3b45b51406880a0878fb37eb941a 100644 (file)
--- 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 */
index f4dbaab5c3119f572923ce5a7496f2bfbb0fc36a..3f54da2c9545fc516f1153427b5583ac47bb646a 100644 (file)
 
 #include <string.h>
 #include <stdio.h>
-#include <unistd.h>
 #include <stdlib.h>
+
+#include <unistd.h>
+#include <sys/time.h>
 #include <pthread.h>
 
 #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();
-}
-
index f9fb56a1f639be8b273915ddc513270238cb9edb..8077bd9a867a79d37bc6284dfa17603839af7940 100644 (file)
@@ -28,7 +28,6 @@
 #include <stdio.h>
 
 #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
index 3de3bae6505c419137ed53d7d4693bf3b87951d6..854db104b1755d7e39101ce2bf42e390c50d8076 100644 (file)
@@ -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