]> git.cworth.org Git - apitrace/blobdiff - common/trace_profiler.cpp
Changed profile parsing to use stringstream instead of sscanf.
[apitrace] / common / trace_profiler.cpp
index 02d88dcbc2d167219bca63a6f9a193b1020ed4e8..225e04203389ac42fa3f1eec91c08549680b21d7 100644 (file)
@@ -25,6 +25,9 @@
 
 #include "trace_profiler.hpp"
 #include <iostream>
+#include <string.h>
+#include <assert.h>
+#include <sstream>
 
 namespace trace {
 Profiler::Profiler()
@@ -155,4 +158,51 @@ void Profiler::addFrameEnd(uint64_t gpuEnd, uint64_t cpuEnd)
               << " " << cpuDuration
               << std::endl;
 }
+
+void Profiler::parseLine(const char* in, Profile* profile)
+{
+    std::stringstream line(in, std::ios_base::in);
+    std::string type;
+
+    if (in[0] == '#' || strlen(in) < 12)
+        return;
+
+    line >> type;
+
+    if (type.compare("call") == 0) {
+        assert(profile->frames.size());
+        Profile::Call call;
+
+        line >> call.no
+             >> call.gpuStart
+             >> call.gpuDuration
+             >> call.cpuStart
+             >> call.cpuDuration
+             >> call.pixels
+             >> call.program
+             >> call.name;
+
+        profile->frames.back().calls.push_back(call);
+    } else if (type.compare("frame_begin") == 0) {
+        Profile::Frame frame;
+        frame.gpuDuration = 0;
+        frame.cpuDuration = 0;
+
+        line >> frame.no
+             >> frame.gpuStart
+             >> frame.cpuStart;
+
+        profile->frames.push_back(frame);
+    } else if (type.compare("frame_end") == 0) {
+        assert(profile->frames.size());
+        Profile::Frame& frame = profile->frames.back();
+        int64_t skipi64;
+
+        line >> frame.no
+             >> skipi64
+             >> frame.gpuDuration
+             >> skipi64
+             >> frame.cpuDuration;
+    }
+}
 }