From 3105b21909837f223207c461adfa0eb94286061b Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Mon, 2 Mar 2020 20:17:48 +0300 Subject: [PATCH] Print PPU Syscall Usage Stats * Every 10 seconds * On normal exit --- rpcs3/Emu/Cell/PPUThread.cpp | 4 +-- rpcs3/Emu/Cell/lv2/lv2.cpp | 56 ++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/rpcs3/Emu/Cell/PPUThread.cpp b/rpcs3/Emu/Cell/PPUThread.cpp index 458633ca289a..319226c864f3 100644 --- a/rpcs3/Emu/Cell/PPUThread.cpp +++ b/rpcs3/Emu/Cell/PPUThread.cpp @@ -1374,8 +1374,8 @@ extern void ppu_initialize(const ppu_module& info) { if (auto sc = ppu_get_syscall(index)) { - link_table.emplace(fmt::format("%s", ppu_syscall_code(index)), reinterpret_cast(sc)); - link_table.emplace(fmt::format("syscall_%u", index), reinterpret_cast(sc)); + link_table.emplace(fmt::format("%s", ppu_syscall_code(index)), reinterpret_cast(ppu_execute_syscall)); + link_table.emplace(fmt::format("syscall_%u", index), reinterpret_cast(ppu_execute_syscall)); } } diff --git a/rpcs3/Emu/Cell/lv2/lv2.cpp b/rpcs3/Emu/Cell/lv2/lv2.cpp index 65ab86cf617a..7b2ea967b06c 100644 --- a/rpcs3/Emu/Cell/lv2/lv2.cpp +++ b/rpcs3/Emu/Cell/lv2/lv2.cpp @@ -985,10 +985,66 @@ extern void ppu_initialize_syscalls() g_ppu_syscall_table = s_ppu_syscall_table; } +class ppu_syscall_usage +{ + // Internal buffer + std::string m_stats; + +public: + // Public info collection buffers + atomic_t stat[1024]{}; + + void print_stats() noexcept + { + std::multimap> usage; + + for (u32 i = 0; i < 1024; i++) + { + if (u64 v = stat[i]) + { + // Only add syscalls with non-zero usage counter + usage.emplace(v, i); + } + } + + m_stats.clear(); + + for (auto&& pair : usage) + { + fmt::append(m_stats, u8"\n\t⁂ %s [%u]", ppu_get_syscall_name(pair.second), pair.first); + } + + ppu_log.notice("PPU Syscall Usage Stats: %s", m_stats); + } + + void operator()() + { + while (thread_ctrl::state() != thread_state::aborting) + { + std::this_thread::sleep_for(10s); + print_stats(); + } + } + + ~ppu_syscall_usage() + { + print_stats(); + } + + static constexpr auto thread_name = "PPU Syscall Usage Thread"sv; +}; + extern void ppu_execute_syscall(ppu_thread& ppu, u64 code) { + if (g_cfg.core.ppu_decoder == ppu_decoder_type::llvm) + { + code = ppu.gpr[11]; + } + if (code < g_ppu_syscall_table.size()) { + g_fxo->get>()->stat[code]++; + if (auto func = g_ppu_syscall_table[code]) { func(ppu);