Fixed the in-built Dolphin profiler.

This commit is contained in:
skidau 2012-03-10 16:24:13 +11:00
parent 1680c6849f
commit bf76b802a7
4 changed files with 51 additions and 37 deletions

View File

@ -412,10 +412,13 @@ const u8* Jit64::DoJit(u32 em_address, PPCAnalyst::CodeBuffer *code_buf, JitBloc
if (Core::g_CoreStartupParameter.bEnableDebugging) if (Core::g_CoreStartupParameter.bEnableDebugging)
{ {
// Comment out the following to disable breakpoints (speed-up) // Comment out the following to disable breakpoints (speed-up)
if (!Profiler::g_ProfileBlocks)
{
blockSize = 1; blockSize = 1;
broken_block = true; broken_block = true;
Trace(); Trace();
} }
}
if (em_address == 0) if (em_address == 0)
{ {

View File

@ -524,9 +524,12 @@ const u8* JitIL::DoJit(u32 em_address, PPCAnalyst::CodeBuffer *code_buf, JitBloc
if (Core::g_CoreStartupParameter.bEnableDebugging) if (Core::g_CoreStartupParameter.bEnableDebugging)
{ {
// Comment out the following to disable breakpoints (speed-up) // Comment out the following to disable breakpoints (speed-up)
if (!Profiler::g_ProfileBlocks)
{
blockSize = 1; blockSize = 1;
Trace(); Trace();
} }
}
if (em_address == 0) if (em_address == 0)
PanicAlert("ERROR : Trying to compile at 0. LR=%08x", LR); PanicAlert("ERROR : Trying to compile at 0. LR=%08x", LR);

View File

@ -56,6 +56,8 @@ void WriteProfileResults(const char *filename)
for (int i = 0; i < jit->GetBlockCache()->GetNumBlocks(); i++) for (int i = 0; i < jit->GetBlockCache()->GetNumBlocks(); i++)
{ {
const JitBlock *block = jit->GetBlockCache()->GetBlock(i); const JitBlock *block = jit->GetBlockCache()->GetBlock(i);
if (block && !block->invalid)
{
// Rough heuristic. Mem instructions should cost more. // Rough heuristic. Mem instructions should cost more.
u64 cost = block->originalSize * (block->runCount / 4); u64 cost = block->originalSize * (block->runCount / 4);
#ifdef _WIN32 #ifdef _WIN32
@ -69,6 +71,7 @@ void WriteProfileResults(const char *filename)
timecost_sum += timecost; timecost_sum += timecost;
#endif #endif
} }
}
sort(stats.begin(), stats.end()); sort(stats.begin(), stats.end());
File::IOFile f(filename, "w"); File::IOFile f(filename, "w");
@ -77,18 +80,18 @@ void WriteProfileResults(const char *filename)
PanicAlert("failed to open %s", filename); PanicAlert("failed to open %s", filename);
return; 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++) for (unsigned int i = 0; i < stats.size(); i++)
{ {
const JitBlock *block = jit->GetBlockCache()->GetBlock(stats[i].blockNum); const JitBlock *block = jit->GetBlockCache()->GetBlock(stats[i].blockNum);
if (block) if (block && !block->invalid)
{ {
std::string name = g_symbolDB.GetDescription(block->originalAddress); std::string name = g_symbolDB.GetDescription(block->originalAddress);
double percent = 100.0 * (double)stats[i].cost / (double)cost_sum; double percent = 100.0 * (double)stats[i].cost / (double)cost_sum;
#ifdef _WIN32 #ifdef _WIN32
double timePercent = 100.0 * (double)block->ticCounter / (double)timecost_sum; 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", 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->originalAddress, name.c_str(), stats[i].cost, block->runCount,
block->ticCounter, percent, timePercent, block->ticCounter, percent, timePercent,
(double)block->ticCounter*1000.0/(double)countsPerSec, block->codeSize); (double)block->ticCounter*1000.0/(double)countsPerSec, block->codeSize);
#else #else

View File

@ -187,17 +187,21 @@ void CCodeWindow::CreateMenuSymbols(wxMenuBar *pMenuBar)
void CCodeWindow::OnProfilerMenu(wxCommandEvent& event) void CCodeWindow::OnProfilerMenu(wxCommandEvent& event)
{ {
if (Core::GetState() == Core::CORE_RUN) {
event.Skip();
return;
}
switch (event.GetId()) switch (event.GetId())
{ {
case IDM_PROFILEBLOCKS: 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); Profiler::g_ProfileBlocks = GetMenuBar()->IsChecked(IDM_PROFILEBLOCKS);
Core::SetState(Core::CORE_RUN);
break; break;
case IDM_WRITEPROFILE: case IDM_WRITEPROFILE:
if (Core::GetState() == Core::CORE_RUN)
Core::SetState(Core::CORE_PAUSE);
if (Core::GetState() == Core::CORE_PAUSE && PowerPC::GetMode() == PowerPC::MODE_JIT)
{
if (jit != NULL) if (jit != NULL)
{ {
std::string filename = File::GetUserPath(D_DUMP_IDX) + "Debug/profiler.txt"; std::string filename = File::GetUserPath(D_DUMP_IDX) + "Debug/profiler.txt";
@ -217,6 +221,7 @@ void CCodeWindow::OnProfilerMenu(wxCommandEvent& event)
if(!OpenCommand.IsEmpty()) if(!OpenCommand.IsEmpty())
wxExecute(OpenCommand, wxEXEC_SYNC); wxExecute(OpenCommand, wxEXEC_SYNC);
} }
}
break; break;
} }
} }