Added the initialization code + UI bindings + logs

This commit is contained in:
Nemoumbra 2024-09-08 18:45:27 +03:00
parent e3b09bea59
commit 25f6b01d86
5 changed files with 90 additions and 9 deletions

View File

@ -43,6 +43,7 @@
#include "Core/MIPS/MIPS.h"
#include "Core/HLE/sceNetAdhoc.h"
#include "GPU/Debugger/Stepping.h"
#include "Core/MIPS/MIPSTracer.h"
#ifdef _WIN32
#include "Common/CommonWindows.h"
@ -334,6 +335,9 @@ bool Core_Run(GraphicsContext *ctx) {
void Core_EnableStepping(bool step, const char *reason, u32 relatedAddress) {
if (step) {
// Stop the tracer
mipsTracer.stop_tracing();
Core_UpdateState(CORE_STEPPING);
steppingCounter++;
_assert_msg_(reason != nullptr, "No reason specified for break");

View File

@ -1238,7 +1238,9 @@ u32 IRInterpret(MIPSState *mips, const IRInst *inst) {
}
break;
case IROp::LogBlockHash:
// Do nothing for now
if (mipsTracer.tracing_enabled) {
mipsTracer.executed_blocks.push_back(inst->constant);
}
break;
case IROp::Nop: // TODO: This shouldn't crash, but for now we should not emit nops, so...

View File

@ -36,6 +36,14 @@ void TraceBlockStorage::initialize(u32 capacity) {
raw_instructions.resize(capacity);
cur_offset = 0;
cur_data_ptr = raw_instructions.data();
INFO_LOG(Log::JIT, "TraceBlockStorage initialized: capacity=0x%x", capacity);
}
void TraceBlockStorage::clear() {
raw_instructions.clear();
cur_offset = 0;
cur_data_ptr = nullptr;
INFO_LOG(Log::JIT, "TraceBlockStorage cleared");
}
void MIPSTracer::prepare_block(MIPSComp::IRBlock* block, MIPSComp::IRBlockCache& blocks) {
@ -57,8 +65,9 @@ void MIPSTracer::prepare_block(MIPSComp::IRBlock* block, MIPSComp::IRBlockCache&
auto mips_instructions_ptr = (const u32*)Memory::GetPointerUnchecked(virt_addr);
if (!mipsTracer.storage.push_block(mips_instructions_ptr, size)) {
// We ran out of storage! TODO: report that to the user
mipsTracer.tracing_enabled = false;
// We ran out of storage!
WARN_LOG(Log::JIT, "The MIPSTracer ran out of storage for the blocks, cannot proceed!");
stop_tracing();
return;
}
// Successfully inserted the block at index 'possible_index'!
@ -75,10 +84,38 @@ void MIPSTracer::prepare_block(MIPSComp::IRBlock* block, MIPSComp::IRBlockCache&
}
bool MIPSTracer::flush_to_file() {
INFO_LOG(Log::JIT, "MIPSTracer ordered to flush the trace to a file...");
// Do nothing for now
clear();
return true;
}
void MIPSTracer::start_tracing() {
tracing_enabled = true;
INFO_LOG(Log::JIT, "MIPSTracer enabled");
}
void MIPSTracer::stop_tracing() {
tracing_enabled = false;
INFO_LOG(Log::JIT, "MIPSTracer disabled");
}
void MIPSTracer::initialize(u32 storage_capacity, u32 max_trace_size) {
executed_blocks.resize(max_trace_size);
hash_to_index.reserve(max_trace_size);
storage.initialize(storage_capacity);
trace_info.reserve(max_trace_size);
INFO_LOG(Log::JIT, "MIPSTracer initialized: storage_capacity=0x%x, max_trace_size=%d", storage_capacity, max_trace_size);
}
void MIPSTracer::clear() {
executed_blocks.clear();
hash_to_index.clear();
storage.clear();
trace_info.clear();
INFO_LOG(Log::JIT, "MIPSTracer cleared");
}
MIPSTracer mipsTracer;

View File

@ -25,6 +25,7 @@
#include "Common/CommonTypes.h"
#include "Core/Opcode.h"
#include "Core/MIPS/IR/IRJit.h"
#include "Common/Log.h"
@ -51,6 +52,7 @@ struct TraceBlockStorage {
bool push_block(const u32* instructions, u32 size);
void initialize(u32 capacity);
void clear();
Memory::Opcode operator[](u32 index) {
return Memory::Opcode(raw_instructions[index]);
@ -135,6 +137,12 @@ struct MIPSTracer {
std::string logging_path;
bool tracing_enabled = false;
int in_storage_capacity = 0;
int in_max_trace_size = 0;
void start_tracing();
void stop_tracing();
void prepare_block(MIPSComp::IRBlock* block, MIPSComp::IRBlockCache& blocks);
void setLoggingPath(std::string path) {
logging_path = path;
@ -144,6 +152,8 @@ struct MIPSTracer {
}
bool flush_to_file();
void initialize(u32 storage_capacity, u32 max_trace_size);
void clear();
MIPSTracer(): trace_info(), executed_blocks(), hash_to_index(), storage(), logging_path() {}
};

View File

@ -1919,9 +1919,31 @@ void DeveloperToolsScreen::CreateViews() {
MIPSTracerPath_ = mipsTracer.getLoggingPath();
MIPSTracerPath = list->Add(new InfoItem(dev->T("Current log file"), MIPSTracerPath_));
Button *test = list->Add(new Button(dev->T("Flush the trace")));
test->OnClick.Handle(this, &DeveloperToolsScreen::OnMIPSTracerFlushTrace);
test->SetEnabledFunc([]() {
PopupSliderChoice* storage_capacity = list->Add(
new PopupSliderChoice(
&mipsTracer.in_storage_capacity, 0x4'0000, 0x40'0000, 0x10'0000, dev->T("Storage capacity"), 0x10000, screenManager()
)
);
storage_capacity->SetFormat("0x%x asm opcodes");
storage_capacity->OnChange.Add([&](UI::EventParams &) {
INFO_LOG(Log::JIT, "User changed the tracer's storage capacity to 0x%x", mipsTracer.in_storage_capacity);
return UI::EVENT_CONTINUE;
});
PopupSliderChoice* trace_max_size = list->Add(
new PopupSliderChoice(
&mipsTracer.in_max_trace_size, 0x1'0000, 0x40'0000, 0x10'0000, dev->T("Max allowed trace size"), 0x10000, screenManager()
)
);
trace_max_size->SetFormat("%d basic blocks");
trace_max_size->OnChange.Add([&](UI::EventParams &) {
INFO_LOG(Log::JIT, "User changed the tracer's max trace size to %d", mipsTracer.in_max_trace_size);
return UI::EVENT_CONTINUE;
});
Button *FlushTrace = list->Add(new Button(dev->T("Flush the trace")));
FlushTrace->OnClick.Handle(this, &DeveloperToolsScreen::OnMIPSTracerFlushTrace);
FlushTrace->SetEnabledFunc([]() {
#if PPSSPP_PLATFORM(WINDOWS)
return true;
#else
@ -2119,11 +2141,17 @@ UI::EventReturn DeveloperToolsScreen::OnRemoteDebugger(UI::EventParams &e) {
}
UI::EventReturn DeveloperToolsScreen::OnMIPSTracerEnabled(UI::EventParams &e) {
mipsTracer.clear();
if (MIPSTracerEnabled_) {
// mipsTracer.tracing_enabled = true;
u32 capacity = mipsTracer.in_storage_capacity;
u32 trace_size = mipsTracer.in_max_trace_size;
mipsTracer.initialize(capacity, trace_size);
// mipsTracer.start_tracing();
}
else {
mipsTracer.tracing_enabled = false;
mipsTracer.stop_tracing();
}
return UI::EVENT_DONE;
}
@ -2150,7 +2178,7 @@ UI::EventReturn DeveloperToolsScreen::OnMIPSTracerFlushTrace(UI::EventParams &e)
#if PPSSPP_PLATFORM(WINDOWS)
bool success = mipsTracer.flush_to_file();
if (!success) {
// TODO: report this to the user
WARN_LOG(Log::JIT, "Error: cannot flush the trace to the specified file!");
}
#endif
return UI::EVENT_DONE;