IOFile: Replace all fprintf string writing with calls to WriteString.

This commit is contained in:
Admiral H. Curtiss 2020-11-25 03:00:20 +01:00
parent 9c590e215f
commit 45d4746a5d
5 changed files with 34 additions and 26 deletions

View File

@ -473,7 +473,7 @@ static void ImHere()
if (!f)
f.Open("log64.txt", "w");
fprintf(f.GetHandle(), "%08x\n", PC);
f.WriteString(fmt::format("{0:08x}\n", PC));
}
if (been_here.find(PC) != been_here.end())
{

View File

@ -16,6 +16,8 @@
#include "Common/PerformanceCounter.h"
#endif
#include <fmt/format.h>
#include "Common/ChunkFile.h"
#include "Common/CommonTypes.h"
#include "Common/File.h"
@ -103,17 +105,19 @@ void WriteProfileResults(const std::string& filename)
PanicAlert("Failed to open %s", filename.c_str());
return;
}
fprintf(f.GetHandle(), "origAddr\tblkName\trunCount\tcost\ttimeCost\tpercent\ttimePercent\tOvAlli"
"nBlkTime(ms)\tblkCodeSize\n");
f.WriteString("origAddr\tblkName\trunCount\tcost\ttimeCost\tpercent\ttimePercent\tOvAllinBlkTime("
"ms)\tblkCodeSize\n");
for (auto& stat : prof_stats.block_stats)
{
std::string name = g_symbolDB.GetDescription(stat.addr);
double percent = 100.0 * (double)stat.cost / (double)prof_stats.cost_sum;
double timePercent = 100.0 * (double)stat.tick_counter / (double)prof_stats.timecost_sum;
fprintf(f.GetHandle(),
"%08x\t%s\t%" PRIu64 "\t%" PRIu64 "\t%" PRIu64 "\t%.2f\t%.2f\t%.2f\t%i\n", stat.addr,
name.c_str(), stat.run_count, stat.cost, stat.tick_counter, percent, timePercent,
(double)stat.tick_counter * 1000.0 / (double)prof_stats.countsPerSec, stat.block_size);
f.WriteString(fmt::format("{0:08x}\t{1}\t{2}\t{3}\t{4}\t{5:.2f}\t{6:.2f}\t{7:.2f}\t{8}\n",
stat.addr, name, stat.run_count, stat.cost, stat.tick_counter,
percent, timePercent,
static_cast<double>(stat.tick_counter) * 1000.0 /
static_cast<double>(prof_stats.countsPerSec),
stat.block_size));
}
}

View File

@ -12,6 +12,8 @@
#include <utility>
#include <vector>
#include <fmt/format.h>
#include "Common/CommonTypes.h"
#include "Common/File.h"
#include "Common/Logging/Log.h"
@ -438,21 +440,21 @@ bool PPCSymbolDB::SaveSymbolMap(const std::string& filename) const
}
// Write .text section
fprintf(f.GetHandle(), ".text section layout\n");
f.WriteString(".text section layout\n");
for (const auto& symbol : function_symbols)
{
// Write symbol address, size, virtual address, alignment, name
fprintf(f.GetHandle(), "%08x %08x %08x %i %s\n", symbol->address, symbol->size, symbol->address,
0, symbol->name.c_str());
f.WriteString(fmt::format("{0:08x} {1:08x} {2:08x} {3} {4}\n", symbol->address, symbol->size,
symbol->address, 0, symbol->name));
}
// Write .data section
fprintf(f.GetHandle(), "\n.data section layout\n");
f.WriteString("\n.data section layout\n");
for (const auto& symbol : data_symbols)
{
// Write symbol address, size, virtual address, alignment, name
fprintf(f.GetHandle(), "%08x %08x %08x %i %s\n", symbol->address, symbol->size, symbol->address,
0, symbol->name.c_str());
f.WriteString(fmt::format("{0:08x} {1:08x} {2:08x} {3} {4}\n", symbol->address, symbol->size,
symbol->address, 0, symbol->name));
}
return true;
@ -471,7 +473,7 @@ bool PPCSymbolDB::SaveCodeMap(const std::string& filename) const
return false;
// Write ".text" at the top
fprintf(f.GetHandle(), ".text\n");
f.WriteString(".text\n");
u32 next_address = 0;
for (const auto& function : m_functions)
@ -482,20 +484,20 @@ bool PPCSymbolDB::SaveCodeMap(const std::string& filename) const
if (symbol.address + symbol.size <= next_address)
{
// At least write the symbol name and address
fprintf(f.GetHandle(), "// %08x beginning of %s\n", symbol.address, symbol.name.c_str());
f.WriteString(fmt::format("// {0:08x} beginning of {1}\n", symbol.address, symbol.name));
continue;
}
// Write the symbol full name
fprintf(f.GetHandle(), "\n%s:\n", symbol.name.c_str());
f.WriteString(fmt::format("\n{0}:\n", symbol.name));
next_address = symbol.address + symbol.size;
// Write the code
for (u32 address = symbol.address; address < next_address; address += 4)
{
const std::string disasm = debugger->Disassemble(address);
fprintf(f.GetHandle(), "%08x %-*.*s %s\n", address, SYMBOL_NAME_LIMIT, SYMBOL_NAME_LIMIT,
symbol.name.c_str(), disasm.c_str());
f.WriteString(fmt::format("{0:08x} {1:<{2}.{3}} {4}\n", address, symbol.name,
SYMBOL_NAME_LIMIT, SYMBOL_NAME_LIMIT, disasm));
}
}
return true;

View File

@ -171,8 +171,8 @@ void LogCompiledInstructions()
GekkoOPInfo* pInst = m_allInstructions[i];
if (pInst->compileCount > 0)
{
fprintf(f.GetHandle(), "%s\t%i\t%" PRId64 "\t%08x\n", pInst->opname, pInst->compileCount,
pInst->runCount, pInst->lastUse);
f.WriteString(fmt::format("{0}\t{1}\t{2}\t{3:08x}\n", pInst->opname, pInst->compileCount,
pInst->runCount, pInst->lastUse));
}
}
@ -182,8 +182,8 @@ void LogCompiledInstructions()
GekkoOPInfo* pInst = m_allInstructions[i];
if (pInst->compileCount == 0)
{
fprintf(f.GetHandle(), "%s\t%i\t%" PRId64 "\n", pInst->opname, pInst->compileCount,
pInst->runCount);
f.WriteString(
fmt::format("{0}\t{1}\t{2}\n", pInst->opname, pInst->compileCount, pInst->runCount));
}
}
@ -191,7 +191,7 @@ void LogCompiledInstructions()
f.Open(fmt::format("{}" OP_TO_LOG "_at{}.txt", File::GetUserPath(D_LOGS_IDX), time), "w");
for (auto& rsplocation : rsplocations)
{
fprintf(f.GetHandle(), OP_TO_LOG ": %08x\n", rsplocation);
f.WriteString(fmt::format(OP_TO_LOG ": {0:08x}\n", rsplocation));
}
#endif

View File

@ -8,6 +8,8 @@
#include <fstream>
#include <sstream>
#include <fmt/format.h>
#include "Common/File.h"
#include "Common/FileUtil.h"
#include "Common/Logging/Log.h"
@ -70,9 +72,9 @@ bool CSVSignatureDB::Save(const std::string& file_path) const
{
// The object name/location are unused for the time being.
// To be implemented.
fprintf(f.GetHandle(), "%08x\t%08x\t%s\t%s\t%s\n", func.first, func.second.size,
func.second.name.c_str(), func.second.object_location.c_str(),
func.second.object_name.c_str());
f.WriteString(fmt::format("{0:08x}\t{1:08x}\t{2}\t{3}\t{4}\n", func.first, func.second.size,
func.second.name, func.second.object_location,
func.second.object_name));
}
INFO_LOG(SYMBOLS, "CSV database save successful");