Skip to content

Commit

Permalink
logging: minor trace optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
Megamouse committed Jun 15, 2023
1 parent 0a22cab commit fd4d86d
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 17 deletions.
7 changes: 5 additions & 2 deletions rpcs3/Emu/Cell/PPUModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,12 @@ static void ppu_initialize_modules(ppu_linkage_info* link, utils::serial* ar = n
u32 alloc_addr = 0;

// "Use" all the modules for correct linkage
for (auto& _module : registered)
if (ppu_loader.trace)
{
ppu_loader.trace("Registered static module: %s", _module->name);
for (auto& _module : registered)
{
ppu_loader.trace("Registered static module: %s", _module->name);
}
}

struct hle_vars_save
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/PPUThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2267,7 +2267,7 @@ static T ppu_load_acquire_reservation(ppu_thread& ppu, u32 addr)
ppu.use_full_rdata = false;
}

if ((addr & addr_mask) == (ppu.last_faddr & addr_mask))
if (ppu_log.trace && (addr & addr_mask) == (ppu.last_faddr & addr_mask))
{
ppu_log.trace(u8"LARX after fail: addr=0x%x, faddr=0x%x, time=%u c", addr, ppu.last_faddr, (perf0.get() - ppu.last_ftsc));
}
Expand Down
18 changes: 18 additions & 0 deletions rpcs3/Emu/Cell/lv2/lv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ void fmt_class_string<lv2_protocol>::format(std::string& out, u64 arg)
});
}

template <>
void fmt_class_string<lv2_obj::name_64>::format(std::string& out, u64 arg)
{
out += lv2_obj::name64(get_object(arg).data);
}

static void null_func_(ppu_thread& ppu, ppu_opcode_t, be_t<u32>* this_op, ppu_intrp_func*)
{
ppu_log.todo("Unimplemented syscall %s -> CELL_OK (r3=0x%llx, r4=0x%llx, r5=0x%llx, r6=0x%llx, r7=0x%llx, r8=0x%llx, r9=0x%llx, r10=0x%llx)", ppu_syscall_code(ppu.gpr[11]),
Expand Down Expand Up @@ -1231,6 +1237,18 @@ namespace cpu_counter
void remove(cpu_thread*) noexcept;
}

std::string lv2_obj::name64(u64 name_u64)
{
const auto ptr = reinterpret_cast<const char*>(&name_u64);

// NTS string, ignore invalid/newline characters
// Example: "lv2\n\0tx" will be printed as "lv2"
std::string str{ptr, std::find(ptr, ptr + 7, '\0')};
str.erase(std::remove_if(str.begin(), str.end(), [](uchar c){ return !std::isprint(c); }), str.end());

return str;
}

bool lv2_obj::sleep(cpu_thread& cpu, const u64 timeout)
{
// Should already be performed when using this flag
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/lv2/sys_lwcond.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ error_code _sys_lwcond_create(ppu_thread& ppu, vm::ptr<u32> lwcond_id, u32 lwmut
{
ppu.state += cpu_flag::wait;

sys_lwcond.warning(u8"_sys_lwcond_create(lwcond_id=*0x%x, lwmutex_id=0x%x, control=*0x%x, name=0x%llx (“%s”))", lwcond_id, lwmutex_id, control, name, lv2_obj::name64(std::bit_cast<be_t<u64>>(name)));
sys_lwcond.warning(u8"_sys_lwcond_create(lwcond_id=*0x%x, lwmutex_id=0x%x, control=*0x%x, name=0x%llx (“%s”))", lwcond_id, lwmutex_id, control, name, lv2_obj::name_64{std::bit_cast<be_t<u64>>(name)});

u32 protocol;

Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/lv2/sys_lwmutex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ error_code _sys_lwmutex_create(ppu_thread& ppu, vm::ptr<u32> lwmutex_id, u32 pro
{
ppu.state += cpu_flag::wait;

sys_lwmutex.trace(u8"_sys_lwmutex_create(lwmutex_id=*0x%x, protocol=0x%x, control=*0x%x, has_name=0x%x, name=0x%llx (“%s”))", lwmutex_id, protocol, control, has_name, name, lv2_obj::name64(std::bit_cast<be_t<u64>>(name)));
sys_lwmutex.trace(u8"_sys_lwmutex_create(lwmutex_id=*0x%x, protocol=0x%x, control=*0x%x, has_name=0x%x, name=0x%llx (“%s”))", lwmutex_id, protocol, control, has_name, name, lv2_obj::name_64{std::bit_cast<be_t<u64>>(name)});

if (protocol != SYS_SYNC_FIFO && protocol != SYS_SYNC_RETRY && protocol != SYS_SYNC_PRIORITY)
{
Expand Down
14 changes: 5 additions & 9 deletions rpcs3/Emu/Cell/lv2/sys_sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,13 @@ struct lv2_obj
return ptr && ptr->exists;
}

static std::string name64(u64 name_u64)
// wrapper for name64 string formatting
struct name_64
{
const auto ptr = reinterpret_cast<const char*>(&name_u64);

// NTS string, ignore invalid/newline characters
// Example: "lv2\n\0tx" will be printed as "lv2"
std::string str{ptr, std::find(ptr, ptr + 7, '\0')};
str.erase(std::remove_if(str.begin(), str.end(), [](uchar c){ return !std::isprint(c); }), str.end());
u64 data;
};

return str;
}
static std::string name64(u64 name_u64);

// Find and remove the object from the linked list
template <bool ModifyNode = true, typename T>
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/NP/np_dnshook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ namespace np
s32 dnshook::analyze_dns_packet(s32 s, const u8* buf, u32 len)
{
std::lock_guard lock(mutex);

dnshook_log.trace("DNS REQUEST:\n%s", fmt::buf_to_hexstring(buf, len));

struct dns_header
Expand Down
3 changes: 2 additions & 1 deletion rpcs3/Emu/NP/np_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,8 @@ namespace np
}

local_ip_addr = client_addr.sin_addr.s_addr;
nph_log.trace("discover_ip_address: IP was determined to be %s", ip_to_string(local_ip_addr));
if (nph_log.trace)
nph_log.trace("discover_ip_address: IP was determined to be %s", ip_to_string(local_ip_addr));
close_socket();
return true;
}
Expand Down
3 changes: 2 additions & 1 deletion rpcs3/Emu/RSX/rsx_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@ namespace rsx

if ((location & ~7) != (CELL_GCM_CONTEXT_DMA_NOTIFY_MAIN_0 & ~7))
{
rsx_log.trace("NV4097_NOTIFY: invalid context = 0x%x", method_registers.context_dma_notify());
if (rsx_log.trace)
rsx_log.trace("NV4097_NOTIFY: invalid context = 0x%x", method_registers.context_dma_notify());
return;
}

Expand Down

0 comments on commit fd4d86d

Please sign in to comment.