-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathprofiler.cpp
More file actions
33 lines (28 loc) · 943 Bytes
/
profiler.cpp
File metadata and controls
33 lines (28 loc) · 943 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "profiler.hpp"
#include <cstdio>
profiler::profiler(const std::string& name) : name(name)
{
}
profiler::~profiler()
{
const auto frequency = SDL_GetPerformanceFrequency();
const auto duration = static_cast<double>(performanceCounter) / static_cast<double>(frequency);
const auto average = runCounter ? 1000.0 * duration / static_cast<double>(runCounter) : 0.0f;
const auto longestMillis = 1000 * longest / frequency;
printf("[%s] Duration %f s, run counter %" SDL_PRIu64 ", average %f ms, longest %" SDL_PRIu64 " ms\n",
name.c_str(), duration, runCounter, average, longestMillis);
}
void profiler::start()
{
started = SDL_GetPerformanceCounter();
}
void profiler::stop()
{
const auto finished = SDL_GetPerformanceCounter();
const auto duration = finished - started;
performanceCounter += duration;
runCounter++;
if (duration > longest) {
longest = duration;
}
}