PerformanceInfo improvements
This commit is contained in:
@@ -18,42 +18,45 @@ namespace OpenVulkano::Scene::UI
|
||||
{
|
||||
namespace
|
||||
{
|
||||
float FrameCollectionValuesGetter(void *data, int index)
|
||||
float FloatCollectionValuesGetter(void *data, int index)
|
||||
{
|
||||
auto frameCollection = reinterpret_cast<FrameTimeCollection *>(data);
|
||||
float value = frameCollection->m_frameTimes[index];
|
||||
float result = value / frameCollection->m_maxValue * 100;
|
||||
auto collection = static_cast<FloatCollection *>(data);
|
||||
float value = collection->m_values[index];
|
||||
float result = value / collection->m_maxValue * 100;
|
||||
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()
|
||||
{
|
||||
m_frameCollection.m_frameTimes.push_back(static_cast<float>(CURRENT_FRAME.frameTime));
|
||||
while(m_frameCollection.m_frameTimes.size() > m_windowSize)
|
||||
m_frameCollection.m_frameTimes.pop_front();
|
||||
float newFrameTime = static_cast<float>(CURRENT_FRAME.frameTime);
|
||||
if(newFrameTime > m_frames.m_maxValue)
|
||||
m_frames.m_maxValue = newFrameTime;
|
||||
|
||||
float maxFrameTime = FLT_MIN;
|
||||
for(auto value : m_frameCollection.m_frameTimes)
|
||||
m_frames.m_values.push_back(newFrameTime);
|
||||
|
||||
while(m_frames.m_values.size() > m_windowSize)
|
||||
{
|
||||
if(value > maxFrameTime)
|
||||
maxFrameTime = value;
|
||||
float poppedFrameTime = m_frames.m_values.front();
|
||||
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()));
|
||||
while(m_ramUsed.size() > m_windowSize)
|
||||
m_ramUsed.pop_front();
|
||||
m_ramUsed.m_values.push_back(static_cast<float>(SystemInfo::GetAppRamUsed()));
|
||||
while(m_ramUsed.m_values.size() > m_windowSize)
|
||||
m_ramUsed.m_values.pop_front();
|
||||
|
||||
m_ramUsed.m_maxValue = SystemInfo::GetAppRamMax();
|
||||
|
||||
assert(m_ramUsed.m_values.size() <= m_windowSize);
|
||||
}
|
||||
|
||||
void PerformanceInfo::BeginDraw()
|
||||
@@ -65,20 +68,20 @@ namespace OpenVulkano::Scene::UI
|
||||
void PerformanceInfo::Draw()
|
||||
{
|
||||
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 FPS: %f", 1 / m_frameCollection.m_frameTimes.back());
|
||||
ImGui::Text("Last Frame Time: %f s", m_frames.m_values.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::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(),
|
||||
&FloatCollectionValuesGetter, &m_frames, "Frame Time(wrt max)",
|
||||
&FloatCollectionValuesGetter, &m_ramUsed, "RAM",
|
||||
(int)m_ramUsed.m_values.size(),
|
||||
scaleMin, scaleMax, availableSize);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,17 +12,17 @@
|
||||
|
||||
namespace OpenVulkano::Scene::UI
|
||||
{
|
||||
struct FrameTimeCollection
|
||||
struct FloatCollection
|
||||
{
|
||||
std::deque<float> m_frameTimes;
|
||||
std::deque<float> m_values;
|
||||
float m_maxValue;
|
||||
};
|
||||
|
||||
class PerformanceInfo : public UiElement
|
||||
{
|
||||
int m_windowSize = 200;
|
||||
std::deque<float> m_ramUsed;
|
||||
FrameTimeCollection m_frameCollection;
|
||||
FloatCollection m_ramUsed;
|
||||
FloatCollection m_frames;
|
||||
|
||||
void UpdateQueues();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user