hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/src/ui/profiler.h
blob: d951af8fd63a32f1e921a9571b10f0c2d9807e6e (plain)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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 value) -> void { m_paused = value; }

    private:
        TimeSeries m_frame_ms;
        TimeSeries m_fps;
        TimeSeries m_target_memory_mb;
        bool m_paused = false;
    };
}