]> git.cworth.org Git - apitrace/blobdiff - retrace/retrace_main.cpp
Ignore OpenGL core 3.2 requirement on Windows.
[apitrace] / retrace / retrace_main.cpp
index c15af29fe3daf2edf9696957aa5b8b321d670fd3..9386a6182a989621a62a60c5e5b689fbd2fcaac6 100644 (file)
@@ -49,18 +49,23 @@ namespace retrace {
 
 
 trace::Parser parser;
+trace::Profiler profiler;
 
 
 int verbosity = 0;
 bool debug = true;
-bool profiling = false;
-
+bool dumpingState = false;
 
 bool doubleBuffer = true;
 bool coreProfile = false;
 
+bool profiling = false;
+bool profilingGpuTimes = false;
+bool profilingCpuTimes = false;
+bool profilingPixelsDrawn = false;
 
-static unsigned frameNo = 0;
+unsigned frameNo = 0;
+unsigned callNo = 0;
 
 
 void
@@ -122,6 +127,7 @@ mainLoop() {
     addCallbacks(retracer);
 
     long long startTime = 0; 
+    frameNo = 0;
 
     startTime = os::getTime();
     trace::Call *call;
@@ -147,6 +153,7 @@ mainLoop() {
             }
         }
 
+        callNo = call->no;
         retracer.retrace(*call);
 
         if (doSnapshot && !swapRenderTarget) {
@@ -177,7 +184,7 @@ mainLoop() {
     if (waitOnFinish) {
         waitForInput();
     } else {
-        exit(0);
+        return;
     }
 }
 
@@ -188,11 +195,13 @@ mainLoop() {
 static void
 usage(const char *argv0) {
     std::cout << 
-        "Usage: " << argv0 << " [OPTION] TRACE\n"
+        "Usage: " << argv0 << " [OPTION] TRACE [...]\n"
         "Replay TRACE.\n"
         "\n"
         "  -b           benchmark mode (no error checking or warning messages)\n"
-        "  -p           profiling mode (run whole trace, dump profiling info)\n"
+        "  -pcpu        cpu profiling (cpu times per call)\n"
+        "  -pgpu        gpu profiling (gpu times per draw call)\n"
+        "  -ppd         pixels drawn profiling (pixels drawn per draw call)\n"
         "  -c PREFIX    compare against snapshots\n"
         "  -C CALLSET   calls to compare (default is every frame)\n"
         "  -core        use core profile\n"
@@ -209,6 +218,8 @@ usage(const char *argv0) {
 extern "C"
 int main(int argc, char **argv)
 {
+    using namespace retrace;
+
     assert(compareFrequency.empty());
     assert(snapshotFrequency.empty());
 
@@ -225,10 +236,6 @@ int main(int argc, char **argv)
         } else if (!strcmp(arg, "-b")) {
             retrace::debug = false;
             retrace::verbosity = -1;
-        } else if (!strcmp(arg, "-p")) {
-            retrace::debug = false;
-            retrace::profiling = true;
-            retrace::verbosity = -1;
         } else if (!strcmp(arg, "-c")) {
             comparePrefix = argv[++i];
             if (compareFrequency.empty()) {
@@ -241,6 +248,7 @@ int main(int argc, char **argv)
             }
         } else if (!strcmp(arg, "-D")) {
             dumpStateCallNo = atoi(argv[++i]);
+            dumpingState = true;
             retrace::verbosity = -2;
         } else if (!strcmp(arg, "-core")) {
             retrace::coreProfile = true;
@@ -269,6 +277,18 @@ int main(int argc, char **argv)
             ++retrace::verbosity;
         } else if (!strcmp(arg, "-w")) {
             waitOnFinish = true;
+        } else if (arg[1] == 'p') {
+            retrace::debug = false;
+            retrace::profiling = true;
+            retrace::verbosity = -1;
+
+            if (!strcmp(arg, "-pcpu")) {
+                retrace::profilingCpuTimes = true;
+            } else if (!strcmp(arg, "-pgpu")) {
+                retrace::profilingGpuTimes = true;
+            } else if (!strcmp(arg, "-ppd")) {
+                retrace::profilingPixelsDrawn = true;
+            }
         } else {
             std::cerr << "error: unknown option " << arg << "\n";
             usage(argv[0]);
@@ -277,6 +297,9 @@ int main(int argc, char **argv)
     }
 
     retrace::setUp();
+    if (retrace::profiling) {
+        retrace::profiler.setup(retrace::profilingCpuTimes, retrace::profilingGpuTimes, retrace::profilingPixelsDrawn);
+    }
 
     for ( ; i < argc; ++i) {
         if (!retrace::parser.open(argv[i])) {
@@ -289,7 +312,8 @@ int main(int argc, char **argv)
         retrace::parser.close();
     }
 
-    retrace::cleanUp();
+    // XXX: X often hangs on XCloseDisplay
+    //retrace::cleanUp();
 
     return 0;
 }