From 1532a729d70fa1d900308973a43fa7fbb84c2519 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 19 Sep 2021 15:17:13 -0700 Subject: [PATCH] Core: Allow forcing debug statistics collection. Useful for remote debugging. --- Core/HLE/sceDisplay.cpp | 8 ++++---- Core/System.cpp | 16 +++++++++++++--- Core/System.h | 2 ++ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/Core/HLE/sceDisplay.cpp b/Core/HLE/sceDisplay.cpp index 9757186a0b..63f6f58ea7 100644 --- a/Core/HLE/sceDisplay.cpp +++ b/Core/HLE/sceDisplay.cpp @@ -497,7 +497,7 @@ static void CalculateFPS() { } } - if (g_Config.bDrawFrameGraph) { + if (g_Config.bDrawFrameGraph || coreCollectDebugStats) { frameTimeHistory[frameTimeHistoryPos++] = now - lastFrameTimeHistory; lastFrameTimeHistory = now; frameTimeHistoryPos = frameTimeHistoryPos % frameTimeHistorySize; @@ -682,7 +682,7 @@ static void DoFrameIdleTiming() { #endif } - if (g_Config.bDrawFrameGraph) { + if (g_Config.bDrawFrameGraph || coreCollectDebugStats) { frameSleepHistory[frameTimeHistoryPos] += time_now_d() - before; } } @@ -848,7 +848,7 @@ void __DisplayFlip(int cyclesLate) { CoreTiming::ScheduleEvent(0 - cyclesLate, afterFlipEvent, 0); numVBlanksSinceFlip = 0; - if (g_Config.bDrawFrameGraph) { + if (g_Config.bDrawFrameGraph || coreCollectDebugStats) { // Track how long we sleep (whether vsync or sleep_ms.) frameSleepHistory[frameSleepPos] += time_now_d() - lastFrameTimeHistory; } @@ -913,7 +913,7 @@ void hleLagSync(u64 userdata, int cyclesLate) { const int over = (int)((now - goal) * 1000000); ScheduleLagSync(over - emuOver); - if (g_Config.bDrawFrameGraph) { + if (g_Config.bDrawFrameGraph || coreCollectDebugStats) { frameSleepHistory[frameTimeHistoryPos] += now - before; } } diff --git a/Core/System.cpp b/Core/System.cpp index 04070c614e..ea752d2aae 100644 --- a/Core/System.cpp +++ b/Core/System.cpp @@ -98,7 +98,7 @@ static std::string loadingReason; bool audioInitialized; bool coreCollectDebugStats = false; -bool coreCollectDebugStatsForced = false; +static int coreCollectDebugStatsCounter = 0; // This can be read and written from ANYWHERE. volatile CoreState coreState = CORE_STEPPING; @@ -385,8 +385,9 @@ void Core_UpdateState(CoreState newState) { } void Core_UpdateDebugStats(bool collectStats) { - if (coreCollectDebugStats != collectStats) { - coreCollectDebugStats = collectStats; + bool newState = collectStats || coreCollectDebugStatsCounter > 0; + if (coreCollectDebugStats != newState) { + coreCollectDebugStats = newState; mipsr4k.ClearJitCache(); } @@ -394,6 +395,15 @@ void Core_UpdateDebugStats(bool collectStats) { gpuStats.ResetFrame(); } +void Core_ForceDebugStats(bool enable) { + if (enable) { + coreCollectDebugStatsCounter++; + } else { + coreCollectDebugStatsCounter--; + } + _assert_(coreCollectDebugStatsCounter >= 0); +} + bool PSP_InitStart(const CoreParameter &coreParam, std::string *error_string) { if (pspIsIniting || pspIsQuitting) { return false; diff --git a/Core/System.h b/Core/System.h index 380c9e00f3..f28681e6d3 100644 --- a/Core/System.h +++ b/Core/System.h @@ -94,6 +94,8 @@ struct PSP_LoadingLock { // Call before PSP_BeginHostFrame() in order to not miss any GPU stats. void Core_UpdateDebugStats(bool collectStats); +// Increments or decrements an internal counter. Intended to be used by debuggers. +void Core_ForceDebugStats(bool enable); void Audio_Init(); void Audio_Shutdown();