Compare commits

...

2 Commits

Author SHA1 Message Date
Eladash 8e15de5c83 sys_tty: Try to avoid logging single newlines to log 2024-03-07 14:31:41 +02:00
Eladash 69a90ef9e7 rsx/cpu_thread: Fix cpu_thread::get_name() for RSX 2024-03-07 14:31:41 +02:00
2 changed files with 60 additions and 9 deletions

View File

@ -1072,17 +1072,31 @@ void cpu_thread::add_remove_flags(bs_t<cpu_flag> to_add, bs_t<cpu_flag> to_remov
std::string cpu_thread::get_name() const std::string cpu_thread::get_name() const
{ {
// Downcast to correct type // Downcast to correct type
if (id_type() == 1) switch (id_type())
{
case 1:
{ {
return thread_ctrl::get_name(*static_cast<const named_thread<ppu_thread>*>(this)); return thread_ctrl::get_name(*static_cast<const named_thread<ppu_thread>*>(this));
} }
case 2:
if (id_type() == 2)
{ {
return thread_ctrl::get_name(*static_cast<const named_thread<spu_thread>*>(this)); return thread_ctrl::get_name(*static_cast<const named_thread<spu_thread>*>(this));
} }
default:
{
if (cpu_thread::get_current() == this && thread_ctrl::get_current())
{
return thread_ctrl::get_name();
}
fmt::throw_exception("Invalid cpu_thread type"); if (id_type() == 0x55)
{
return fmt::format("rsx::thread");
}
return fmt::format("Invalid cpu_thread type (0x%x)", id_type());
}
}
} }
u32 cpu_thread::get_pc() const u32 cpu_thread::get_pc() const

View File

@ -108,14 +108,34 @@ error_code sys_tty_write([[maybe_unused]] ppu_thread& ppu, s32 ch, vm::cptr<char
} }
} }
if (msg.find("abort"sv) != umax || msg.find("error"sv) != umax || [&]() auto find_word = [](std::string_view msg, std::string_view word) -> bool
{ {
static atomic_t<u64> last_write = 0; // Match uppercase and lowercase starting words
const usz index = msg.find(word.substr(1));
if (index != umax && index >= 1u)
{
return std::tolower(static_cast<u8>(msg[index - 1])) == word[0];
}
return false;
};
std::string_view sample = std::string_view(msg).substr(0, 1024);
const bool warning = find_word(sample, "failed"sv) || find_word(sample, "abort"sv) || find_word(sample, "crash"sv)
|| find_word(sample, "error"sv) || find_word(sample, "unexpected"sv) || find_word(sample, "0x8001"sv);
sample = {}; // Remove reference to string
if (msg.size() >= 2u && ([&]()
{
static thread_local u64 last_write = 0;
// Dump thread about every period which TTY was not being touched for about half a second // Dump thread about every period which TTY was not being touched for about half a second
const u64 current = get_system_time(); const u64 current = get_system_time();
return current - last_write.exchange(current) >= 500'000; return current - std::exchange(last_write, current) >= 3'000'000;
}()) }() || warning))
{ {
ppu_log.notice("\n%s", dump_useful_thread_info()); ppu_log.notice("\n%s", dump_useful_thread_info());
} }
@ -143,7 +163,24 @@ error_code sys_tty_write([[maybe_unused]] ppu_thread& ppu, s32 ch, vm::cptr<char
{ {
if (!msg.empty()) if (!msg.empty())
{ {
sys_tty.notice(u8"sys_tty_write(): “%s”", msg); if (msg.ends_with("\n"))
{
// Avoid logging trailing newlines, log them verbosely instead
const std::string_view msg_clear = std::string_view(msg).substr(0, msg.find_last_not_of('\n') + 1);
if (msg.size() - 1 == msg_clear.size())
{
(warning ? sys_tty.warning : sys_tty.notice)(u8"sys_tty_write(): “%s“ << endl", msg_clear);
}
else
{
(warning ? sys_tty.warning : sys_tty.notice)(u8"sys_tty_write(): “%s” << endl(%u)", msg_clear, msg.size() - msg_clear.size());
}
}
else
{
(warning ? sys_tty.warning : sys_tty.notice)(u8"sys_tty_write(): “%s”", msg);
}
if (g_tty) if (g_tty)
{ {