Print LV2 Syscall Usage only if increased since last print

This commit is contained in:
Eladash 2023-01-28 10:43:35 +02:00 committed by Megamouse
parent 18ab42dc83
commit 5aced2e44b

View File

@ -1093,21 +1093,23 @@ class ppu_syscall_usage
{
// Internal buffer
std::string m_stats;
u64 m_old_stat[1024]{};
public:
// Public info collection buffers
atomic_t<u64> stat[1024]{};
void print_stats() noexcept
void print_stats(bool force_print) noexcept
{
std::multimap<u64, u64, std::greater<u64>> usage;
for (u32 i = 0; i < 1024; i++)
{
if (u64 v = stat[i])
if (u64 v = stat[i]; m_old_stat[i] != v || (force_print && v))
{
// Only add syscalls with non-zero usage counter
// Only add syscalls with non-zero usage counter and only if caught new calls since last print
usage.emplace(v, i);
m_old_stat[i] = v;
}
}
@ -1118,27 +1120,36 @@ public:
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);
if (!m_stats.empty())
{
ppu_log.notice("PPU Syscall Usage Stats: %s", m_stats);
}
}
void operator()()
{
while (thread_ctrl::state() != thread_state::aborting)
bool was_paused = false;
for (u32 i = 1; thread_ctrl::state() != thread_state::aborting; i++)
{
thread_ctrl::wait_for(10000'000);
thread_ctrl::wait_for(1'000'000);
if (Emu.IsPaused())
const bool is_paused = Emu.IsPaused();
// Force-print all if paused
const bool force_print = is_paused && !was_paused;
if (force_print || i % 10 == 0)
{
continue;
was_paused = is_paused;
print_stats(force_print);
}
print_stats();
}
}
~ppu_syscall_usage()
{
print_stats();
print_stats(true);
}
static constexpr auto thread_name = "PPU Syscall Usage Thread"sv;