SleakEngine
0.1.0
C++23 multi-backend game engine
Toggle main menu visibility
Loading...
Searching...
No Matches
Benchmark.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include <
Core/OSDef.hpp
>
4
#include <
Core/Timer.hpp
>
5
#include <string>
6
#include <vector>
7
#include <functional>
8
#include <fstream>
9
10
namespace
Sleak
{
11
12
namespace
RenderEngine
{
class
Renderer
; }
13
14
/// A custom metric that the game module (or anyone) can register.
15
/// @ingroup debug
16
struct
BenchmarkMetric
{
17
std::string
Name
;
18
std::function<float()>
Getter
;
19
};
20
21
/// Records per-frame performance data to a CSV session file while recording is active.
22
/// @ingroup debug
23
class
ENGINE_API
Benchmark
{
24
public
:
25
Benchmark
() =
default
;
26
~Benchmark
();
27
28
void
Initialize
(
RenderEngine::Renderer
* renderer);
29
30
/// Register a custom metric (e.g. render distance from Game).
31
void
RegisterMetric
(
const
std::string& name, std::function<
float
()> getter);
32
void
UnregisterMetric
(
const
std::string& name);
33
34
/// Call once per frame from the main loop.
35
void
Tick
(
float
deltaTime);
36
37
/// Toggle recording on/off (F12).
38
void
ToggleRecording
();
39
bool
IsRecording
()
const
{
return
m_recording; }
40
41
private
:
42
void
StartRecording();
43
void
StopRecording();
44
void
WriteFrameData(
float
deltaTime);
45
void
WriteSummary();
46
void
WriteHardwareInfo();
47
48
std::string GetRendererTag()
const
;
49
std::string GenerateFilename()
const
;
50
51
RenderEngine::Renderer
* m_renderer =
nullptr
;
52
bool
m_recording =
false
;
53
54
std::ofstream m_file;
55
int
m_frameIndex = 0;
56
Timer
m_sessionTimer;
57
58
std::vector<BenchmarkMetric> m_customMetrics;
59
60
// Per-session accumulators
61
int
m_minFPS = 0;
62
int
m_maxFPS = 0;
63
double
m_sumFPS = 0.0;
64
float
m_minFrameTime = 0.0f;
65
float
m_maxFrameTime = 0.0f;
66
double
m_sumFrameTime = 0.0;
67
double
m_sumTriangles = 0.0;
68
double
m_sumCPU = 0.0;
69
double
m_sumRAM = 0.0;
70
71
// Stutter/spike counters
72
int
m_spikes16 = 0;
// frames > 16.67ms (below 60 FPS)
73
int
m_spikes33 = 0;
// frames > 33.33ms (below 30 FPS)
74
int
m_spikes50 = 0;
// frames > 50ms (below 20 FPS)
75
76
std::vector<float> m_frameTimes;
// all frame times for percentile calculation
77
std::vector<double> m_customSums;
78
};
79
80
}
// namespace Sleak
OSDef.hpp
Timer.hpp
Sleak::Benchmark::ToggleRecording
void ToggleRecording()
Toggle recording on/off (F12).
Definition
Benchmark.cpp:55
Sleak::Benchmark::RegisterMetric
void RegisterMetric(const std::string &name, std::function< float()> getter)
Register a custom metric (e.g. render distance from Game).
Definition
Benchmark.cpp:33
Sleak::Benchmark::Initialize
void Initialize(RenderEngine::Renderer *renderer)
Definition
Benchmark.cpp:29
Sleak::Benchmark::UnregisterMetric
void UnregisterMetric(const std::string &name)
Definition
Benchmark.cpp:43
Sleak::Benchmark::Benchmark
Benchmark()=default
Sleak::Benchmark::IsRecording
bool IsRecording() const
Definition
Benchmark.hpp:39
Sleak::Benchmark::Tick
void Tick(float deltaTime)
Call once per frame from the main loop.
Definition
Benchmark.cpp:50
Sleak::RenderEngine::Renderer
Abstract render backend: swapchain, frame lifecycle, and post-effect toggles.
Definition
Renderer.hpp:37
Sleak::Timer
Definition
Timer.hpp:10
Sleak::RenderEngine
Backend-facing rendering layer shared by the four graphics backends.
Definition
Application.hpp:60
Sleak
Root namespace for everything the engine exposes.
Definition
Camera.hpp:10
Sleak::BenchmarkMetric
Definition
Benchmark.hpp:16
Sleak::BenchmarkMetric::Name
std::string Name
Definition
Benchmark.hpp:17
Sleak::BenchmarkMetric::Getter
std::function< float()> Getter
Definition
Benchmark.hpp:18
include
public
Debug
Benchmark.hpp
Generated on
for SleakEngine by
1.18.0