From bf76b802a7b619369349ac95de1850ce89091e63 Mon Sep 17 00:00:00 2001 From: skidau Date: Sat, 10 Mar 2012 16:24:13 +1100 Subject: [PATCH] Fixed the in-built Dolphin profiler. --- Source/Core/Core/Src/PowerPC/Jit64/Jit.cpp | 9 ++-- .../Core/Core/Src/PowerPC/Jit64IL/JitIL.cpp | 7 ++- Source/Core/Core/Src/PowerPC/Profiler.cpp | 27 ++++++----- .../Src/Debugger/CodeWindowFunctions.cpp | 45 ++++++++++--------- 4 files changed, 51 insertions(+), 37 deletions(-) diff --git a/Source/Core/Core/Src/PowerPC/Jit64/Jit.cpp b/Source/Core/Core/Src/PowerPC/Jit64/Jit.cpp index 0d31893b53..df1fd0f589 100644 --- a/Source/Core/Core/Src/PowerPC/Jit64/Jit.cpp +++ b/Source/Core/Core/Src/PowerPC/Jit64/Jit.cpp @@ -412,9 +412,12 @@ const u8* Jit64::DoJit(u32 em_address, PPCAnalyst::CodeBuffer *code_buf, JitBloc if (Core::g_CoreStartupParameter.bEnableDebugging) { // Comment out the following to disable breakpoints (speed-up) - blockSize = 1; - broken_block = true; - Trace(); + if (!Profiler::g_ProfileBlocks) + { + blockSize = 1; + broken_block = true; + Trace(); + } } if (em_address == 0) diff --git a/Source/Core/Core/Src/PowerPC/Jit64IL/JitIL.cpp b/Source/Core/Core/Src/PowerPC/Jit64IL/JitIL.cpp index 75755de5cb..77c7fb6169 100644 --- a/Source/Core/Core/Src/PowerPC/Jit64IL/JitIL.cpp +++ b/Source/Core/Core/Src/PowerPC/Jit64IL/JitIL.cpp @@ -524,8 +524,11 @@ const u8* JitIL::DoJit(u32 em_address, PPCAnalyst::CodeBuffer *code_buf, JitBloc if (Core::g_CoreStartupParameter.bEnableDebugging) { // Comment out the following to disable breakpoints (speed-up) - blockSize = 1; - Trace(); + if (!Profiler::g_ProfileBlocks) + { + blockSize = 1; + Trace(); + } } if (em_address == 0) diff --git a/Source/Core/Core/Src/PowerPC/Profiler.cpp b/Source/Core/Core/Src/PowerPC/Profiler.cpp index 2874705d4b..3636b00717 100644 --- a/Source/Core/Core/Src/PowerPC/Profiler.cpp +++ b/Source/Core/Core/Src/PowerPC/Profiler.cpp @@ -56,18 +56,21 @@ void WriteProfileResults(const char *filename) for (int i = 0; i < jit->GetBlockCache()->GetNumBlocks(); i++) { const JitBlock *block = jit->GetBlockCache()->GetBlock(i); - // Rough heuristic. Mem instructions should cost more. - u64 cost = block->originalSize * (block->runCount / 4); + if (block && !block->invalid) + { + // Rough heuristic. Mem instructions should cost more. + u64 cost = block->originalSize * (block->runCount / 4); #ifdef _WIN32 - u64 timecost = block->ticCounter; + u64 timecost = block->ticCounter; #endif - // Todo: tweak. - if (block->runCount >= 1) - stats.push_back(BlockStat(i, cost)); - cost_sum += cost; + // Todo: tweak. + if (block->runCount >= 1) + stats.push_back(BlockStat(i, cost)); + cost_sum += cost; #ifdef _WIN32 - timecost_sum += timecost; + timecost_sum += timecost; #endif + } } sort(stats.begin(), stats.end()); @@ -77,18 +80,18 @@ void WriteProfileResults(const char *filename) PanicAlert("failed to open %s", filename); return; } - fprintf(f.GetHandle(), "origAddr\tblkName\tcost\ttimeCost\tpercent\ttimePercent\tOvAllinBlkTime(ms)\tblkCodeSize\n"); + fprintf(f.GetHandle(), "origAddr\tblkName\tcost\trunCount\ttimeCost\tpercent\ttimePercent\tOvAllinBlkTime(ms)\tblkCodeSize\n"); for (unsigned int i = 0; i < stats.size(); i++) { const JitBlock *block = jit->GetBlockCache()->GetBlock(stats[i].blockNum); - if (block) + if (block && !block->invalid) { std::string name = g_symbolDB.GetDescription(block->originalAddress); double percent = 100.0 * (double)stats[i].cost / (double)cost_sum; #ifdef _WIN32 double timePercent = 100.0 * (double)block->ticCounter / (double)timecost_sum; - fprintf(f.GetHandle(), "%08x\t%s\t%llu\t%llu\t%.2lf\t%llf\t%lf\t%i\n", - block->originalAddress, name.c_str(), stats[i].cost, + fprintf(f.GetHandle(), "%08x\t%s\t%llu\t%llu\t%llu\t%.2lf\t%llf\t%lf\t%i\n", + block->originalAddress, name.c_str(), stats[i].cost, block->runCount, block->ticCounter, percent, timePercent, (double)block->ticCounter*1000.0/(double)countsPerSec, block->codeSize); #else diff --git a/Source/Core/DolphinWX/Src/Debugger/CodeWindowFunctions.cpp b/Source/Core/DolphinWX/Src/Debugger/CodeWindowFunctions.cpp index a3dd9a9ab8..05915ecd20 100644 --- a/Source/Core/DolphinWX/Src/Debugger/CodeWindowFunctions.cpp +++ b/Source/Core/DolphinWX/Src/Debugger/CodeWindowFunctions.cpp @@ -187,35 +187,40 @@ void CCodeWindow::CreateMenuSymbols(wxMenuBar *pMenuBar) void CCodeWindow::OnProfilerMenu(wxCommandEvent& event) { - if (Core::GetState() == Core::CORE_RUN) { - event.Skip(); - return; - } switch (event.GetId()) { case IDM_PROFILEBLOCKS: - if (jit != NULL) jit->ClearCache(); + Core::SetState(Core::CORE_PAUSE); + if (jit != NULL) + jit->ClearCache(); Profiler::g_ProfileBlocks = GetMenuBar()->IsChecked(IDM_PROFILEBLOCKS); + Core::SetState(Core::CORE_RUN); break; case IDM_WRITEPROFILE: - if (jit != NULL) - { - std::string filename = File::GetUserPath(D_DUMP_IDX) + "Debug/profiler.txt"; - File::CreateFullPath(filename); - Profiler::WriteProfileResults(filename.c_str()); + if (Core::GetState() == Core::CORE_RUN) + Core::SetState(Core::CORE_PAUSE); - wxFileType* filetype = NULL; - if (!(filetype = wxTheMimeTypesManager->GetFileTypeFromExtension(_T("txt")))) + if (Core::GetState() == Core::CORE_PAUSE && PowerPC::GetMode() == PowerPC::MODE_JIT) + { + if (jit != NULL) { - // From extension failed, trying with MIME type now - if (!(filetype = wxTheMimeTypesManager->GetFileTypeFromMimeType(_T("text/plain")))) - // MIME type failed, aborting mission - break; + std::string filename = File::GetUserPath(D_DUMP_IDX) + "Debug/profiler.txt"; + File::CreateFullPath(filename); + Profiler::WriteProfileResults(filename.c_str()); + + wxFileType* filetype = NULL; + if (!(filetype = wxTheMimeTypesManager->GetFileTypeFromExtension(_T("txt")))) + { + // From extension failed, trying with MIME type now + if (!(filetype = wxTheMimeTypesManager->GetFileTypeFromMimeType(_T("text/plain")))) + // MIME type failed, aborting mission + break; + } + wxString OpenCommand; + OpenCommand = filetype->GetOpenCommand(wxString::From8BitData(filename.c_str())); + if(!OpenCommand.IsEmpty()) + wxExecute(OpenCommand, wxEXEC_SYNC); } - wxString OpenCommand; - OpenCommand = filetype->GetOpenCommand(wxString::From8BitData(filename.c_str())); - if(!OpenCommand.IsEmpty()) - wxExecute(OpenCommand, wxEXEC_SYNC); } break; }