/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ #include "PerformanceInfo.hpp" #include "Base/FrameMetadata.hpp" #include "Base/Utils.hpp" #include "Host/SystemInfo.hpp" #include "Math/ByteSize.hpp" #include "ImGuiExtensions/ImGuiTextFmt.hpp" #include "ImGuiExtensions/ImGuiPlotTwoLines.hpp" #include namespace OpenVulkano::Scene::UI { namespace { float FrameCollectionValuesGetter(void *data, int index) { auto frameCollection = reinterpret_cast(data); float value = frameCollection->m_frameTimes[index]; float result = value / frameCollection->m_maxValue * 100; return result; } float RamValuesGetter(void *data, int index) { auto queue = reinterpret_cast *>(data); float used = (*queue)[index]; float max = SystemInfo::GetAppRamMax(); float percentage = used / max * 100; return percentage; } } void PerformanceInfo::UpdateQueues() { m_frameCollection.m_frameTimes.push_back(static_cast(CURRENT_FRAME.frameTime)); while(m_frameCollection.m_frameTimes.size() > m_windowSize) m_frameCollection.m_frameTimes.pop_front(); float maxFrameTime = FLT_MIN; for(auto value : m_frameCollection.m_frameTimes) { if(value > maxFrameTime) maxFrameTime = value; } m_frameCollection.m_maxValue = maxFrameTime; m_ramUsed.push_back(static_cast(SystemInfo::GetAppRamUsed())); while(m_ramUsed.size() > m_windowSize) m_ramUsed.pop_front(); } void PerformanceInfo::BeginDraw() { bool alwaysShow = true; ImGui::Begin("Performance Info", &alwaysShow); } void PerformanceInfo::Draw() { UpdateQueues(); assert(m_frameCollection.m_frameTimes.size() == m_ramUsed.size()); ImGui::Text("Last Frame Time(wrt max): %f s", m_frameCollection.m_frameTimes.back()); ImGui::Text("Last FPS: %f", 1 / m_frameCollection.m_frameTimes.back()); 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(); float scaleMin = 0.01; float scaleMax = 100; ImGui::PlotTwoLines("", &FrameCollectionValuesGetter, &m_frameCollection, "Frame Time", &RamValuesGetter, &m_ramUsed, "RAM", (int)m_ramUsed.size(), scaleMin, scaleMax, availableSize); } void PerformanceInfo::EndDraw() { ImGui::End(); } }