Log TTY output after emulation have been stopped

This commit is contained in:
Elad Ashkenazi 2023-07-26 16:25:33 +03:00
parent 106f31db6a
commit 5d98f3866c
2 changed files with 28 additions and 0 deletions

View File

@ -2125,6 +2125,8 @@ void Emulator::Run(bool start_playtime)
m_pause_start_time = 0; m_pause_start_time = 0;
m_pause_amend_time = 0; m_pause_amend_time = 0;
m_tty_file_init_pos = g_tty ? g_tty.pos() : usz{umax};
rpcs3::utils::configure_logs(); rpcs3::utils::configure_logs();
m_state = system_state::starting; m_state = system_state::starting;
@ -2957,6 +2959,30 @@ void Emulator::Kill(bool allow_autoexit, bool savestate)
m_state = system_state::stopped; m_state = system_state::stopped;
GetCallbacks().on_stop(); GetCallbacks().on_stop();
if (g_tty)
{
// Write merged TTY output after emulation has been safely stopped
if (usz attempted_read_size = utils::sub_saturate<usz>(g_tty.pos(), m_tty_file_init_pos))
{
if (fs::file tty_read_fd{fs::get_cache_dir() + "TTY.log"})
{
// Enfore an arbitrary limit for now to avoid OOM in case the guest code has bombarded TTY
// 16MB, this should be enough
constexpr usz c_max_tty_spill_size = 0x10'0000;
std::string tty_buffer(std::min<usz>(attempted_read_size, c_max_tty_spill_size), '\0');
tty_buffer.resize(tty_read_fd.read_at(m_tty_file_init_pos, tty_buffer.data(), tty_buffer.size()));
if (!tty_buffer.empty())
{
// Mark start and end very clearly with RPCS3 put in it
sys_log.notice("\nAccumulated RPCS3 TTY:\n\n\n%s\n\n\nEnd RPCS3 TTY Section.\n", tty_buffer);
}
}
}
}
// Always Enable display sleep, not only if it was prevented. // Always Enable display sleep, not only if it was prevented.
enable_display_sleep(); enable_display_sleep();

View File

@ -139,6 +139,8 @@ class Emulator final
bool m_state_inspection_savestate = false; bool m_state_inspection_savestate = false;
usz m_tty_file_init_pos = umax;
std::vector<std::shared_ptr<atomic_t<u32>>> m_pause_msgs_refs; std::vector<std::shared_ptr<atomic_t<u32>>> m_pause_msgs_refs;
std::vector<std::function<void()>> deferred_deserialization; std::vector<std::function<void()>> deferred_deserialization;