]> git.cworth.org Git - apitrace/blobdiff - common/trace_profiler.cpp
Cleaned up trace profiler output.
[apitrace] / common / trace_profiler.cpp
index fd684ede7bf16d623b7b54b9f80e67477aaf8bc8..02d88dcbc2d167219bca63a6f9a193b1020ed4e8 100644 (file)
 
 namespace trace {
 Profiler::Profiler()
-    : baseTime(0)
+    : baseGpuTime(0),
+      baseCpuTime(0),
+      cpuTimes(false),
+      gpuTimes(true),
+      pixelsDrawn(false)
 {
 }
 
@@ -36,41 +40,119 @@ Profiler::~Profiler()
 {
 }
 
-void Profiler::addCall(unsigned no, const char *name, uint64_t gpu_start, uint64_t gpu_duration)
+void Profiler::setup(bool cpuTimes_, bool gpuTimes_, bool pixelsDrawn_)
 {
-    if (baseTime == 0)
-        baseTime = gpu_start;
-
-    std::cout << "call "
-              << no << " "
-              << (gpu_start - baseTime) << " "
-              << gpu_duration << " "
-              << name << std::endl;
+    cpuTimes = cpuTimes_;
+    gpuTimes = gpuTimes_;
+    pixelsDrawn = pixelsDrawn_;
+
+    std::cout << "# frame_begin no gpu_start cpu_start" << std::endl;
+    std::cout << "# frame_end no gpu_end gpu_dura cpu_end cpu_dura" << std::endl;
+    std::cout << "# call no gpu_start gpu_dura cpu_start cpu_dura pixels program name" << std::endl;
 }
 
-void Profiler::addFrameStart(unsigned no, uint64_t timestamp)
+void Profiler::addCall(unsigned no,
+                       const char *name,
+                       unsigned program,
+                       uint64_t pixels,
+                       uint64_t gpuStart, uint64_t gpuDuration,
+                       uint64_t cpuStart, uint64_t cpuDuration)
 {
-    if (baseTime == 0)
-        baseTime = timestamp;
+    if (baseGpuTime == 0) {
+        baseGpuTime = gpuStart;
+    }
+
+    if (baseCpuTime == 0) {
+        baseCpuTime = cpuStart;
+    }
+
+    if (gpuTimes) {
+        gpuStart -= baseGpuTime;
+    } else {
+        gpuStart = 0;
+        gpuDuration = 0;
+    }
+
+    if (cpuTimes) {
+        cpuStart -= baseCpuTime;
+    } else {
+        cpuStart = 0;
+        cpuDuration = 0;
+    }
+
+    if (!pixelsDrawn) {
+        pixels = 0;
+    }
+
+    std::cout << "call"
+              << " " << no
+              << " " << gpuStart
+              << " " << gpuDuration
+              << " " << cpuStart
+              << " " << cpuDuration
+              << " " << pixels
+              << " " << program
+              << " " << name
+              << std::endl;
+}
+
+void Profiler::addFrameStart(unsigned no, uint64_t gpuStart, uint64_t cpuStart)
+{
+    if (baseGpuTime == 0) {
+        baseGpuTime = gpuStart;
+    }
+
+    if (baseCpuTime == 0) {
+        baseCpuTime = cpuStart;
+    }
+
+    if (gpuTimes) {
+        lastFrame.gpuStart = gpuStart - baseGpuTime;
+    } else {
+        lastFrame.gpuStart = 0;
+    }
+
+    if (cpuTimes) {
+        lastFrame.cpuStart = cpuStart - baseCpuTime;
+    } else {
+        lastFrame.cpuStart = 0;
+    }
 
     lastFrame.no = no;
-    lastFrame.start = timestamp - baseTime;
 
-    std::cout << "frame begin "
-              << lastFrame.no << " "
-              << lastFrame.start << std::endl;
+    std::cout << "frame_begin"
+              << " " << lastFrame.no
+              << " " << lastFrame.gpuStart
+              << " " << lastFrame.cpuStart
+              << std::endl;
 }
 
-void Profiler::addFrameEnd(uint64_t timestamp)
+void Profiler::addFrameEnd(uint64_t gpuEnd, uint64_t cpuEnd)
 {
-    if (baseTime == 0)
-        baseTime = timestamp;
+    uint64_t gpuDuration, cpuDuration;
+
+    if (gpuTimes) {
+        gpuEnd -= baseGpuTime;
+        gpuDuration = gpuEnd - lastFrame.gpuStart;
+    } else {
+        gpuEnd = 0;
+        gpuDuration = 0;
+    }
 
-    lastFrame.end = timestamp - baseTime;
+    if (cpuTimes) {
+        cpuEnd -= baseCpuTime;
+        cpuDuration = cpuEnd - lastFrame.cpuStart;
+    } else {
+        cpuEnd = 0;
+        cpuDuration = 0;
+    }
 
-    std::cout << "frame end "
-              << lastFrame.no << " "
-              << lastFrame.end << " "
-              << (lastFrame.end - lastFrame.start) << std::endl;
+    std::cout << "frame_end"
+              << " " << lastFrame.no
+              << " " << gpuEnd
+              << " " << gpuDuration
+              << " " << cpuEnd
+              << " " << cpuDuration
+              << std::endl;
 }
 }