PerformanceInfo improvements

This commit is contained in:
Vladyslav Baranovskyi
2024-06-13 22:53:38 +03:00
parent bad6c95c3f
commit b5df2edab5
2 changed files with 39 additions and 36 deletions

View File

@@ -18,42 +18,45 @@ namespace OpenVulkano::Scene::UI
{ {
namespace namespace
{ {
float FrameCollectionValuesGetter(void *data, int index) float FloatCollectionValuesGetter(void *data, int index)
{ {
auto frameCollection = reinterpret_cast<FrameTimeCollection *>(data); auto collection = static_cast<FloatCollection *>(data);
float value = frameCollection->m_frameTimes[index]; float value = collection->m_values[index];
float result = value / frameCollection->m_maxValue * 100; float result = value / collection->m_maxValue * 100;
return result; return result;
} }
float RamValuesGetter(void *data, int index)
{
auto queue = reinterpret_cast<std::deque<float> *>(data);
float used = (*queue)[index];
float max = SystemInfo::GetAppRamMax();
float percentage = used / max * 100;
return percentage;
}
} }
void PerformanceInfo::UpdateQueues() void PerformanceInfo::UpdateQueues()
{ {
m_frameCollection.m_frameTimes.push_back(static_cast<float>(CURRENT_FRAME.frameTime)); float newFrameTime = static_cast<float>(CURRENT_FRAME.frameTime);
while(m_frameCollection.m_frameTimes.size() > m_windowSize) if(newFrameTime > m_frames.m_maxValue)
m_frameCollection.m_frameTimes.pop_front(); m_frames.m_maxValue = newFrameTime;
float maxFrameTime = FLT_MIN; m_frames.m_values.push_back(newFrameTime);
for(auto value : m_frameCollection.m_frameTimes)
while(m_frames.m_values.size() > m_windowSize)
{ {
if(value > maxFrameTime) float poppedFrameTime = m_frames.m_values.front();
maxFrameTime = value; m_frames.m_values.pop_front();
if(m_frames.m_maxValue == poppedFrameTime)
{
m_frames.m_maxValue = FLT_MIN;
for(auto value : m_frames.m_values)
{
if(value > m_frames.m_maxValue)
m_frames.m_maxValue = value;
}
}
} }
m_frameCollection.m_maxValue = maxFrameTime;
m_ramUsed.push_back(static_cast<float>(SystemInfo::GetAppRamUsed())); m_ramUsed.m_values.push_back(static_cast<float>(SystemInfo::GetAppRamUsed()));
while(m_ramUsed.size() > m_windowSize) while(m_ramUsed.m_values.size() > m_windowSize)
m_ramUsed.pop_front(); m_ramUsed.m_values.pop_front();
m_ramUsed.m_maxValue = SystemInfo::GetAppRamMax();
assert(m_ramUsed.m_values.size() <= m_windowSize);
} }
void PerformanceInfo::BeginDraw() void PerformanceInfo::BeginDraw()
@@ -65,20 +68,20 @@ namespace OpenVulkano::Scene::UI
void PerformanceInfo::Draw() void PerformanceInfo::Draw()
{ {
UpdateQueues(); UpdateQueues();
assert(m_frameCollection.m_frameTimes.size() == m_ramUsed.size()); assert(m_frames.m_values.size() == m_ramUsed.m_values.size());
ImGui::Text("Last Frame Time(wrt max): %f s", m_frameCollection.m_frameTimes.back()); ImGui::Text("Last Frame Time: %f s", m_frames.m_values.back());
ImGui::Text("Last FPS: %f", 1 / m_frameCollection.m_frameTimes.back()); ImGui::Text("Last FPS: %f", 1 / m_frames.m_values.back());
ImGui::TextFmt("RAM: {} / {}, Free: {}", ByteSize(m_ramUsed.m_values.back()), ByteSize(SystemInfo::GetAppRamMax()), ByteSize(SystemInfo::GetAppRamAvailable()));
ImGui::SliderInt("Window Size", &m_windowSize, 10, 1000); ImGui::SliderInt("Window Size", &m_windowSize, 10, 1000);
ImGui::TextFmt("RAM: {} / {}, Free: {}", ByteSize(m_ramUsed.back()), ByteSize(SystemInfo::GetAppRamMax()), ByteSize(SystemInfo::GetAppRamAvailable()));
ImVec2 availableSize = ImGui::GetContentRegionAvail(); ImVec2 availableSize = ImGui::GetContentRegionAvail();
float scaleMin = 0.01; float scaleMin = 0.01;
float scaleMax = 100; float scaleMax = 100;
ImGui::PlotTwoLines("", ImGui::PlotTwoLines("",
&FrameCollectionValuesGetter, &m_frameCollection, "Frame Time", &FloatCollectionValuesGetter, &m_frames, "Frame Time(wrt max)",
&RamValuesGetter, &m_ramUsed, "RAM", &FloatCollectionValuesGetter, &m_ramUsed, "RAM",
(int)m_ramUsed.size(), (int)m_ramUsed.m_values.size(),
scaleMin, scaleMax, availableSize); scaleMin, scaleMax, availableSize);
} }

View File

@@ -12,17 +12,17 @@
namespace OpenVulkano::Scene::UI namespace OpenVulkano::Scene::UI
{ {
struct FrameTimeCollection struct FloatCollection
{ {
std::deque<float> m_frameTimes; std::deque<float> m_values;
float m_maxValue; float m_maxValue;
}; };
class PerformanceInfo : public UiElement class PerformanceInfo : public UiElement
{ {
int m_windowSize = 200; int m_windowSize = 200;
std::deque<float> m_ramUsed; FloatCollection m_ramUsed;
FrameTimeCollection m_frameCollection; FloatCollection m_frames;
void UpdateQueues(); void UpdateQueues();