Skip to content

Commit

Permalink
Log TTY output after emulation have been stopped
Browse files Browse the repository at this point in the history
  • Loading branch information
elad335 committed Jul 26, 2023
1 parent 106f31d commit 5d98f38
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
26 changes: 26 additions & 0 deletions rpcs3/Emu/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2125,6 +2125,8 @@ void Emulator::Run(bool start_playtime)
m_pause_start_time = 0;
m_pause_amend_time = 0;

m_tty_file_init_pos = g_tty ? g_tty.pos() : usz{umax};

rpcs3::utils::configure_logs();

m_state = system_state::starting;
Expand Down Expand Up @@ -2957,6 +2959,30 @@ void Emulator::Kill(bool allow_autoexit, bool savestate)
m_state = system_state::stopped;
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.
enable_display_sleep();

Expand Down
2 changes: 2 additions & 0 deletions rpcs3/Emu/System.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ class Emulator final

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::function<void()>> deferred_deserialization;
Expand Down

0 comments on commit 5d98f38

Please sign in to comment.