X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=common%2Ftrace_profiler.cpp;h=2d12698083a5082d0ed13d94f68e59759a19a708;hb=00fa77c21097e9ef28c5091ec9b05691523aa36c;hp=02d88dcbc2d167219bca63a6f9a193b1020ed4e8;hpb=c748fbcb434374ec13e14cc837ade7c581789e0c;p=apitrace diff --git a/common/trace_profiler.cpp b/common/trace_profiler.cpp index 02d88dc..2d12698 100644 --- a/common/trace_profiler.cpp +++ b/common/trace_profiler.cpp @@ -25,6 +25,10 @@ #include "trace_profiler.hpp" #include +#include +#include +#include +#include "os_time.hpp" namespace trace { Profiler::Profiler() @@ -51,6 +55,12 @@ void Profiler::setup(bool cpuTimes_, bool gpuTimes_, bool pixelsDrawn_) std::cout << "# call no gpu_start gpu_dura cpu_start cpu_dura pixels program name" << std::endl; } +void Profiler::setBaseTimes(uint64_t gpuStart, uint64_t cpuStart) +{ + baseCpuTime = cpuStart; + baseGpuTime = gpuStart; +} + void Profiler::addCall(unsigned no, const char *name, unsigned program, @@ -58,14 +68,6 @@ void Profiler::addCall(unsigned no, uint64_t gpuStart, uint64_t gpuDuration, uint64_t cpuStart, uint64_t cpuDuration) { - if (baseGpuTime == 0) { - baseGpuTime = gpuStart; - } - - if (baseCpuTime == 0) { - baseCpuTime = cpuStart; - } - if (gpuTimes) { gpuStart -= baseGpuTime; } else { @@ -74,7 +76,9 @@ void Profiler::addCall(unsigned no, } if (cpuTimes) { - cpuStart -= baseCpuTime; + double cpuTimeScale = 1.0E9 / os::timeFrequency; + cpuStart = (cpuStart - baseCpuTime) * cpuTimeScale; + cpuDuration = cpuDuration * cpuTimeScale; } else { cpuStart = 0; cpuDuration = 0; @@ -98,32 +102,27 @@ void Profiler::addCall(unsigned no, void Profiler::addFrameStart(unsigned no, uint64_t gpuStart, uint64_t cpuStart) { - if (baseGpuTime == 0) { - baseGpuTime = gpuStart; - } - - if (baseCpuTime == 0) { - baseCpuTime = cpuStart; - } + lastFrame.no = no; + lastFrame.gpuStart = gpuStart; + lastFrame.cpuStart = cpuStart; if (gpuTimes) { - lastFrame.gpuStart = gpuStart - baseGpuTime; + gpuStart = gpuStart - baseGpuTime; } else { - lastFrame.gpuStart = 0; + gpuStart = 0; } if (cpuTimes) { - lastFrame.cpuStart = cpuStart - baseCpuTime; + double cpuTimeScale = 1.0E9 / os::timeFrequency; + cpuStart = (cpuStart - baseCpuTime) * cpuTimeScale; } else { - lastFrame.cpuStart = 0; + cpuStart = 0; } - lastFrame.no = no; - std::cout << "frame_begin" - << " " << lastFrame.no - << " " << lastFrame.gpuStart - << " " << lastFrame.cpuStart + << " " << no + << " " << gpuStart + << " " << cpuStart << std::endl; } @@ -132,16 +131,17 @@ void Profiler::addFrameEnd(uint64_t gpuEnd, uint64_t cpuEnd) uint64_t gpuDuration, cpuDuration; if (gpuTimes) { - gpuEnd -= baseGpuTime; gpuDuration = gpuEnd - lastFrame.gpuStart; + gpuEnd = gpuEnd - baseGpuTime; } else { gpuEnd = 0; gpuDuration = 0; } if (cpuTimes) { - cpuEnd -= baseCpuTime; - cpuDuration = cpuEnd - lastFrame.cpuStart; + double cpuTimeScale = 1.0E9 / os::timeFrequency; + cpuDuration = (cpuEnd - lastFrame.cpuStart) * cpuTimeScale; + cpuEnd = (cpuEnd - baseCpuTime) * cpuTimeScale; } else { cpuEnd = 0; cpuDuration = 0; @@ -155,4 +155,51 @@ void Profiler::addFrameEnd(uint64_t gpuEnd, uint64_t 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; + + line >> frame.no + >> skipi64 + >> frame.gpuDuration + >> skipi64 + >> frame.cpuDuration; + } +} }