[PATCH 6/6] Terminate retrace early if capturing snapshots

Dan McCabe zen3d.linux at gmail.com
Fri Jun 1 13:40:07 PDT 2012


When taking snapshots, terminate retrace early if the last snapshot
has been captured.

In order to do this, the maximum entry of a call set needs to be determined
as well.

Note that when capturing snapshots, we also need to inhibit a state dump
because this confuses qapitrace.
---
 common/trace_callset.hpp |   16 ++++++++++++++++
 retrace/retrace_main.cpp |   13 +++++++++++--
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/common/trace_callset.hpp b/common/trace_callset.hpp
index b679d94..82f6132 100644
--- a/common/trace_callset.hpp
+++ b/common/trace_callset.hpp
@@ -155,6 +155,22 @@ namespace trace {
         contains(const trace::Call &call) {
             return contains(call.no, call.flags);
         }
+
+        inline CallNo
+        max() const {
+            CallNo max = 0;
+
+            if (!empty()) {
+                RangeList::const_iterator it;
+                for (it = ranges.begin(); it != ranges.end(); ++it) {
+                    if (max < it->stop) {
+                        max = it->stop;
+                    }
+                }
+            }
+
+            return max;
+        }
     };
 
 
diff --git a/retrace/retrace_main.cpp b/retrace/retrace_main.cpp
index f7fb711..463a070 100644
--- a/retrace/retrace_main.cpp
+++ b/retrace/retrace_main.cpp
@@ -128,6 +128,15 @@ mainLoop() {
     startTime = os::getTime();
     trace::Call *call;
 
+    unsigned lastCallNo = ~0;
+
+    if (!snapshotFrequency.empty()) {
+        lastCallNo = snapshotFrequency.max();
+    }
+    if (dumpStateCallNo < lastCallNo) {
+        lastCallNo = dumpStateCallNo;
+    }
+
     while ((call = retrace::parser.parse_call())) {
         bool swapRenderTarget = call->flags & trace::CALL_FLAG_SWAP_RENDERTARGET;
         bool doSnapshot =
@@ -155,8 +164,8 @@ mainLoop() {
             takeSnapshot(call->no);
         }
 
-        if (call->no >= dumpStateCallNo &&
-            dumpState(std::cout)) {
+        if (call->no >= lastCallNo  &&
+           (doSnapshot || dumpState(std::cout))) {
             exit(0);
         }
 
-- 
1.7.9.1



More information about the apitrace mailing list