summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorJames Benton <jbenton@vmware.com>2012-08-08 17:09:07 +0100
committerJames Benton <jbenton@vmware.com>2012-08-08 17:11:23 +0100
commitfc4f55a3193269f86c142219f5593dd8b8e9b3c8 (patch)
treeb887c7d858d625f1746a1d71553f8dd7a1c2fd75 /common
parentb7634e4d276c25160a6df53dcedf422c2a01b037 (diff)
Add gui support for trace profiling.
Diffstat (limited to 'common')
-rw-r--r--common/trace_profiler.cpp33
-rw-r--r--common/trace_profiler.hpp35
2 files changed, 68 insertions, 0 deletions
diff --git a/common/trace_profiler.cpp b/common/trace_profiler.cpp
index 02d88dcb..8a3b137b 100644
--- a/common/trace_profiler.cpp
+++ b/common/trace_profiler.cpp
@@ -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);
+ }
+}
}
diff --git a/common/trace_profiler.hpp b/common/trace_profiler.hpp
index c36fd77f..c8b38b9a 100644
--- a/common/trace_profiler.hpp
+++ b/common/trace_profiler.hpp
@@ -27,10 +27,43 @@
#define TRACE_PROFILER_H
#include <string>
+#include <vector>
#include <stdint.h>
namespace trace
{
+
+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;
+
+ typedef std::vector<Call>::iterator iterator;
+ typedef std::vector<Call>::const_iterator const_iterator;
+ };
+
+ struct Frame {
+ unsigned no;
+ int64_t gpuStart;
+ int64_t gpuDuration;
+ int64_t cpuStart;
+ int64_t cpuDuration;
+
+ std::vector<Call> calls;
+
+ typedef std::vector<Frame>::iterator iterator;
+ typedef std::vector<Frame>::const_iterator const_iterator;
+ };
+
+ std::vector<Frame> frames;
+};
+
class Profiler
{
public:
@@ -49,6 +82,8 @@ public:
uint64_t gpuStart, uint64_t gpuDuration,
uint64_t cpuStart, uint64_t cpuDuration);
+ static void parseLine(const char* line, Profile* profile);
+
private:
uint64_t baseGpuTime;
uint64_t baseCpuTime;