Skip to content

Commit

Permalink
Print PPU Syscall Usage Stats
Browse files Browse the repository at this point in the history
* Every 10 seconds
* On normal exit
  • Loading branch information
Nekotekina committed Mar 2, 2020
1 parent d94b875 commit d6189cf
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
4 changes: 2 additions & 2 deletions rpcs3/Emu/Cell/PPUThread.cpp
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 (stat[i].raw() > 0)
{
// Only add syscalls with non-zero usage counter
usage.emplace(stat[i].raw(), i);
}
}

m_stats.clear();

for (auto&& pair : usage)
{
fmt::append(m_stats, "\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

0 comments on commit d6189cf

Please sign in to comment.