X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=common%2Ftrace_profiler.cpp;h=02d88dcbc2d167219bca63a6f9a193b1020ed4e8;hb=c748fbcb434374ec13e14cc837ade7c581789e0c;hp=fdc0fd4a2f748c170c464bbd7af12e6852d4f68b;hpb=addf7f90727a50040d79e6da6d59ffb031074674;p=apitrace diff --git a/common/trace_profiler.cpp b/common/trace_profiler.cpp index fdc0fd4..02d88dc 100644 --- a/common/trace_profiler.cpp +++ b/common/trace_profiler.cpp @@ -28,7 +28,11 @@ namespace trace { Profiler::Profiler() - : baseTime(0) + : baseGpuTime(0), + baseCpuTime(0), + cpuTimes(false), + gpuTimes(true), + pixelsDrawn(false) { } @@ -36,26 +40,119 @@ Profiler::~Profiler() { } -void Profiler::addCall(const Call& call) +void Profiler::setup(bool cpuTimes_, bool gpuTimes_, bool pixelsDrawn_) { - if (baseTime == 0) - baseTime = call.gpu.start; - - std::cout << "call " - << call.no << " " - << (call.gpu.start - baseTime) << " " - << call.gpu.duration << " " - << call.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::addCall(unsigned no, + const char *name, + unsigned program, + uint64_t pixels, + 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 { + 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::addFrame(const Frame& frame) +void Profiler::addFrameStart(unsigned no, uint64_t gpuStart, uint64_t cpuStart) { - if (baseTime == 0) - baseTime = frame.gpu.start; + 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; + + std::cout << "frame_begin" + << " " << lastFrame.no + << " " << lastFrame.gpuStart + << " " << lastFrame.cpuStart + << std::endl; +} + +void Profiler::addFrameEnd(uint64_t gpuEnd, uint64_t cpuEnd) +{ + uint64_t gpuDuration, cpuDuration; + + if (gpuTimes) { + gpuEnd -= baseGpuTime; + gpuDuration = gpuEnd - lastFrame.gpuStart; + } else { + gpuEnd = 0; + gpuDuration = 0; + } + + if (cpuTimes) { + cpuEnd -= baseCpuTime; + cpuDuration = cpuEnd - lastFrame.cpuStart; + } else { + cpuEnd = 0; + cpuDuration = 0; + } - std::cout << "frame " - << frame.no << " " - << (frame.gpu.start - baseTime) << " " - << frame.gpu.duration << std::endl; + std::cout << "frame_end" + << " " << lastFrame.no + << " " << gpuEnd + << " " << gpuDuration + << " " << cpuEnd + << " " << cpuDuration + << std::endl; } }