From c1ad3db1d85a683be0c0a6a79c421fdb88bb95e5 Mon Sep 17 00:00:00 2001 From: Nemoumbra Date: Fri, 13 Sep 2024 03:52:30 +0300 Subject: [PATCH] Switched to PPSSPP's C file-stream API --- Core/MIPS/MIPSTracer.cpp | 12 ++++++------ Core/MIPS/MIPSTracer.h | 10 ++++++---- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Core/MIPS/MIPSTracer.cpp b/Core/MIPS/MIPSTracer.cpp index 079edeeb3a..8789c998fc 100644 --- a/Core/MIPS/MIPSTracer.cpp +++ b/Core/MIPS/MIPSTracer.cpp @@ -100,8 +100,8 @@ void MIPSTracer::prepare_block(MIPSComp::IRBlock* block, MIPSComp::IRBlockCache& bool MIPSTracer::flush_to_file() { INFO_LOG(Log::JIT, "Flushing the trace to a file..."); - - output.open(logging_path, std::ios::out); + output = File::OpenCFile(logging_path, "w"); + if (!output) { WARN_LOG(Log::JIT, "MIPSTracer failed to open the file '%s'", logging_path.c_str()); return false; @@ -113,13 +113,14 @@ bool MIPSTracer::flush_to_file() { } INFO_LOG(Log::JIT, "Trace flushed, closing the file..."); - output.close(); + std::fclose(output); + clear(); return true; } void MIPSTracer::flush_block_to_file(TraceBlockInfo& block_info) { - static char buffer[1024]; + char buffer[512]; // The log format is '{prefix}{disassembled line}', where 'prefix' is '0x{8 hex digits of the address}: ' const auto prefix_size = 2 + 8 + 2; @@ -137,8 +138,7 @@ void MIPSTracer::flush_block_to_file(TraceBlockInfo& block_info) { snprintf(buffer, sizeof(buffer), "0x%08x: ", addr); MIPSDisAsm(storage.read_asm(index), addr, buffer + prefix_size, sizeof(buffer) - prefix_size, true); - // TODO: check if removing the std::string makes this faster - output << std::string(buffer) << "\n"; + std::fprintf(output, "%s\n", buffer); } } diff --git a/Core/MIPS/MIPSTracer.h b/Core/MIPS/MIPSTracer.h index c3a03c99df..4aa612f0e0 100644 --- a/Core/MIPS/MIPSTracer.h +++ b/Core/MIPS/MIPSTracer.h @@ -27,6 +27,8 @@ #include "Core/Opcode.h" #include "Core/MIPS/IR/IRJit.h" #include "Common/Log.h" +#include "Common/File/Path.h" +#include "Common/File/FileUtil.h" struct TraceBlockInfo { @@ -135,8 +137,8 @@ struct MIPSTracer { TraceBlockStorage storage; - std::string logging_path; - std::ofstream output; + Path logging_path; + FILE* output; bool tracing_enabled = false; int in_storage_capacity = 0x10'0000; @@ -147,10 +149,10 @@ struct MIPSTracer { void prepare_block(MIPSComp::IRBlock* block, MIPSComp::IRBlockCache& blocks); void setLoggingPath(std::string path) { - logging_path = path; + logging_path = Path(path); } std::string getLoggingPath() const { - return logging_path; + return logging_path.ToString(); } bool flush_to_file();