diff --git a/Core/MIPS/IR/IRJit.cpp b/Core/MIPS/IR/IRJit.cpp index 3bf42f33c8..07c7a54162 100644 --- a/Core/MIPS/IR/IRJit.cpp +++ b/Core/MIPS/IR/IRJit.cpp @@ -40,6 +40,7 @@ #include "Core/MIPS/IR/IRNativeCommon.h" #include "Core/MIPS/JitCommon/JitCommon.h" #include "Core/Reporting.h" +#include "Common/TimeUtil.h" namespace MIPSComp { @@ -257,7 +258,17 @@ void IRJit::RunLoopUntil(u64 globalticks) { u32 opcode = inst & 0xFF000000; if (opcode == MIPS_EMUHACK_OPCODE) { IRBlock *block = blocks_.GetBlockUnchecked(inst & 0xFFFFFF); + +#ifdef IR_PROFILING + { + TimeSpan span; + mips->pc = IRInterpret(mips, block->GetInstructions()); + block->profileStats_.executions += 1; + block->profileStats_.totalNanos += span.ElapsedNanos(); + } +#else mips->pc = IRInterpret(mips, block->GetInstructions()); +#endif // Note: this will "jump to zero" on a badly constructed block missing exits. if (!Memory::IsValid4AlignedAddress(mips->pc)) { Core_ExecException(mips->pc, block->GetOriginalStart(), ExecExceptionType::JUMP); diff --git a/Core/MIPS/IR/IRJit.h b/Core/MIPS/IR/IRJit.h index 07523d092a..09651e8848 100644 --- a/Core/MIPS/IR/IRJit.h +++ b/Core/MIPS/IR/IRJit.h @@ -33,6 +33,8 @@ #include "stddef.h" #endif +// #define IR_PROFILING + namespace MIPSComp { // TODO : Use arena allocators. For now let's just malloc. @@ -98,6 +100,10 @@ public: void Finalize(int number); void Destroy(int number); +#ifdef IR_PROFILING + JitBlockProfileStats profileStats_{}; +#endif + private: u64 CalculateHash() const; @@ -152,6 +158,14 @@ public: void ComputeStats(BlockCacheStats &bcStats) const override; int GetBlockNumberFromStartAddress(u32 em_address, bool realBlocksOnly = true) const override; + bool SupportsProfiling() const override { +#ifdef IR_PROFILING + return true; +#else + return false; +#endif + } + private: u32 AddressToPage(u32 addr) const; diff --git a/Core/MIPS/JitCommon/JitBlockCache.h b/Core/MIPS/JitCommon/JitBlockCache.h index aa8db04f15..ab3ea74e04 100644 --- a/Core/MIPS/JitCommon/JitBlockCache.h +++ b/Core/MIPS/JitCommon/JitBlockCache.h @@ -103,13 +103,22 @@ struct JitBlockDebugInfo { std::vector targetDisasm; }; +struct JitBlockProfileStats { + int64_t executions; + int64_t totalNanos; +}; + class JitBlockCacheDebugInterface { public: virtual int GetNumBlocks() const = 0; virtual int GetBlockNumberFromStartAddress(u32 em_address, bool realBlocksOnly = true) const = 0; - virtual JitBlockDebugInfo GetBlockDebugInfo(int blockNum) const = 0; + virtual JitBlockDebugInfo GetBlockDebugInfo(int blockNum) const = 0; // Expensive + virtual JitBlockProfileStats GetBlockProfileStats(int blockNum) const { // Cheap + return JitBlockProfileStats{}; + } virtual void ComputeStats(BlockCacheStats &bcStats) const = 0; virtual bool IsValidBlock(int blockNum) const = 0; + virtual bool SupportsProfiling() const { return false; } virtual ~JitBlockCacheDebugInterface() {} };