Move PerformanceMetrics from global variable to System

This avoids the static initialization order fiasco between Core and VideoCommon

Co-authored-by: Jordan Woyak <jordan.woyak@gmail.com>
This commit is contained in:
Mihai Brodschi 2026-03-14 15:36:11 +02:00
parent 7a45ede688
commit f9c3f06f0a
9 changed files with 20 additions and 14 deletions

View File

@ -332,7 +332,7 @@ static void CpuThread(Core::System& system, const std::optional<std::string>& sa
DolphinAnalytics::Instance().ReportGameStart();
// Clear performance data collected from previous threads.
g_perf_metrics.Reset();
system.GetPerfMetrics().Reset();
// The JIT need to be able to intercept faults, both for fastmem and for the BLR optimization.
const bool exception_handler = EMM::IsExceptionHandlerSupported();
@ -856,11 +856,12 @@ void RunOnCPUThread(Core::System& system, Common::MoveOnlyFunction<void()> funct
// Called from Renderer::Swap (GPU thread) when a frame is presented to the host screen.
void Callback_FramePresented(const PresentInfo& present_info)
{
g_perf_metrics.CountFrame();
auto& perf_metrics = Core::System::GetInstance().GetPerfMetrics();
perf_metrics.CountFrame();
const auto presentation_offset =
present_info.actual_present_time - present_info.intended_present_time;
g_perf_metrics.SetLatestFramePresentationOffset(presentation_offset);
perf_metrics.SetLatestFramePresentationOffset(presentation_offset);
if (present_info.reason == PresentInfo::PresentReason::VideoInterfaceDuplicate)
return;

View File

@ -422,7 +422,7 @@ void CoreTimingManager::SleepUntil(TimePoint time_point)
// Count amount of time sleeping for analytics
const TimePoint time_after_sleep = Clock::now();
g_perf_metrics.CountThrottleSleep(time_after_sleep - time);
m_system.GetPerfMetrics().CountThrottleSleep(time_after_sleep - time);
}
else
{
@ -452,8 +452,8 @@ void CoreTimingManager::Throttle(const s64 target_cycle)
// Measure current performance after throttling.
Common::ScopeGuard perf_marker{[&] {
g_perf_metrics.CountPerformanceMarker(target_cycle,
m_system.GetSystemTimers().GetTicksPerSecond());
m_system.GetPerfMetrics().CountPerformanceMarker(
target_cycle, m_system.GetSystemTimers().GetTicksPerSecond());
}};
if (IsSpeedUnlimited())
@ -562,7 +562,7 @@ void CoreTimingManager::AdjustEventQueueTimes(u32 new_ppc_clock, u32 old_ppc_clo
UpdateSpeedLimit(ticks, m_emulation_speed);
g_perf_metrics.AdjustClockSpeed(ticks, new_ppc_clock, old_ppc_clock);
m_system.GetPerfMetrics().AdjustClockSpeed(ticks, new_ppc_clock, old_ppc_clock);
for (Event& ev : m_event_queue)
{

View File

@ -214,7 +214,7 @@ s64 SystemTimersManager::GetLocalTimeRTCOffset() const
double SystemTimersManager::GetEstimatedEmulationPerformance() const
{
return g_perf_metrics.GetMaxSpeed();
return m_system.GetPerfMetrics().GetMaxSpeed();
}
// split from Init to break a circular dependency between VideoInterface::Init and

View File

@ -895,7 +895,7 @@ void VideoInterfaceManager::EndField(FieldType field, u64 ticks)
if (is_vblank_data_wanted)
m_system.GetCoreTiming().Throttle(ticks);
g_perf_metrics.CountVBlank();
m_system.GetPerfMetrics().CountVBlank();
m_system.GetVideoEvents().vi_end_field_event.Trigger();
Core::OnFrameEnd(m_system);
}

View File

@ -85,6 +85,7 @@ struct System::Impl
IOS::WiiIPC m_wii_ipc;
Memory::MemoryManager m_memory;
MemoryInterface::MemoryInterfaceManager m_memory_interface;
PerformanceMetrics m_perf_metrics;
PixelEngine::PixelEngineManager m_pixel_engine;
PixelShaderManager m_pixel_shader_manager;
PowerPC::PowerPCManager m_power_pc;
@ -273,6 +274,11 @@ Movie::MovieManager& System::GetMovie() const
return m_impl->m_movie;
}
PerformanceMetrics& System::GetPerfMetrics() const
{
return m_impl->m_perf_metrics;
}
PixelEngine::PixelEngineManager& System::GetPixelEngine() const
{
return m_impl->m_pixel_engine;

View File

@ -5,6 +5,7 @@
#include <memory>
#include "VideoCommon/PerformanceMetrics.h"
#include "VideoCommon/VideoEvents.h"
class GeometryShaderManager;
@ -186,6 +187,7 @@ public:
MemoryInterface::MemoryInterfaceManager& GetMemoryInterface() const;
PowerPC::MMU& GetMMU() const;
Movie::MovieManager& GetMovie() const;
PerformanceMetrics& GetPerfMetrics() const;
PixelEngine::PixelEngineManager& GetPixelEngine() const;
PixelShaderManager& GetPixelShaderManager() const;
PowerPC::PowerPCManager& GetPowerPC() const;

View File

@ -417,7 +417,8 @@ void OnScreenUI::Finalize()
{
auto lock = GetImGuiLock();
g_perf_metrics.DrawImGuiStats(m_backbuffer_scale);
auto& perf_metrics = Core::System::GetInstance().GetPerfMetrics();
perf_metrics.DrawImGuiStats(m_backbuffer_scale);
DrawDebugText();
OSD::DrawMessages();
DrawChallengesAndLeaderboards();

View File

@ -13,8 +13,6 @@
#include "Core/Core.h"
#include "VideoCommon/VideoConfig.h"
PerformanceMetrics g_perf_metrics;
PerformanceMetrics::PerformanceMetrics()
{
const auto invalidate_counters_last_time = [this](Core::State) {

View File

@ -71,5 +71,3 @@ private:
Common::EventHook m_state_change_hook;
};
extern PerformanceMetrics g_perf_metrics;