From 5583dc10d5272068fd145e54073d8d4e8398e435 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 5 Jun 2024 18:58:33 +0200 Subject: [PATCH] Hook up profiling, something is wrong --- Core/MIPS/IR/IRJit.h | 2 +- UI/JitCompareScreen.cpp | 38 +++++++++++++++++++++++++++++++++++--- UI/JitCompareScreen.h | 1 + 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/Core/MIPS/IR/IRJit.h b/Core/MIPS/IR/IRJit.h index deeffe8ff7..171bebe3bf 100644 --- a/Core/MIPS/IR/IRJit.h +++ b/Core/MIPS/IR/IRJit.h @@ -33,7 +33,7 @@ #include "stddef.h" #endif -// #define IR_PROFILING +#define IR_PROFILING namespace MIPSComp { diff --git a/UI/JitCompareScreen.cpp b/UI/JitCompareScreen.cpp index c436410e42..245a205ed1 100644 --- a/UI/JitCompareScreen.cpp +++ b/UI/JitCompareScreen.cpp @@ -87,8 +87,34 @@ void JitCompareScreen::CreateViews() { blockListView_ = root_->Add(new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(1.0f))); blockListView_->SetVisibility(V_GONE); + // Should match the ListSort enum + static ContextMenuItem sortMenu[] = { + { "Block number", "I_ARROW_UP" }, + { "Block length", "I_ARROW_DOWN" }, + { "Block length", "I_ARROW_UP" }, + { "Time spent", "I_ARROW_DOWN" }, + { "Executions", "I_ARROW_DOWN" }, + }; + int sortCount = ARRAY_SIZE(sortMenu); + if (MIPSComp::jit) { + JitBlockCacheDebugInterface *blockCacheDebug = MIPSComp::jit->GetBlockCacheDebugInterface(); + if (!blockCacheDebug->SupportsProfiling()) { + sortCount -= 2; + } + } + LinearLayout *listTopBar = blockListView_->Add(new LinearLayout(ORIENT_HORIZONTAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT))); - listTopBar->Add(new Button(dev->T("Sort...")))->OnClick.Add([this](UI::EventParams &e) { + Button *sortButton = new Button(dev->T("Sort...")); + listTopBar->Add(sortButton)->OnClick.Add([this, sortButton, sortCount](UI::EventParams &e) { + PopupContextMenuScreen *contextMenu = new UI::PopupContextMenuScreen(sortMenu, sortCount, I18NCat::DEVELOPER, sortButton); + screenManager()->push(contextMenu); + contextMenu->OnChoice.Add([=](EventParams &e) -> UI::EventReturn { + if (e.a < (int)ListSort::MAX) { + listSort_ = (ListSort)e.a; + UpdateDisasm(); + } + return UI::EVENT_DONE; + }); return UI::EVENT_DONE; }); @@ -251,9 +277,15 @@ void JitCompareScreen::UpdateDisasm() { blockListContainer_->Clear(); for (int i = 0; i < std::min(100, (int)blockList_.size()); i++) { JitBlockMeta meta = blockCacheDebug->GetBlockMeta(blockList_[i]); - char temp[512], small[512]; - snprintf(temp, sizeof(temp), "%08x: %d instrs", meta.addr, meta.sizeInBytes / 4); + if (blockCacheDebug->SupportsProfiling()) { + JitBlockProfileStats stats = blockCacheDebug->GetBlockProfileStats(blockList_[i]); + int execs = (int)stats.executions; + double us = (double)stats.totalNanos / 1000.0; + snprintf(temp, sizeof(temp), "%08x: %d instrs (%d exec, %0.2f us)", meta.addr, meta.sizeInBytes / 4, execs, us); + } else { + snprintf(temp, sizeof(temp), "%08x: %d instrs", meta.addr, meta.sizeInBytes / 4); + } snprintf(small, sizeof(small), "Small text"); Choice *blockChoice = blockListContainer_->Add(new Choice(temp, small)); blockChoice->OnClick.Handle(this, &JitCompareScreen::OnBlockClick); diff --git a/UI/JitCompareScreen.h b/UI/JitCompareScreen.h index 4f449381cc..03403343f8 100644 --- a/UI/JitCompareScreen.h +++ b/UI/JitCompareScreen.h @@ -42,6 +42,7 @@ private: BLOCK_LENGTH_ASC, TIME_SPENT, EXECUTIONS, + MAX }; ViewMode viewMode_ = ViewMode::BLOCK_LIST; ListType listType_ = ListType::ALL_BLOCKS;