namespace trace {
Profiler::Profiler()
- : baseTime(0)
+ : baseGpuTime(0),
+ baseCpuTime(0),
+ cpuTimes(false),
+ gpuTimes(true),
+ pixelsDrawn(false)
{
}
{
}
-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;
}
}