Log window: stream the hook's logs over IPC into an in-app Log panel
Add a shared log ring (common/coop/log_ring.hpp): a lossy multi-producer / single-consumer ring named coop_log_<pid>. The hook logs from several threads, so producers claim a slot with fetch_add and publish each record with a release store of its sequence; the consumer reads in order and tolerates losing the oldest lines if it falls a whole ring behind. The DLL's logf() now formats once and pushes every line to the ring (the file trace stays as an opt-in mirror); the worker attaches the ring right after IPC connect so bring-up is captured. The host (IpcServer) creates the ring at injection time and exposes drain_logs(); a new LogPanel pulls new lines each frame into a bounded rolling buffer and renders them with auto-scroll, a filter, and clear. Added to the View menu (and UiState.show_log). Verified against Phantom Brave via coop_audio_probe, which now also creates the ring and drains it: the full hook bring-up trace streamed over IPC. All four tests pass. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -42,6 +42,13 @@ public:
|
||||
return server_.hook_status();
|
||||
}
|
||||
|
||||
// Drain log lines the hook streamed (for the Log window). No-op if not active.
|
||||
template <typename F>
|
||||
void drain_logs(F&& emit)
|
||||
{
|
||||
server_.drain_logs(std::forward<F>(emit));
|
||||
}
|
||||
|
||||
private:
|
||||
void refresh_processes();
|
||||
void inject_selected();
|
||||
|
||||
@@ -22,6 +22,15 @@ bool IpcServer::start(unsigned long target_pid)
|
||||
|
||||
block_ = block;
|
||||
target_pid_ = target_pid;
|
||||
|
||||
// Log ring: the injected hook opens this and streams its log lines back for the
|
||||
// Log window. Best-effort -- the rest of the tool works without it.
|
||||
if (log_shm_.create(log_ring_name(target_pid), log_ring_total_size(kLogCapacity)))
|
||||
{
|
||||
log_ring_ = log_shm_.as<LogRing>();
|
||||
log_ring_init(*log_ring_, kLogCapacity);
|
||||
log_cursor_ = 0;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -96,6 +105,9 @@ void IpcServer::stop()
|
||||
block_ = nullptr;
|
||||
}
|
||||
shm_.reset();
|
||||
log_ring_ = nullptr;
|
||||
log_shm_.reset();
|
||||
log_cursor_ = 0;
|
||||
target_pid_ = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
|
||||
#include "coop/log_ring.hpp"
|
||||
#include "coop/protocol.hpp"
|
||||
#include "coop/shared_memory.hpp"
|
||||
#include "input/input_source.hpp"
|
||||
@@ -56,6 +57,17 @@ public:
|
||||
// reconciles on its next tick. No-op if not started.
|
||||
void set_subsystem_enabled(std::uint32_t subsystem, bool enabled);
|
||||
|
||||
// Drain new log lines streamed by the hook, calling `emit(const LogRecord&)`
|
||||
// for each. No-op if not started. Header-only so the callback can stay generic.
|
||||
template <typename F>
|
||||
void drain_logs(F&& emit)
|
||||
{
|
||||
if (log_ring_ != nullptr)
|
||||
{
|
||||
log_ring_drain(*log_ring_, log_cursor_, emit);
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] bool running() const
|
||||
{
|
||||
return block_ != nullptr;
|
||||
@@ -69,6 +81,10 @@ private:
|
||||
SharedMemory shm_;
|
||||
SharedBlock* block_ = nullptr;
|
||||
unsigned long target_pid_ = 0;
|
||||
|
||||
SharedMemory log_shm_; // shared log ring (named coop_log_<pid>)
|
||||
LogRing* log_ring_ = nullptr;
|
||||
std::uint64_t log_cursor_ = 0; // consumer position into the log ring
|
||||
};
|
||||
|
||||
} // namespace coop
|
||||
|
||||
75
host/src/log_panel.cpp
Normal file
75
host/src/log_panel.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
#include "log_panel.hpp"
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
#include "imgui.h"
|
||||
|
||||
#include "injection_panel.hpp"
|
||||
|
||||
namespace coop
|
||||
{
|
||||
|
||||
void LogPanel::add_line(const LogRecord& rec)
|
||||
{
|
||||
if (first_millis_ == 0)
|
||||
{
|
||||
first_millis_ = rec.millis;
|
||||
}
|
||||
const double secs = static_cast<double>(rec.millis - first_millis_) / 1000.0;
|
||||
|
||||
char buf[256];
|
||||
std::snprintf(buf, sizeof(buf), "[%8.3f] %s", secs, rec.text);
|
||||
lines_.emplace_back(buf);
|
||||
while (lines_.size() > kMaxLines)
|
||||
{
|
||||
lines_.pop_front();
|
||||
}
|
||||
}
|
||||
|
||||
void LogPanel::pull(InjectionPanel& injection)
|
||||
{
|
||||
injection.drain_logs([this](const LogRecord& rec) { add_line(rec); });
|
||||
}
|
||||
|
||||
void LogPanel::draw()
|
||||
{
|
||||
ImGui::SetNextWindowPos(ImVec2(24, 760), ImGuiCond_FirstUseEver);
|
||||
ImGui::SetNextWindowSize(ImVec2(720, 240), ImGuiCond_FirstUseEver);
|
||||
ImGui::Begin("Log");
|
||||
|
||||
if (ImGui::Button("Clear"))
|
||||
{
|
||||
lines_.clear();
|
||||
first_millis_ = 0;
|
||||
}
|
||||
ImGui::SameLine();
|
||||
ImGui::Checkbox("Auto-scroll", &autoscroll_);
|
||||
ImGui::SameLine();
|
||||
ImGui::SetNextItemWidth(-1.0f);
|
||||
ImGui::InputTextWithHint("##logfilter", "filter...", filter_, sizeof(filter_));
|
||||
|
||||
ImGui::Separator();
|
||||
if (ImGui::BeginChild("loglines", ImVec2(0, 0), ImGuiChildFlags_None, ImGuiWindowFlags_HorizontalScrollbar))
|
||||
{
|
||||
const bool has_filter = filter_[0] != '\0';
|
||||
for (const std::string& line : lines_)
|
||||
{
|
||||
if (has_filter && line.find(filter_) == std::string::npos)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
ImGui::TextUnformatted(line.c_str());
|
||||
}
|
||||
// Stick to the bottom while new lines arrive (unless the user scrolled up).
|
||||
if (autoscroll_ && ImGui::GetScrollY() >= ImGui::GetScrollMaxY() - 1.0f)
|
||||
{
|
||||
ImGui::SetScrollHereY(1.0f);
|
||||
}
|
||||
}
|
||||
ImGui::EndChild();
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
} // namespace coop
|
||||
36
host/src/log_panel.hpp
Normal file
36
host/src/log_panel.hpp
Normal file
@@ -0,0 +1,36 @@
|
||||
// Log window: shows the log lines the injected hook streams over the shared log
|
||||
// ring (see coop/log_ring.hpp). Pull new lines each frame from the IPC server,
|
||||
// keep a bounded rolling history, and render them with autoscroll + a filter.
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <deque>
|
||||
#include <string>
|
||||
|
||||
#include "coop/log_ring.hpp"
|
||||
|
||||
namespace coop
|
||||
{
|
||||
|
||||
class InjectionPanel;
|
||||
|
||||
class LogPanel
|
||||
{
|
||||
public:
|
||||
// Pull any new lines the hook emitted (call once per frame before draw()).
|
||||
void pull(InjectionPanel& injection);
|
||||
|
||||
void draw();
|
||||
|
||||
private:
|
||||
void add_line(const LogRecord& rec);
|
||||
|
||||
std::deque<std::string> lines_;
|
||||
char filter_[96] = {};
|
||||
bool autoscroll_ = true;
|
||||
std::uint64_t first_millis_ = 0; // hook clock at the first line, for relative timestamps
|
||||
|
||||
static constexpr std::size_t kMaxLines = 2000;
|
||||
};
|
||||
|
||||
} // namespace coop
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "imgui_layer.hpp"
|
||||
#include "injection_panel.hpp"
|
||||
#include "input/xinput_source.hpp"
|
||||
#include "log_panel.hpp"
|
||||
#include "ui/app_chrome.hpp"
|
||||
|
||||
namespace
|
||||
@@ -68,6 +69,7 @@ int run()
|
||||
coop::InjectionPanel injection;
|
||||
coop::AudioPanel audio;
|
||||
coop::CapturePanel capture;
|
||||
coop::LogPanel log;
|
||||
if (!capture.init(window.device()))
|
||||
{
|
||||
MessageBoxW(nullptr, L"Failed to initialize the video mirror.", L"CoopAllTheThings", MB_ICONERROR);
|
||||
@@ -91,6 +93,7 @@ int run()
|
||||
|
||||
imgui.begin_frame();
|
||||
stats.tick(ImGui::GetIO().DeltaTime * 1000.0f);
|
||||
log.pull(injection); // drain hook log lines even while the Log window is hidden
|
||||
|
||||
if (ImGui::IsKeyPressed(ImGuiKey_F1, false))
|
||||
{
|
||||
@@ -120,6 +123,10 @@ int run()
|
||||
{
|
||||
capture.draw_ui(stats);
|
||||
}
|
||||
if (ui.show_log)
|
||||
{
|
||||
log.draw();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -24,6 +24,7 @@ float draw_main_menu_bar(UiState& ui, const FrameStats& stats)
|
||||
ImGui::MenuItem("Injection", nullptr, &ui.show_injection);
|
||||
ImGui::MenuItem("Video mirror", nullptr, &ui.show_video);
|
||||
ImGui::MenuItem("Audio mirror", nullptr, &ui.show_audio);
|
||||
ImGui::MenuItem("Log", nullptr, &ui.show_log);
|
||||
ImGui::Separator();
|
||||
ImGui::MenuItem("Debug details", nullptr, &ui.debug_details);
|
||||
ImGui::EndMenu();
|
||||
|
||||
@@ -18,6 +18,7 @@ struct UiState
|
||||
bool show_injection = true;
|
||||
bool show_video = true;
|
||||
bool show_audio = true;
|
||||
bool show_log = true;
|
||||
bool debug_details = false; // off = general status; on = full diagnostics
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user