diff --git a/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp b/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp index ad15d0f449..1f825fa9ec 100644 --- a/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp +++ b/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp @@ -119,6 +119,12 @@ int* JitBaseBlockCache::GetICache() return iCache.data(); } +void JitBaseBlockCache::RunOnBlocks(std::function f) +{ + for (int i = 0; i < num_blocks; i++) + f(blocks[i]); +} + JitBlock* JitBaseBlockCache::AllocateBlock(u32 em_address) { JitBlock& b = blocks[num_blocks]; diff --git a/Source/Core/Core/PowerPC/JitCommon/JitCache.h b/Source/Core/Core/PowerPC/JitCommon/JitCache.h index 8c4bc04e2e..781fb596f4 100644 --- a/Source/Core/Core/PowerPC/JitCommon/JitCache.h +++ b/Source/Core/Core/PowerPC/JitCommon/JitCache.h @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -130,6 +131,7 @@ public: JitBlock* GetBlocks(); int GetNumBlocks() const; int* GetICache(); + void RunOnBlocks(std::function f); JitBlock* AllocateBlock(u32 em_address); void FinalizeBlock(JitBlock& b, bool block_link, const u8* code_ptr); diff --git a/Source/Core/Core/PowerPC/JitInterface.cpp b/Source/Core/Core/PowerPC/JitInterface.cpp index 790a377dc1..a342f7a6d7 100644 --- a/Source/Core/Core/PowerPC/JitInterface.cpp +++ b/Source/Core/Core/PowerPC/JitInterface.cpp @@ -134,26 +134,23 @@ void GetProfileResults(ProfileStats* prof_stats) prof_stats->cost_sum = 0; prof_stats->timecost_sum = 0; prof_stats->block_stats.clear(); - prof_stats->block_stats.reserve(g_jit->GetBlockCache()->GetNumBlocks()); Core::EState old_state = Core::GetState(); if (old_state == Core::CORE_RUN) Core::SetState(Core::CORE_PAUSE); QueryPerformanceFrequency((LARGE_INTEGER*)&prof_stats->countsPerSec); - for (int i = 0; i < g_jit->GetBlockCache()->GetNumBlocks(); i++) - { - const JitBlock* block = g_jit->GetBlockCache()->GetBlock(i); + g_jit->GetBlockCache()->RunOnBlocks([&prof_stats](const JitBlock& block) { // Rough heuristic. Mem instructions should cost more. - u64 cost = block->originalSize * (block->runCount / 4); - u64 timecost = block->ticCounter; + u64 cost = block.originalSize * (block.runCount / 4); + u64 timecost = block.ticCounter; // Todo: tweak. - if (block->runCount >= 1) - prof_stats->block_stats.emplace_back(i, block->effectiveAddress, cost, timecost, - block->runCount, block->codeSize); + if (block.runCount >= 1) + prof_stats->block_stats.emplace_back(block.effectiveAddress, cost, timecost, block.runCount, + block.codeSize); prof_stats->cost_sum += cost; prof_stats->timecost_sum += timecost; - } + }); sort(prof_stats->block_stats.begin(), prof_stats->block_stats.end()); if (old_state == Core::CORE_RUN) diff --git a/Source/Core/Core/PowerPC/Profiler.h b/Source/Core/Core/PowerPC/Profiler.h index 4c11af58ed..6146bee4d1 100644 --- a/Source/Core/Core/PowerPC/Profiler.h +++ b/Source/Core/Core/PowerPC/Profiler.h @@ -43,11 +43,10 @@ struct BlockStat { - BlockStat(int bn, u32 _addr, u64 c, u64 ticks, u64 run, u32 size) - : blockNum(bn), addr(_addr), cost(c), tick_counter(ticks), run_count(run), block_size(size) + BlockStat(u32 _addr, u64 c, u64 ticks, u64 run, u32 size) + : addr(_addr), cost(c), tick_counter(ticks), run_count(run), block_size(size) { } - int blockNum; u32 addr; u64 cost; u64 tick_counter;