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,9 +412,12 @@ 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)
blockSize = 1; if (!Profiler::g_ProfileBlocks)
broken_block = true; {
Trace(); blockSize = 1;
broken_block = true;
Trace();
}
} }
if (em_address == 0) if (em_address == 0)

View File

@ -524,8 +524,11 @@ 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)
blockSize = 1; if (!Profiler::g_ProfileBlocks)
Trace(); {
blockSize = 1;
Trace();
}
} }
if (em_address == 0) if (em_address == 0)

View File

@ -56,18 +56,21 @@ 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);
// Rough heuristic. Mem instructions should cost more. if (block && !block->invalid)
u64 cost = block->originalSize * (block->runCount / 4); {
// Rough heuristic. Mem instructions should cost more.
u64 cost = block->originalSize * (block->runCount / 4);
#ifdef _WIN32 #ifdef _WIN32
u64 timecost = block->ticCounter; u64 timecost = block->ticCounter;
#endif #endif
// Todo: tweak. // Todo: tweak.
if (block->runCount >= 1) if (block->runCount >= 1)
stats.push_back(BlockStat(i, cost)); stats.push_back(BlockStat(i, cost));
cost_sum += cost; cost_sum += cost;
#ifdef _WIN32 #ifdef _WIN32
timecost_sum += timecost; timecost_sum += timecost;
#endif #endif
}
} }
sort(stats.begin(), stats.end()); sort(stats.begin(), stats.end());
@ -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,35 +187,40 @@ 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 (jit != NULL) if (Core::GetState() == Core::CORE_RUN)
{ Core::SetState(Core::CORE_PAUSE);
std::string filename = File::GetUserPath(D_DUMP_IDX) + "Debug/profiler.txt";
File::CreateFullPath(filename);
Profiler::WriteProfileResults(filename.c_str());
wxFileType* filetype = NULL; if (Core::GetState() == Core::CORE_PAUSE && PowerPC::GetMode() == PowerPC::MODE_JIT)
if (!(filetype = wxTheMimeTypesManager->GetFileTypeFromExtension(_T("txt")))) {
if (jit != NULL)
{ {
// From extension failed, trying with MIME type now std::string filename = File::GetUserPath(D_DUMP_IDX) + "Debug/profiler.txt";
if (!(filetype = wxTheMimeTypesManager->GetFileTypeFromMimeType(_T("text/plain")))) File::CreateFullPath(filename);
// MIME type failed, aborting mission Profiler::WriteProfileResults(filename.c_str());
break;
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; break;
} }