pound-emu_pound/src/frontend/panels.cpp
Ronald Caesar 9d7b05d6ae
rename kvm references to pvm
The term KVM is missleading because we are not using linux kernel
virtualization. PVM stands for "Pound Virtual Machine" which is more
accurate.

Signed-off-by: Ronald Caesar <github43132@proton.me>
2025-09-30 18:13:48 -04:00

125 lines
3.8 KiB
C++

#include "panels.h"
#include <imgui.h>
#include <math.h>
#include "pvm/pvm.h"
#include "common/passert.h"
int8_t gui::panel::render_performance_panel(gui::panel::performance_panel_t* panel, performance_data_t* data,
std::chrono::steady_clock::time_point* last_render)
{
PVM_ASSERT(nullptr != panel);
PVM_ASSERT(nullptr != data);
PVM_ASSERT(nullptr != last_render);
bool is_visible = true;
(void)::ImGui::Begin(PANEL_NAME_PERFORMANCE, &is_visible);
if (false == is_visible)
{
::ImGui::End();
return ERROR_PANEL_IS_CLOSED;
}
auto now = std::chrono::steady_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(now - *last_render);
++data->frame_count;
if (duration.count() >= 100)
{
// Every 100ms
data->fps = (float)data->frame_count * 1000.0f / (float)duration.count();
data->frame_time = (float)duration.count() / (float)data->frame_count;
panel->fps_history.push_back(data->fps);
panel->frame_time_history.push_back(data->frame_time);
// Keep history size limited
while (panel->fps_history.size() > FRAME_TIME_HISTORY_SIZE)
{
panel->fps_history.pop_front();
}
while (panel->frame_time_history.size() > FRAME_TIME_HISTORY_SIZE)
{
panel->frame_time_history.pop_front();
}
data->frame_count = 0;
*last_render = now;
// TODO(GloriousTaco:gui): Get actual CPU and memory usage
data->cpu_usage = 0.0f;
data->memory_usage = 0.0f;
}
::ImGui::Text("FPS: %.1f", data->fps);
::ImGui::Text("Frame Time: %.2f ms", data->frame_time);
::ImGui::Separator();
// Frame Time Graph
if (false == panel->frame_time_history.empty())
{
float frame_time_array[FRAME_TIME_HISTORY_SIZE] = {};
(void)std::copy(panel->frame_time_history.begin(), panel->frame_time_history.end(), frame_time_array);
::ImGui::Text("Frame Time History (ms):");
::ImGui::PlotLines("##FrameTime", frame_time_array, (int)panel->frame_time_history.size(), 0, nullptr, 0.0f,
33.33f, ImVec2(0, 80));
}
::ImGui::Separator();
// System info (placeholder)
::ImGui::Text("CPU Usage: %.1f%%", data->cpu_usage);
::ImGui::Text("Memory Usage: %.1f MB", data->memory_usage);
// Emulation stats
::ImGui::Separator();
::ImGui::Text("Emulation Statistics:");
::ImGui::Text("Instructions/sec: N/A");
::ImGui::Text("JIT Cache Usage: N/A");
::ImGui::End();
return PANEL_SUCCESS;
}
int8_t gui::panel::render_cpu_panel(bool* show_cpu_result_popup)
{
PVM_ASSERT(nullptr != show_cpu_result_popup);
bool is_visible = true;
(void)::ImGui::Begin(PANEL_NAME_CPU, &is_visible, ImGuiWindowFlags_NoCollapse);
if (false == is_visible)
{
::ImGui::End();
return ERROR_PANEL_IS_CLOSED;
}
if (::ImGui::Button("Run CPU Test", ImVec2(120, 0)))
{
pound::pvm::cpuTest();
*show_cpu_result_popup = true;
}
if (true == *show_cpu_result_popup)
{
::ImGui::OpenPopup("CPU Test Result");
}
if (::ImGui::BeginPopupModal("CPU Test Result", nullptr, ImGuiWindowFlags_AlwaysAutoResize))
{
::ImGui::Text("The CPU test has been executed successfully!");
::ImGui::Text("Check the console for detailed output.");
::ImGui::Separator();
::ImGui::Text("Note: Pound is still in pre-alpha state.");
::ImGui::Spacing();
if (::ImGui::Button("OK", ImVec2(120, 0)))
{
*show_cpu_result_popup = false;
::ImGui::CloseCurrentPopup();
}
::ImGui::EndPopup();
}
::ImGui::End();
return PANEL_SUCCESS;
}