+ baseCpuTime = cpuStart;
+ baseGpuTime = gpuStart;
+}
+
+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 (gpuTimes) {
+ gpuStart -= baseGpuTime;
+ } else {
+ gpuStart = 0;
+ gpuDuration = 0;
+ }
+
+ if (cpuTimes) {
+ double cpuTimeScale = 1.0E9 / os::timeFrequency;
+ cpuStart = (cpuStart - baseCpuTime) * cpuTimeScale;
+ cpuDuration = cpuDuration * cpuTimeScale;
+ } 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)
+{
+ lastFrame.no = no;
+ lastFrame.gpuStart = gpuStart;
+ lastFrame.cpuStart = cpuStart;
+
+ if (gpuTimes) {
+ gpuStart = gpuStart - baseGpuTime;
+ } else {
+ gpuStart = 0;
+ }
+
+ if (cpuTimes) {
+ double cpuTimeScale = 1.0E9 / os::timeFrequency;
+ cpuStart = (cpuStart - baseCpuTime) * cpuTimeScale;
+ } else {
+ cpuStart = 0;
+ }
+
+ std::cout << "frame_begin"
+ << " " << no
+ << " " << gpuStart
+ << " " << cpuStart
+ << std::endl;
+}
+
+void Profiler::addFrameEnd(uint64_t gpuEnd, uint64_t cpuEnd)
+{
+ uint64_t gpuDuration, cpuDuration;
+
+ if (gpuTimes) {
+ gpuDuration = gpuEnd - lastFrame.gpuStart;
+ gpuEnd = gpuEnd - baseGpuTime;
+ } else {
+ gpuEnd = 0;
+ gpuDuration = 0;
+ }
+
+ if (cpuTimes) {
+ double cpuTimeScale = 1.0E9 / os::timeFrequency;
+ cpuDuration = (cpuEnd - lastFrame.cpuStart) * cpuTimeScale;
+ cpuEnd = (cpuEnd - baseCpuTime) * cpuTimeScale;
+ } else {
+ cpuEnd = 0;
+ cpuDuration = 0;
+ }
+
+ std::cout << "frame_end"
+ << " " << lastFrame.no
+ << " " << gpuEnd
+ << " " << gpuDuration
+ << " " << 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;