Step MemoryWatcher at end of each video frame.
This commit is contained in:
parent
f4d950f4e2
commit
239af3cdf9
|
@ -98,6 +98,10 @@ static bool s_request_refresh_info = false;
|
||||||
static bool s_is_throttler_temp_disabled = false;
|
static bool s_is_throttler_temp_disabled = false;
|
||||||
static bool s_frame_step = false;
|
static bool s_frame_step = false;
|
||||||
|
|
||||||
|
#ifdef USE_MEMORYWATCHER
|
||||||
|
static std::unique_ptr<MemoryWatcher> s_memory_watcher;
|
||||||
|
#endif
|
||||||
|
|
||||||
struct HostJob
|
struct HostJob
|
||||||
{
|
{
|
||||||
std::function<void()> job;
|
std::function<void()> job;
|
||||||
|
@ -126,6 +130,13 @@ void FrameUpdateOnCPUThread()
|
||||||
NetPlay::NetPlayClient::SendTimeBase();
|
NetPlay::NetPlayClient::SendTimeBase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OnFrameEnd()
|
||||||
|
{
|
||||||
|
#ifdef USE_MEMORYWATCHER
|
||||||
|
s_memory_watcher->Step();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
// Display messages and return values
|
// Display messages and return values
|
||||||
|
|
||||||
// Formatted stop message
|
// Formatted stop message
|
||||||
|
@ -272,7 +283,7 @@ void Stop() // - Hammertime!
|
||||||
ResetRumble();
|
ResetRumble();
|
||||||
|
|
||||||
#ifdef USE_MEMORYWATCHER
|
#ifdef USE_MEMORYWATCHER
|
||||||
MemoryWatcher::Shutdown();
|
s_memory_watcher.reset();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -317,7 +328,7 @@ static void CpuThread(const std::optional<std::string>& savestate_path, bool del
|
||||||
EMM::InstallExceptionHandler(); // Let's run under memory watch
|
EMM::InstallExceptionHandler(); // Let's run under memory watch
|
||||||
|
|
||||||
#ifdef USE_MEMORYWATCHER
|
#ifdef USE_MEMORYWATCHER
|
||||||
MemoryWatcher::Init();
|
s_memory_watcher = std::make_unique<MemoryWatcher>();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (savestate_path)
|
if (savestate_path)
|
||||||
|
|
|
@ -66,6 +66,7 @@ void Callback_WiimoteInterruptChannel(int number, u16 channel_id, const u8* data
|
||||||
void DisplayMessage(const std::string& message, int time_in_ms);
|
void DisplayMessage(const std::string& message, int time_in_ms);
|
||||||
|
|
||||||
void FrameUpdateOnCPUThread();
|
void FrameUpdateOnCPUThread();
|
||||||
|
void OnFrameEnd();
|
||||||
|
|
||||||
void VideoThrottle();
|
void VideoThrottle();
|
||||||
void RequestRefreshInfo();
|
void RequestRefreshInfo();
|
||||||
|
|
|
@ -726,6 +726,7 @@ static void BeginField(FieldType field, u64 ticks)
|
||||||
static void EndField()
|
static void EndField()
|
||||||
{
|
{
|
||||||
Core::VideoThrottle();
|
Core::VideoThrottle();
|
||||||
|
Core::OnFrameEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Purpose: Send VI interrupt when triggered
|
// Purpose: Send VI interrupt when triggered
|
||||||
|
|
|
@ -4,39 +4,14 @@
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <memory>
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "Common/FileUtil.h"
|
#include "Common/FileUtil.h"
|
||||||
#include "Core/CoreTiming.h"
|
|
||||||
#include "Core/HW/Memmap.h"
|
#include "Core/HW/Memmap.h"
|
||||||
#include "Core/HW/SystemTimers.h"
|
#include "Core/HW/SystemTimers.h"
|
||||||
#include "Core/MemoryWatcher.h"
|
#include "Core/MemoryWatcher.h"
|
||||||
|
|
||||||
static std::unique_ptr<MemoryWatcher> s_memory_watcher;
|
|
||||||
static CoreTiming::EventType* s_event;
|
|
||||||
static const int MW_RATE = 600; // Steps per second
|
|
||||||
|
|
||||||
static void MWCallback(u64 userdata, s64 cyclesLate)
|
|
||||||
{
|
|
||||||
s_memory_watcher->Step();
|
|
||||||
CoreTiming::ScheduleEvent(SystemTimers::GetTicksPerSecond() / MW_RATE - cyclesLate, s_event);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MemoryWatcher::Init()
|
|
||||||
{
|
|
||||||
s_memory_watcher = std::make_unique<MemoryWatcher>();
|
|
||||||
s_event = CoreTiming::RegisterEvent("MemoryWatcher", MWCallback);
|
|
||||||
CoreTiming::ScheduleEvent(0, s_event);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MemoryWatcher::Shutdown()
|
|
||||||
{
|
|
||||||
CoreTiming::RemoveEvent(s_event);
|
|
||||||
s_memory_watcher.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
MemoryWatcher::MemoryWatcher()
|
MemoryWatcher::MemoryWatcher()
|
||||||
{
|
{
|
||||||
m_running = false;
|
m_running = false;
|
||||||
|
@ -84,7 +59,6 @@ void MemoryWatcher::ParseLine(const std::string& line)
|
||||||
|
|
||||||
bool MemoryWatcher::OpenSocket(const std::string& path)
|
bool MemoryWatcher::OpenSocket(const std::string& path)
|
||||||
{
|
{
|
||||||
memset(&m_addr, 0, sizeof(m_addr));
|
|
||||||
m_addr.sun_family = AF_UNIX;
|
m_addr.sun_family = AF_UNIX;
|
||||||
strncpy(m_addr.sun_path, path.c_str(), sizeof(m_addr.sun_path) - 1);
|
strncpy(m_addr.sun_path, path.c_str(), sizeof(m_addr.sun_path) - 1);
|
||||||
|
|
||||||
|
@ -100,17 +74,10 @@ u32 MemoryWatcher::ChasePointer(const std::string& line)
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MemoryWatcher::ComposeMessage(const std::string& line, u32 value)
|
std::string MemoryWatcher::ComposeMessages()
|
||||||
{
|
{
|
||||||
std::stringstream message_stream;
|
std::stringstream message_stream;
|
||||||
message_stream << line << '\n' << std::hex << value;
|
message_stream << std::hex;
|
||||||
return message_stream.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MemoryWatcher::Step()
|
|
||||||
{
|
|
||||||
if (!m_running)
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (auto& entry : m_values)
|
for (auto& entry : m_values)
|
||||||
{
|
{
|
||||||
|
@ -122,9 +89,19 @@ void MemoryWatcher::Step()
|
||||||
{
|
{
|
||||||
// Update the value
|
// Update the value
|
||||||
current_value = new_value;
|
current_value = new_value;
|
||||||
std::string message = ComposeMessage(address, new_value);
|
message_stream << address << '\n' << new_value << '\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return message_stream.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MemoryWatcher::Step()
|
||||||
|
{
|
||||||
|
if (!m_running)
|
||||||
|
return;
|
||||||
|
|
||||||
|
std::string message = ComposeMessages();
|
||||||
sendto(m_fd, message.c_str(), message.size() + 1, 0, reinterpret_cast<sockaddr*>(&m_addr),
|
sendto(m_fd, message.c_str(), message.size() + 1, 0, reinterpret_cast<sockaddr*>(&m_addr),
|
||||||
sizeof(m_addr));
|
sizeof(m_addr));
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,21 +24,18 @@ public:
|
||||||
~MemoryWatcher();
|
~MemoryWatcher();
|
||||||
void Step();
|
void Step();
|
||||||
|
|
||||||
static void Init();
|
|
||||||
static void Shutdown();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool LoadAddresses(const std::string& path);
|
bool LoadAddresses(const std::string& path);
|
||||||
bool OpenSocket(const std::string& path);
|
bool OpenSocket(const std::string& path);
|
||||||
|
|
||||||
void ParseLine(const std::string& line);
|
void ParseLine(const std::string& line);
|
||||||
u32 ChasePointer(const std::string& line);
|
u32 ChasePointer(const std::string& line);
|
||||||
std::string ComposeMessage(const std::string& line, u32 value);
|
std::string ComposeMessages();
|
||||||
|
|
||||||
bool m_running;
|
bool m_running = false;
|
||||||
|
|
||||||
int m_fd;
|
int m_fd;
|
||||||
sockaddr_un m_addr;
|
sockaddr_un m_addr{};
|
||||||
|
|
||||||
// Address as stored in the file -> list of offsets to follow
|
// Address as stored in the file -> list of offsets to follow
|
||||||
std::map<std::string, std::vector<u32>> m_addresses;
|
std::map<std::string, std::vector<u32>> m_addresses;
|
||||||
|
|
Loading…
Reference in New Issue