Step MemoryWatcher at end of each video frame.

This commit is contained in:
Vlad Firoiu 2017-02-25 20:58:33 -08:00
parent f4d950f4e2
commit 239af3cdf9
5 changed files with 33 additions and 46 deletions

View File

@ -98,6 +98,10 @@ static bool s_request_refresh_info = false;
static bool s_is_throttler_temp_disabled = false;
static bool s_frame_step = false;
#ifdef USE_MEMORYWATCHER
static std::unique_ptr<MemoryWatcher> s_memory_watcher;
#endif
struct HostJob
{
std::function<void()> job;
@ -126,6 +130,13 @@ void FrameUpdateOnCPUThread()
NetPlay::NetPlayClient::SendTimeBase();
}
void OnFrameEnd()
{
#ifdef USE_MEMORYWATCHER
s_memory_watcher->Step();
#endif
}
// Display messages and return values
// Formatted stop message
@ -272,7 +283,7 @@ void Stop() // - Hammertime!
ResetRumble();
#ifdef USE_MEMORYWATCHER
MemoryWatcher::Shutdown();
s_memory_watcher.reset();
#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
#ifdef USE_MEMORYWATCHER
MemoryWatcher::Init();
s_memory_watcher = std::make_unique<MemoryWatcher>();
#endif
if (savestate_path)

View File

@ -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 FrameUpdateOnCPUThread();
void OnFrameEnd();
void VideoThrottle();
void RequestRefreshInfo();

View File

@ -726,6 +726,7 @@ static void BeginField(FieldType field, u64 ticks)
static void EndField()
{
Core::VideoThrottle();
Core::OnFrameEnd();
}
// Purpose: Send VI interrupt when triggered

View File

@ -4,39 +4,14 @@
#include <fstream>
#include <iostream>
#include <memory>
#include <sstream>
#include <unistd.h>
#include "Common/FileUtil.h"
#include "Core/CoreTiming.h"
#include "Core/HW/Memmap.h"
#include "Core/HW/SystemTimers.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()
{
m_running = false;
@ -84,7 +59,6 @@ void MemoryWatcher::ParseLine(const std::string& line)
bool MemoryWatcher::OpenSocket(const std::string& path)
{
memset(&m_addr, 0, sizeof(m_addr));
m_addr.sun_family = AF_UNIX;
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;
}
std::string MemoryWatcher::ComposeMessage(const std::string& line, u32 value)
std::string MemoryWatcher::ComposeMessages()
{
std::stringstream message_stream;
message_stream << line << '\n' << std::hex << value;
return message_stream.str();
}
void MemoryWatcher::Step()
{
if (!m_running)
return;
message_stream << std::hex;
for (auto& entry : m_values)
{
@ -122,9 +89,19 @@ void MemoryWatcher::Step()
{
// Update the 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),
sizeof(m_addr));
}
}
}

View File

@ -24,21 +24,18 @@ public:
~MemoryWatcher();
void Step();
static void Init();
static void Shutdown();
private:
bool LoadAddresses(const std::string& path);
bool OpenSocket(const std::string& path);
void ParseLine(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;
sockaddr_un m_addr;
sockaddr_un m_addr{};
// Address as stored in the file -> list of offsets to follow
std::map<std::string, std::vector<u32>> m_addresses;