]> git.cworth.org Git - apitrace/blobdiff - common/trace_profiler.cpp
Add gui support for trace profiling.
[apitrace] / common / trace_profiler.cpp
index 02d88dcbc2d167219bca63a6f9a193b1020ed4e8..8a3b137bbbe8d94bb32a8dd3b0f943af3b6d1274 100644 (file)
@@ -25,6 +25,9 @@
 
 #include "trace_profiler.hpp"
 #include <iostream>
+#include <string.h>
+#include <assert.h>
+#include <stdio.h>
 
 namespace trace {
 Profiler::Profiler()
@@ -155,4 +158,34 @@ void Profiler::addFrameEnd(uint64_t gpuEnd, uint64_t cpuEnd)
               << " " << cpuDuration
               << std::endl;
 }
+
+void Profiler::parseLine(const char* line, Profile* profile)
+{
+    char name[64];
+
+    if (line[0] == '#' || strlen(line) < 12)
+        return;
+
+    if (strncmp(line, "call ", 5) == 0) {
+        assert(profile->frames.size());
+
+        Profile::Call call;
+        sscanf(line, "call %u %li %li %li %li %li %u %s", &call.no, &call.gpuStart, &call.gpuDuration, &call.cpuStart, &call.cpuDuration, &call.pixels, &call.program, name);
+        call.name = name;
+        profile->frames.back().calls.push_back(call);
+    } else if (strncmp(line, "frame_begin ", 12) == 0) {
+        Profile::Frame frame;
+        frame.gpuDuration = 0;
+        frame.gpuDuration = 0;
+        sscanf(line, "frame_begin %u %li %li", &frame.no, &frame.gpuStart, &frame.cpuStart);
+        profile->frames.push_back(frame);
+    } else if (strncmp(line, "frame_end ", 10) == 0) {
+        assert(profile->frames.size());
+
+        Profile::Frame& frame = profile->frames.back();
+        unsigned no;
+        sscanf(line, "frame_end %u %*li %li %*li %li", &no, &frame.gpuDuration, &frame.cpuDuration);
+        assert(no == frame.no);
+    }
+}
 }