blob: b91770417e1da165b8b3701d0339176cf543af7d (
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
#include "ui/profiler.h"
#include <numeric>
namespace Hsdbg
{
auto TimeSeries::push(float value) -> void
{
m_values[m_write] = value;
m_write = (m_write + 1) % CAPACITY;
if (m_count < CAPACITY)
m_count += 1;
}
auto TimeSeries::clear() -> void
{
m_values.fill(0.0f);
m_count = 0;
m_write = 0;
}
auto TimeSeries::latest() const -> float
{
if (m_count == 0)
return 0.0f;
const int last = (m_write - 1 + CAPACITY) % CAPACITY;
return m_values[last];
}
auto TimeSeries::average() const -> float
{
if (m_count == 0)
return 0.0f;
const float sum = std::accumulate(m_values.begin(), m_values.begin() + m_count, 0.0f);
return sum / static_cast<float>(m_count);
}
auto TimeSeries::maximum() const -> float
{
float peak = 0.0f;
for (int i = 0; i < m_count; ++i)
{
if (m_values[i] > peak)
peak = m_values[i];
}
return peak;
}
auto Profiler::sample_frame(float delta_seconds) -> void
{
if (m_paused)
return;
const float frame_ms = delta_seconds * 1000.0f;
m_frame_ms.push(frame_ms);
m_fps.push(delta_seconds > 0.0f ? 1.0f / delta_seconds : 0.0f);
}
auto Profiler::sample_target(uint64_t resident_bytes, bool alive) -> void
{
if (m_paused)
return;
const float megabytes = alive
? static_cast<float>(resident_bytes) / (1024.0f * 1024.0f)
: 0.0f;
m_target_memory_mb.push(megabytes);
}
auto Profiler::reset() -> void
{
m_frame_ms.clear();
m_fps.clear();
m_target_memory_mb.clear();
}
}
|