From 7e53abd75355caa817532c71a935b6a231b3cd9e Mon Sep 17 00:00:00 2001 From: hachem Date: Fri, 26 Sep 2025 16:58:48 +0200 Subject: feat: attempt to add a profiler...didn't work --- src/ui/profiler.h | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/ui/profiler.h (limited to 'src/ui/profiler.h') 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 +#include + +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 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; + }; +} -- cgit v1.3