]> git.cworth.org Git - apitrace/blobdiff - common/trace_profiler.hpp
CPU Profiling now includes all OpenGL calls (was only draw calls).
[apitrace] / common / trace_profiler.hpp
index 19a874f9b4fb4199c538d11aff68a161f84f12f3..dc3c4be0b0e9bafc868360366cf00f366132c9b3 100644 (file)
 #define TRACE_PROFILER_H
 
 #include <string>
+#include <vector>
 #include <stdint.h>
 
 namespace trace
 {
-class Profiler
-{
-public:
-    struct GpuTime
-    {
-        GpuTime()
-            : start(0), duration(0)
-        {
-        }
-
-        GpuTime(uint64_t start_, uint64_t duration_)
-            : start(start_), duration(duration_)
-        {
-        }
-
-        uint64_t start;
-        uint64_t duration;
-    };
-
-    struct Call
-    {
-        Call()
-            : no(0)
-        {
-        }
-
-        Call(unsigned no_, const char* name_, uint64_t gpu_start, uint64_t gpu_duration)
-            : no(no_), name(name_), gpu(gpu_start, gpu_duration)
-        {
-        }
 
+struct Profile {
+    struct Call {
         unsigned no;
+        int64_t gpuStart;
+        int64_t gpuDuration;
+        int64_t cpuStart;
+        int64_t cpuDuration;
+        int64_t pixels;
+        unsigned program;
         std::string name;
 
-        GpuTime gpu;
+        typedef std::vector<Call>::iterator iterator;
+        typedef std::vector<Call>::const_iterator const_iterator;
     };
 
-    struct Frame
-    {
-        Frame()
-            : no(0)
-        {
-        }
+    struct Frame {
+        unsigned no;
+        int64_t gpuStart;
+        int64_t gpuDuration;
+        int64_t cpuStart;
+        int64_t cpuDuration;
 
-        Frame(unsigned no_, uint64_t gpu_start, uint64_t gpu_duration)
-            : no(no_), gpu(gpu_start, gpu_duration)
-        {
-        }
+        std::vector<Call> calls;
 
-        unsigned no;
-        GpuTime gpu;
+        typedef std::vector<Frame>::iterator iterator;
+        typedef std::vector<Frame>::const_iterator const_iterator;
     };
 
+    std::vector<Frame> frames;
+};
+
+class Profiler
+{
 public:
     Profiler();
     ~Profiler();
 
-    void addCall(const Call& call);
-    void addFrame(const Frame& frame);
+    void setup(bool cpuTimes_, bool gpuTimes_, bool pixelsDrawn_);
+    void setBaseTimes(int64_t gpuStart, int64_t cpuStart);
+    bool hasBaseTimes();
+
+    void addFrameStart(unsigned no, int64_t gpuStart, int64_t cpuStart);
+    void addFrameEnd(int64_t gpuEnd, int64_t cpuEnd);
+
+    void addCall(unsigned no,
+                 const char* name,
+                 unsigned program,
+                 int64_t pixels,
+                 int64_t gpuStart, int64_t gpuDuration,
+                 int64_t cpuStart, int64_t cpuDuration);
+
+    static void parseLine(const char* line, Profile* profile);
 
 private:
-    uint64_t baseTime;
+    int64_t baseGpuTime;
+    int64_t baseCpuTime;
+
+    bool cpuTimes;
+    bool gpuTimes;
+    bool pixelsDrawn;
+
+    struct {
+        unsigned no;
+        int64_t gpuStart;
+        int64_t cpuStart;
+    } lastFrame;
 };
 }