hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/src/ui/profiler.h
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2025-09-26 16:58:48 +0200
committerhachem <im@hachem.wtf>2025-09-26 16:58:48 +0200
commit7e53abd75355caa817532c71a935b6a231b3cd9e (patch)
tree61538f78ffa156bea4a85163eb604b4553856424 /src/ui/profiler.h
parent049e7e2aa15debb1ed112494681d7b3e28765679 (diff)
feat: attempt to add a profiler...didn't work
Diffstat (limited to 'src/ui/profiler.h')
-rw-r--r--src/ui/profiler.h52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/ui/profiler.h b/src/ui/profiler.h
new file mode 100644
index 0000000..587b7ca
--- /dev/null
+++ b/src/ui/profiler.h
@@ -0,0 +1,52 @@
+#pragma once
+
+#include <array>
+#include <cstdint>
+
+namespace Hsdbg
+{
+ class TimeSeries
+ {
+ public:
+ static constexpr int CAPACITY = 240;
+
+ auto push(float value) -> void;
+ auto clear() -> void;
+
+ auto values() const -> const float* { return m_values.data(); }
+ auto count() const -> int { return m_count; }
+
+ auto offset() const -> int { return m_count == CAPACITY ? m_write : 0; }
+
+ auto latest() const -> float;
+ auto average() const -> float;
+ auto maximum() const -> float;
+
+ private:
+ std::array<float, CAPACITY> m_values{};
+ int m_count = 0;
+ int m_write = 0;
+ };
+
+ class Profiler
+ {
+ public:
+ auto sample_frame(float delta_seconds) -> void;
+
+ auto sample_target(uint64_t resident_bytes, bool alive) -> void;
+ auto reset() -> void;
+
+ auto frame_times() const -> const TimeSeries& { return m_frame_ms; }
+ auto frame_rates() const -> const TimeSeries& { return m_fps; }
+ auto target_memory_mb() const -> const TimeSeries& { return m_target_memory_mb; }
+
+ auto paused() const -> bool { return m_paused; }
+ auto set_paused(bool paused) -> void { m_paused = paused; }
+
+ private:
+ TimeSeries m_frame_ms;
+ TimeSeries m_fps;
+ TimeSeries m_target_memory_mb;
+ bool m_paused = false;
+ };
+}