Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print PPU Syscall Usage Stats #7671

Merged
merged 1 commit into from Mar 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions rpcs3/Emu/Cell/PPUThread.cpp
Expand Up @@ -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<u64>(sc));
link_table.emplace(fmt::format("syscall_%u", index), reinterpret_cast<u64>(sc));
link_table.emplace(fmt::format("%s", ppu_syscall_code(index)), reinterpret_cast<u64>(ppu_execute_syscall));
link_table.emplace(fmt::format("syscall_%u", index), reinterpret_cast<u64>(ppu_execute_syscall));
}
}

Expand Down
56 changes: 56 additions & 0 deletions rpcs3/Emu/Cell/lv2/lv2.cpp
Expand Up @@ -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<u64> stat[1024]{};

void print_stats() noexcept
{
std::multimap<u64, u64, std::greater<u64>> 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<named_thread<ppu_syscall_usage>>()->stat[code]++;

if (auto func = g_ppu_syscall_table[code])
{
func(ppu);
Expand Down