Skip to content

Commit

Permalink
Switched to PPSSPP's C file-stream API
Browse files Browse the repository at this point in the history
  • Loading branch information
Nemoumbra committed Sep 13, 2024
1 parent 27e59b1 commit 9e3c6ea
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
12 changes: 6 additions & 6 deletions Core/MIPS/MIPSTracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
}
}

Expand Down
10 changes: 6 additions & 4 deletions Core/MIPS/MIPSTracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand Down

0 comments on commit 9e3c6ea

Please sign in to comment.