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) if (!f)
f.Open("log64.txt", "w"); 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()) if (been_here.find(PC) != been_here.end())
{ {

View File

@ -16,6 +16,8 @@
#include "Common/PerformanceCounter.h" #include "Common/PerformanceCounter.h"
#endif #endif
#include <fmt/format.h>
#include "Common/ChunkFile.h" #include "Common/ChunkFile.h"
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/File.h" #include "Common/File.h"
@ -103,17 +105,19 @@ void WriteProfileResults(const std::string& filename)
PanicAlert("Failed to open %s", filename.c_str()); PanicAlert("Failed to open %s", filename.c_str());
return; return;
} }
fprintf(f.GetHandle(), "origAddr\tblkName\trunCount\tcost\ttimeCost\tpercent\ttimePercent\tOvAlli" f.WriteString("origAddr\tblkName\trunCount\tcost\ttimeCost\tpercent\ttimePercent\tOvAllinBlkTime("
"nBlkTime(ms)\tblkCodeSize\n"); "ms)\tblkCodeSize\n");
for (auto& stat : prof_stats.block_stats) for (auto& stat : prof_stats.block_stats)
{ {
std::string name = g_symbolDB.GetDescription(stat.addr); std::string name = g_symbolDB.GetDescription(stat.addr);
double percent = 100.0 * (double)stat.cost / (double)prof_stats.cost_sum; 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; double timePercent = 100.0 * (double)stat.tick_counter / (double)prof_stats.timecost_sum;
fprintf(f.GetHandle(), 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",
"%08x\t%s\t%" PRIu64 "\t%" PRIu64 "\t%" PRIu64 "\t%.2f\t%.2f\t%.2f\t%i\n", stat.addr, stat.addr, name, stat.run_count, stat.cost, stat.tick_counter,
name.c_str(), stat.run_count, stat.cost, stat.tick_counter, percent, timePercent, percent, timePercent,
(double)stat.tick_counter * 1000.0 / (double)prof_stats.countsPerSec, stat.block_size); 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 <utility>
#include <vector> #include <vector>
#include <fmt/format.h>
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/File.h" #include "Common/File.h"
#include "Common/Logging/Log.h" #include "Common/Logging/Log.h"
@ -438,21 +440,21 @@ bool PPCSymbolDB::SaveSymbolMap(const std::string& filename) const
} }
// Write .text section // Write .text section
fprintf(f.GetHandle(), ".text section layout\n"); f.WriteString(".text section layout\n");
for (const auto& symbol : function_symbols) for (const auto& symbol : function_symbols)
{ {
// Write symbol address, size, virtual address, alignment, name // Write symbol address, size, virtual address, alignment, name
fprintf(f.GetHandle(), "%08x %08x %08x %i %s\n", symbol->address, symbol->size, symbol->address, f.WriteString(fmt::format("{0:08x} {1:08x} {2:08x} {3} {4}\n", symbol->address, symbol->size,
0, symbol->name.c_str()); symbol->address, 0, symbol->name));
} }
// Write .data section // Write .data section
fprintf(f.GetHandle(), "\n.data section layout\n"); f.WriteString("\n.data section layout\n");
for (const auto& symbol : data_symbols) for (const auto& symbol : data_symbols)
{ {
// Write symbol address, size, virtual address, alignment, name // Write symbol address, size, virtual address, alignment, name
fprintf(f.GetHandle(), "%08x %08x %08x %i %s\n", symbol->address, symbol->size, symbol->address, f.WriteString(fmt::format("{0:08x} {1:08x} {2:08x} {3} {4}\n", symbol->address, symbol->size,
0, symbol->name.c_str()); symbol->address, 0, symbol->name));
} }
return true; return true;
@ -471,7 +473,7 @@ bool PPCSymbolDB::SaveCodeMap(const std::string& filename) const
return false; return false;
// Write ".text" at the top // Write ".text" at the top
fprintf(f.GetHandle(), ".text\n"); f.WriteString(".text\n");
u32 next_address = 0; u32 next_address = 0;
for (const auto& function : m_functions) 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) if (symbol.address + symbol.size <= next_address)
{ {
// At least write the symbol name and 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; continue;
} }
// Write the symbol full name // 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; next_address = symbol.address + symbol.size;
// Write the code // Write the code
for (u32 address = symbol.address; address < next_address; address += 4) for (u32 address = symbol.address; address < next_address; address += 4)
{ {
const std::string disasm = debugger->Disassemble(address); const std::string disasm = debugger->Disassemble(address);
fprintf(f.GetHandle(), "%08x %-*.*s %s\n", address, SYMBOL_NAME_LIMIT, SYMBOL_NAME_LIMIT, f.WriteString(fmt::format("{0:08x} {1:<{2}.{3}} {4}\n", address, symbol.name,
symbol.name.c_str(), disasm.c_str()); SYMBOL_NAME_LIMIT, SYMBOL_NAME_LIMIT, disasm));
} }
} }
return true; return true;

View File

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

View File

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