mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-20 05:16:01 +00:00
Add enhanced one-session diagnostic bundles
This commit is contained in:
1 parent
b563b8d1eb
commit
5614bd5d5a
32 files changed
+3100
-141
No files matched your search
@@ -0,0 +1,333 @@
|
||||
diff --git a/src/Backends/WaylandBackend.cpp b/src/Backends/WaylandBackend.cpp
|
||||
index 953765a..73ab9cc 100644
|
||||
--- a/src/Backends/WaylandBackend.cpp
|
||||
+++ b/src/Backends/WaylandBackend.cpp
|
||||
@@ -14,2 +14,3 @@
|
||||
#include "Utils/WaylandScaling.h"
|
||||
+#include "droiddeck_frame_trace.hpp"
|
||||
|
||||
@@ -1002,2 +1003,4 @@ namespace gamescope
|
||||
|
||||
+ droiddeck::frame_trace::Record( droiddeck::frame_trace::Event::OutputRelease );
|
||||
+
|
||||
xdg_log.debugf( "buffer_release: %p", pBuffer );
|
||||
@@ -1079,2 +1082,3 @@ namespace gamescope
|
||||
{
|
||||
+ droiddeck::frame_trace::Record( droiddeck::frame_trace::Event::OutputPresent );
|
||||
UpdateFullscreenState();
|
||||
@@ -1485,2 +1489,3 @@ namespace gamescope
|
||||
{
|
||||
+ droiddeck::frame_trace::Record( droiddeck::frame_trace::Event::OutputAttach );
|
||||
assert( oState->pBuffer );
|
||||
@@ -1633,2 +1638,3 @@ namespace gamescope
|
||||
{
|
||||
+ droiddeck::frame_trace::Record( droiddeck::frame_trace::Event::OutputDetach );
|
||||
wl_surface_attach( m_pSurface, nullptr, 0, 0 );
|
||||
@@ -1650,2 +1656,3 @@ namespace gamescope
|
||||
{
|
||||
+ droiddeck::frame_trace::Record( droiddeck::frame_trace::Event::OutputCommit );
|
||||
if ( m_bNeedsDecorCommit )
|
||||
diff --git a/src/droiddeck_frame_trace.hpp b/src/droiddeck_frame_trace.hpp
|
||||
new file mode 100644
|
||||
index 0000000..2c57f65
|
||||
--- /dev/null
|
||||
+++ b/src/droiddeck_frame_trace.hpp
|
||||
@@ -0,0 +1,191 @@
|
||||
+#pragma once
|
||||
+
|
||||
+#include <atomic>
|
||||
+#include <chrono>
|
||||
+#include <cstdint>
|
||||
+#include <cstdio>
|
||||
+#include <cstdlib>
|
||||
+#include <cstring>
|
||||
+
|
||||
+#ifndef DROIDDECK_FRAME_TRACE_FAST_INTERVAL_MS
|
||||
+#define DROIDDECK_FRAME_TRACE_FAST_INTERVAL_MS 2000
|
||||
+#endif
|
||||
+#ifndef DROIDDECK_FRAME_TRACE_SLOW_INTERVAL_MS
|
||||
+#define DROIDDECK_FRAME_TRACE_SLOW_INTERVAL_MS 15000
|
||||
+#endif
|
||||
+#ifndef DROIDDECK_FRAME_TRACE_FAST_DURATION_MS
|
||||
+#define DROIDDECK_FRAME_TRACE_FAST_DURATION_MS 120000
|
||||
+#endif
|
||||
+#ifndef DROIDDECK_FRAME_TRACE_DURATION_MS
|
||||
+#define DROIDDECK_FRAME_TRACE_DURATION_MS 86400000
|
||||
+#endif
|
||||
+
|
||||
+namespace droiddeck::frame_trace
|
||||
+{
|
||||
+
|
||||
+enum class Event : uint32_t
|
||||
+{
|
||||
+ X11Damage,
|
||||
+ X11DamageCurrent,
|
||||
+ X11DamageOther,
|
||||
+ SurfaceCommit,
|
||||
+ SurfaceCommitBuffer,
|
||||
+ SurfaceCommitNoBuffer,
|
||||
+ CommitDequeued,
|
||||
+ CommitDequeuedCurrent,
|
||||
+ CommitDequeuedOther,
|
||||
+ ImportSucceeded,
|
||||
+ ImportSucceededCurrent,
|
||||
+ ImportSucceededOther,
|
||||
+ ImportFailed,
|
||||
+ ImportFailedCurrent,
|
||||
+ ImportFailedOther,
|
||||
+ FenceReady,
|
||||
+ FenceWaited,
|
||||
+ CommitDone,
|
||||
+ CommitDoneCurrent,
|
||||
+ CommitDoneOther,
|
||||
+ BaseLatched,
|
||||
+ BaseLatchedCurrent,
|
||||
+ BaseLatchedOther,
|
||||
+ OutputPresent,
|
||||
+ OutputAttach,
|
||||
+ OutputDetach,
|
||||
+ OutputCommit,
|
||||
+ OutputRelease,
|
||||
+ Count,
|
||||
+};
|
||||
+
|
||||
+class State
|
||||
+{
|
||||
+public:
|
||||
+ State()
|
||||
+ : m_enabled( EnabledByEnvironment() )
|
||||
+ {
|
||||
+ }
|
||||
+
|
||||
+ void Start()
|
||||
+ {
|
||||
+ if ( !m_enabled || m_started.exchange( true, std::memory_order_relaxed ) )
|
||||
+ return;
|
||||
+
|
||||
+ m_startedAt = std::chrono::steady_clock::now();
|
||||
+ m_nextSummaryMs = kFastIntervalMs;
|
||||
+ std::fprintf( stderr,
|
||||
+ "DROIDDECK_FRAME_TRACE schema=1 fast_interval_ms=%ld slow_interval_ms=%ld "
|
||||
+ "fast_duration_ms=%ld duration_ms=%ld\n",
|
||||
+ kFastIntervalMs, kSlowIntervalMs, kFastDurationMs, kDurationMs );
|
||||
+ PrintSummary( 0 );
|
||||
+ }
|
||||
+
|
||||
+ void Record( Event event )
|
||||
+ {
|
||||
+ if ( !m_enabled || !m_started.load( std::memory_order_relaxed ) ||
|
||||
+ !m_active.load( std::memory_order_relaxed ) )
|
||||
+ return;
|
||||
+ m_counts[static_cast<uint32_t>( event )].fetch_add( 1, std::memory_order_relaxed );
|
||||
+ }
|
||||
+
|
||||
+ void Tick()
|
||||
+ {
|
||||
+ if ( !m_enabled || !m_started.load( std::memory_order_relaxed ) ||
|
||||
+ !m_active.load( std::memory_order_relaxed ) )
|
||||
+ return;
|
||||
+
|
||||
+ const int64_t elapsed = ElapsedMs();
|
||||
+ if ( elapsed >= kDurationMs )
|
||||
+ {
|
||||
+ PrintSummary( kDurationMs );
|
||||
+ m_active.store( false, std::memory_order_relaxed );
|
||||
+ return;
|
||||
+ }
|
||||
+ if ( elapsed < m_nextSummaryMs )
|
||||
+ return;
|
||||
+
|
||||
+ PrintSummary( elapsed );
|
||||
+ m_nextSummaryMs = elapsed + ( elapsed < kFastDurationMs ? kFastIntervalMs : kSlowIntervalMs );
|
||||
+ }
|
||||
+
|
||||
+private:
|
||||
+ static constexpr int64_t kFastIntervalMs = DROIDDECK_FRAME_TRACE_FAST_INTERVAL_MS;
|
||||
+ static constexpr int64_t kSlowIntervalMs = DROIDDECK_FRAME_TRACE_SLOW_INTERVAL_MS;
|
||||
+ static constexpr int64_t kFastDurationMs = DROIDDECK_FRAME_TRACE_FAST_DURATION_MS;
|
||||
+ static constexpr int64_t kDurationMs = DROIDDECK_FRAME_TRACE_DURATION_MS;
|
||||
+
|
||||
+ static bool EnabledByEnvironment()
|
||||
+ {
|
||||
+ const char *value = std::getenv( "DROIDDECK_ENHANCED_DIAGNOSTICS" );
|
||||
+ return value != nullptr && std::strcmp( value, "1" ) == 0;
|
||||
+ }
|
||||
+
|
||||
+ int64_t ElapsedMs() const
|
||||
+ {
|
||||
+ return std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
+ std::chrono::steady_clock::now() - m_startedAt ).count();
|
||||
+ }
|
||||
+
|
||||
+ uint64_t Count( Event event ) const
|
||||
+ {
|
||||
+ return m_counts[static_cast<uint32_t>( event )].load( std::memory_order_relaxed );
|
||||
+ }
|
||||
+
|
||||
+ void PrintSummary( int64_t elapsed ) const
|
||||
+ {
|
||||
+ std::fprintf( stderr,
|
||||
+ "DROIDDECK_FRAME_TRACE t_ms=%ld x11_damage=%lu x11_damage_current=%lu x11_damage_other=%lu "
|
||||
+ "surface_commit=%lu surface_buffer=%lu surface_no_buffer=%lu dequeued=%lu dequeued_current=%lu "
|
||||
+ "dequeued_other=%lu import_ok=%lu import_ok_current=%lu import_ok_other=%lu import_failed=%lu "
|
||||
+ "import_failed_current=%lu import_failed_other=%lu fence_ready=%lu fence_waited=%lu commit_done=%lu "
|
||||
+ "commit_done_current=%lu commit_done_other=%lu base_latched=%lu base_latched_current=%lu "
|
||||
+ "base_latched_other=%lu output_present=%lu output_attach=%lu "
|
||||
+ "output_detach=%lu output_commit=%lu output_release=%lu\n",
|
||||
+ elapsed,
|
||||
+ Count( Event::X11Damage ), Count( Event::X11DamageCurrent ), Count( Event::X11DamageOther ),
|
||||
+ Count( Event::SurfaceCommit ), Count( Event::SurfaceCommitBuffer ), Count( Event::SurfaceCommitNoBuffer ),
|
||||
+ Count( Event::CommitDequeued ), Count( Event::CommitDequeuedCurrent ), Count( Event::CommitDequeuedOther ),
|
||||
+ Count( Event::ImportSucceeded ), Count( Event::ImportSucceededCurrent ), Count( Event::ImportSucceededOther ),
|
||||
+ Count( Event::ImportFailed ), Count( Event::ImportFailedCurrent ), Count( Event::ImportFailedOther ),
|
||||
+ Count( Event::FenceReady ), Count( Event::FenceWaited ), Count( Event::CommitDone ),
|
||||
+ Count( Event::CommitDoneCurrent ), Count( Event::CommitDoneOther ), Count( Event::BaseLatched ),
|
||||
+ Count( Event::BaseLatchedCurrent ), Count( Event::BaseLatchedOther ), Count( Event::OutputPresent ),
|
||||
+ Count( Event::OutputAttach ), Count( Event::OutputDetach ), Count( Event::OutputCommit ),
|
||||
+ Count( Event::OutputRelease ) );
|
||||
+ std::fflush( stderr );
|
||||
+ }
|
||||
+
|
||||
+ bool m_enabled;
|
||||
+ std::atomic<bool> m_started{ false };
|
||||
+ std::atomic<bool> m_active{ true };
|
||||
+ std::chrono::steady_clock::time_point m_startedAt{};
|
||||
+ int64_t m_nextSummaryMs = 0;
|
||||
+ std::atomic<uint64_t> m_counts[static_cast<uint32_t>( Event::Count )]{};
|
||||
+};
|
||||
+
|
||||
+inline State &GetState()
|
||||
+{
|
||||
+ static State state;
|
||||
+ return state;
|
||||
+}
|
||||
+
|
||||
+inline void Start()
|
||||
+{
|
||||
+ GetState().Start();
|
||||
+}
|
||||
+
|
||||
+inline void Record( Event event )
|
||||
+{
|
||||
+ GetState().Record( event );
|
||||
+}
|
||||
+
|
||||
+inline void RecordWindow( Event total, Event focused, Event other, bool isFocused )
|
||||
+{
|
||||
+ Record( total );
|
||||
+ Record( isFocused ? focused : other );
|
||||
+}
|
||||
+
|
||||
+inline void Tick()
|
||||
+{
|
||||
+ GetState().Tick();
|
||||
+}
|
||||
+
|
||||
+}
|
||||
diff --git a/src/main.cpp b/src/main.cpp
|
||||
index eef4264..1d22ba4 100644
|
||||
--- a/src/main.cpp
|
||||
+++ b/src/main.cpp
|
||||
@@ -35,2 +35,3 @@
|
||||
#include "Utils/Version.h"
|
||||
+#include "droiddeck_frame_trace.hpp"
|
||||
|
||||
@@ -718,2 +719,3 @@ int main(int argc, char **argv)
|
||||
g_argv = argv;
|
||||
+ droiddeck::frame_trace::Start();
|
||||
|
||||
diff --git a/src/steamcompmgr.cpp b/src/steamcompmgr.cpp
|
||||
index b4c6830..46e7a6c 100644
|
||||
--- a/src/steamcompmgr.cpp
|
||||
+++ b/src/steamcompmgr.cpp
|
||||
@@ -32,2 +32,3 @@
|
||||
#include "backend.h"
|
||||
+#include "droiddeck_frame_trace.hpp"
|
||||
#include "gamescope_shared.h"
|
||||
@@ -6419,2 +6420,9 @@ damage_win(xwayland_ctx_t *ctx, XDamageNotifyEvent *de)
|
||||
|
||||
+ global_focus_t *pTraceFocus = GetCurrentFocus();
|
||||
+ droiddeck::frame_trace::RecordWindow(
|
||||
+ droiddeck::frame_trace::Event::X11Damage,
|
||||
+ droiddeck::frame_trace::Event::X11DamageCurrent,
|
||||
+ droiddeck::frame_trace::Event::X11DamageOther,
|
||||
+ pTraceFocus != nullptr && pTraceFocus->focusWindow == w );
|
||||
+
|
||||
if (w->IsAnyOverlay() && !w->opacity)
|
||||
@@ -7999,2 +8007,8 @@ bool handle_done_commit( steamcompmgr_win_t *w, xwayland_ctx_t *ctx, uint64_t co
|
||||
{
|
||||
+ global_focus_t *pTraceFocus = GetCurrentFocus();
|
||||
+ droiddeck::frame_trace::RecordWindow(
|
||||
+ droiddeck::frame_trace::Event::CommitDone,
|
||||
+ droiddeck::frame_trace::Event::CommitDoneCurrent,
|
||||
+ droiddeck::frame_trace::Event::CommitDoneOther,
|
||||
+ pTraceFocus != nullptr && pTraceFocus->focusWindow == w );
|
||||
gpuvis_trace_printf( "commit %lu done", w->commit_queue[ j ]->commitID );
|
||||
@@ -8049,3 +8063,10 @@ bool handle_done_commit( steamcompmgr_win_t *w, xwayland_ctx_t *ctx, uint64_t co
|
||||
if ( !cv_paint_debug_pause_base_plane )
|
||||
+ {
|
||||
pFocus->HeldCommits[ HELD_COMMIT_BASE ] = w->commit_queue[ j ];
|
||||
+ droiddeck::frame_trace::RecordWindow(
|
||||
+ droiddeck::frame_trace::Event::BaseLatched,
|
||||
+ droiddeck::frame_trace::Event::BaseLatchedCurrent,
|
||||
+ droiddeck::frame_trace::Event::BaseLatchedOther,
|
||||
+ pFocus == GetCurrentFocus() );
|
||||
+ }
|
||||
hasRepaint = true;
|
||||
@@ -8397,2 +8418,4 @@ static void note_commit_fence( bool bReadyAtImport )
|
||||
{
|
||||
+ droiddeck::frame_trace::Record( bReadyAtImport ? droiddeck::frame_trace::Event::FenceReady
|
||||
+ : droiddeck::frame_trace::Event::FenceWaited );
|
||||
static uint64_t s_ulReady = 0, s_ulWaited = 0, s_ulLastLog = 0;
|
||||
@@ -8412,2 +8435,9 @@ void update_wayland_res(const std::shared_ptr<CommitDoneList_t> &doneCommits, st
|
||||
{
|
||||
+ global_focus_t *pTraceFocus = GetCurrentFocus();
|
||||
+ const bool bTraceCurrent = pTraceFocus != nullptr && pTraceFocus->focusWindow == w;
|
||||
+ droiddeck::frame_trace::RecordWindow(
|
||||
+ droiddeck::frame_trace::Event::CommitDequeued,
|
||||
+ droiddeck::frame_trace::Event::CommitDequeuedCurrent,
|
||||
+ droiddeck::frame_trace::Event::CommitDequeuedOther,
|
||||
+ bTraceCurrent );
|
||||
struct wlr_buffer *buf = reslistentry.buf;
|
||||
@@ -8501,2 +8531,7 @@ void update_wayland_res(const std::shared_ptr<CommitDoneList_t> &doneCommits, st
|
||||
{
|
||||
+ droiddeck::frame_trace::RecordWindow(
|
||||
+ droiddeck::frame_trace::Event::ImportFailed,
|
||||
+ droiddeck::frame_trace::Event::ImportFailedCurrent,
|
||||
+ droiddeck::frame_trace::Event::ImportFailedOther,
|
||||
+ bTraceCurrent );
|
||||
// Import failed to import, early exit.
|
||||
@@ -8504,2 +8539,7 @@ void update_wayland_res(const std::shared_ptr<CommitDoneList_t> &doneCommits, st
|
||||
}
|
||||
+ droiddeck::frame_trace::RecordWindow(
|
||||
+ droiddeck::frame_trace::Event::ImportSucceeded,
|
||||
+ droiddeck::frame_trace::Event::ImportSucceededCurrent,
|
||||
+ droiddeck::frame_trace::Event::ImportSucceededOther,
|
||||
+ bTraceCurrent );
|
||||
|
||||
@@ -8679,3 +8719,2 @@ void update_wayland_res(const std::shared_ptr<CommitDoneList_t> &doneCommits, st
|
||||
}
|
||||
-
|
||||
gpuvis_trace_printf( "pushing wait for commit %lu win %lx", newCommit->commitID, w->type == steamcompmgr_win_type_t::XWAYLAND ? w->xwayland().id : 0 );
|
||||
@@ -10256,2 +10295,3 @@ steamcompmgr_main(int argc, char **argv)
|
||||
{
|
||||
+ droiddeck::frame_trace::Tick();
|
||||
{
|
||||
diff --git a/src/wlserver.cpp b/src/wlserver.cpp
|
||||
index 5733871..ed4dbc3 100644
|
||||
--- a/src/wlserver.cpp
|
||||
+++ b/src/wlserver.cpp
|
||||
@@ -24,2 +24,3 @@
|
||||
#include "WaylandServer/GamescopeLimiter.h"
|
||||
+#include "droiddeck_frame_trace.hpp"
|
||||
|
||||
@@ -210,2 +211,8 @@ void xwayland_surface_commit(struct wlr_surface *wlr_surface) {
|
||||
|
||||
+ droiddeck::frame_trace::Record( droiddeck::frame_trace::Event::SurfaceCommit );
|
||||
+ droiddeck::frame_trace::Record(
|
||||
+ ( wlr_surface->current.committed & WLR_SURFACE_STATE_BUFFER )
|
||||
+ ? droiddeck::frame_trace::Event::SurfaceCommitBuffer
|
||||
+ : droiddeck::frame_trace::Event::SurfaceCommitNoBuffer );
|
||||
+
|
||||
wlr_surface->current.committed = 0;
|
||||
|
||||
@@ -0,0 +1,446 @@
|
||||
#!/usr/bin/env python3
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import sys
|
||||
import time
|
||||
|
||||
|
||||
PREFIX = "DROIDDECK_PROCESS_TRACE "
|
||||
SCHEMA = 1
|
||||
DEFAULT_INTERVAL_MS = 5_000
|
||||
DEFAULT_DURATION_MS = 86_400_000
|
||||
DEFAULT_MAX_RECORDS = 512
|
||||
HEARTBEAT_MS = 300_000
|
||||
MAX_PROCESSES = 256
|
||||
MAX_MAP_BYTES = 8 * 1024 * 1024
|
||||
MAX_MAP_LINES = 65_536
|
||||
MAX_LIBRARIES = 128
|
||||
MAX_CMDLINE_BYTES = 16 * 1024
|
||||
MAX_ENUMERATED_PROCESSES = 4_096
|
||||
MAX_CHILDREN_BYTES = 64 * 1024
|
||||
SAFE_LIBRARY = re.compile(r"[A-Za-z0-9._+-]{1,128}")
|
||||
WINDOWS_GRAPHICS_LIBRARIES = {
|
||||
"d3d8.dll", "d3d9.dll", "d3d10.dll", "d3d10_1.dll", "d3d10core.dll",
|
||||
"d3d11.dll", "d3d12.dll", "dxgi.dll", "vulkan-1.dll",
|
||||
}
|
||||
KNOWN_GRAPHICS_SONAMES = {
|
||||
"libvulkan.so", "libvulkan_freedreno.so", "libvulkan_panfrost.so", "libvulkan_lvp.so",
|
||||
"libvulkan_virtio.so", "libvulkan_dzn.so", "libvulkan_broadcom.so",
|
||||
"libEGL.so", "libEGL_mesa.so", "libGLESv1_CM.so", "libGLESv2.so", "libGLESv3.so",
|
||||
"libGL.so", "libGLX.so", "libGLX_mesa.so", "libgbm.so", "libwayland-client.so",
|
||||
"libX11.so", "libX11-xcb.so", "libdrm.so", "libdrm_amdgpu.so", "libdrm_freedreno.so",
|
||||
"libdrm_intel.so", "libdrm_nouveau.so", "libdrm_radeon.so", "libxcb.so", "libxcb-dri2.so",
|
||||
"libxcb-dri3.so", "libxcb-glx.so", "libxcb-present.so", "libxcb-randr.so", "libxcb-render.so",
|
||||
"libxcb-shm.so", "libxcb-sync.so", "libxcb-xfixes.so", "libhybris-vulkan-icd.so",
|
||||
"libVkLayer_hybris_compat.so", "libVkLayer_DROIDDECK_placed_memory.so",
|
||||
"libVkLayer_KHRONOS_validation.so", "libVkLayer_FROG_gamescope_wsi_aarch64.so",
|
||||
"libVkLayer_MESA_device_select.so", "libVkLayer_MESA_overlay.so", "libvkd3d.so",
|
||||
"libvkd3d-shader.so", "libvkd3d-utils.so",
|
||||
}
|
||||
|
||||
|
||||
def emit(payload, output=sys.stdout):
|
||||
output.write(PREFIX + json.dumps(payload, separators=(",", ":"), sort_keys=True) + "\n")
|
||||
output.flush()
|
||||
|
||||
|
||||
def process_stat(path):
|
||||
text = path.read_text(errors="replace")
|
||||
end = text.rfind(") ")
|
||||
if end < 0:
|
||||
raise ValueError("invalid process stat")
|
||||
fields = text[end + 2:].split()
|
||||
if len(fields) < 20:
|
||||
raise ValueError("short process stat")
|
||||
return int(fields[1]), fields[19]
|
||||
|
||||
|
||||
def bounded_bytes(path, limit):
|
||||
with path.open("rb") as source:
|
||||
return source.read(limit)
|
||||
|
||||
|
||||
def process_role(comm, cmdline):
|
||||
probe = (comm + "\0" + cmdline.decode("utf-8", "replace")).lower()
|
||||
if "steamwebhelper" in probe:
|
||||
return "steam-webhelper"
|
||||
if "gamescope" in probe:
|
||||
return "gamescope"
|
||||
if "xwayland" in probe:
|
||||
return "xwayland"
|
||||
if "mangoapp" in probe:
|
||||
return "mangoapp"
|
||||
if "pressure-vessel" in probe or "steam-runtime" in probe:
|
||||
return "steam-runtime"
|
||||
if "steamrtarm64/steam" in probe or "steamrt64/steam" in probe or comm.lower() == "steam":
|
||||
return "steam-client"
|
||||
if "fexinterpreter" in probe or comm.lower() == "fex":
|
||||
return "fex"
|
||||
if "wineserver" in probe:
|
||||
return "wineserver"
|
||||
if any(name in probe for name in ("wine64", "wine-preloader", "/wine ")):
|
||||
return "wine"
|
||||
if "pipewire" in probe or "pulseaudio" in probe:
|
||||
return "audio-server"
|
||||
if "dbus-daemon" in probe:
|
||||
return "dbus"
|
||||
if "droiddeck-session" in probe:
|
||||
return "session"
|
||||
return "game-or-helper"
|
||||
|
||||
|
||||
def is_graphics_library(name):
|
||||
lower = name.lower()
|
||||
return (
|
||||
lower in WINDOWS_GRAPHICS_LIBRARIES or
|
||||
lower.startswith(("libvulkan", "libvklayer", "vulkan.", "libegl", "libgles", "libglx",
|
||||
"libgl.so", "libgbm", "libdrm", "libwayland", "libxcb", "libx11")) or
|
||||
"vkd3d" in lower or "dxvk" in lower or "zink" in lower or "mangohud" in lower
|
||||
)
|
||||
|
||||
|
||||
def origin_class(path):
|
||||
lower = path.lower()
|
||||
if lower.startswith("/vendor/"):
|
||||
return "android-vendor"
|
||||
if lower.startswith(("/system/", "/apex/")):
|
||||
return "android-system"
|
||||
if "/files/components/" in lower or "/files/system_vulkan/" in lower:
|
||||
return "droiddeck-component"
|
||||
if "/steamapps/common/" in lower:
|
||||
return "steam-tool"
|
||||
if lower.startswith(("/usr/", "/lib/", "/opt/")):
|
||||
return "guest-runtime"
|
||||
if lower.startswith("/tmp/"):
|
||||
return "temporary"
|
||||
return "other"
|
||||
|
||||
|
||||
def library_identity(name, origin):
|
||||
if origin in {"android-vendor", "android-system"}:
|
||||
return name
|
||||
base = name
|
||||
while True:
|
||||
head, separator, tail = base.rpartition(".")
|
||||
if not separator or not tail.isdigit():
|
||||
break
|
||||
base = head
|
||||
if name.lower() in WINDOWS_GRAPHICS_LIBRARIES or base in KNOWN_GRAPHICS_SONAMES:
|
||||
return name
|
||||
return "sha256:" + hashlib.sha256(name.encode()).hexdigest()[:16]
|
||||
|
||||
|
||||
def graphics_libraries(maps_path):
|
||||
libraries = set()
|
||||
total = 0
|
||||
lines = 0
|
||||
with maps_path.open("rb") as source:
|
||||
while lines < MAX_MAP_LINES and total < MAX_MAP_BYTES:
|
||||
raw = source.readline(min(64 * 1024, MAX_MAP_BYTES - total + 1))
|
||||
if not raw:
|
||||
break
|
||||
total += len(raw)
|
||||
lines += 1
|
||||
if total > MAX_MAP_BYTES:
|
||||
return libraries, "capped"
|
||||
parts = raw.decode("utf-8", "replace").rstrip("\n").split(None, 5)
|
||||
if len(parts) < 6 or not parts[5].startswith("/"):
|
||||
continue
|
||||
mapped = parts[5].removesuffix(" (deleted)")
|
||||
name = os.path.basename(mapped)
|
||||
if SAFE_LIBRARY.fullmatch(name) and is_graphics_library(name):
|
||||
origin = origin_class(mapped)
|
||||
libraries.add((library_identity(name, origin), origin))
|
||||
if len(libraries) >= MAX_LIBRARIES:
|
||||
return libraries, "capped"
|
||||
return libraries, "readable"
|
||||
|
||||
|
||||
class Collector:
|
||||
def __init__(self, proc_root, root_pid):
|
||||
self.proc_root = Path(proc_root)
|
||||
self.root_pid = int(root_pid)
|
||||
self.known = {}
|
||||
self.tokens = {}
|
||||
self.next_token = 1
|
||||
self.self_pid = os.getpid()
|
||||
self.root_identity = None
|
||||
self.last_maps_state = None
|
||||
self.last_provider_error = None
|
||||
|
||||
def _scan_fallback(self, result):
|
||||
capped = False
|
||||
try:
|
||||
entries = self.proc_root.iterdir()
|
||||
except OSError:
|
||||
return capped, "proc-unavailable"
|
||||
examined = 0
|
||||
for entry in entries:
|
||||
if not entry.name.isdigit():
|
||||
continue
|
||||
examined += 1
|
||||
if examined > MAX_ENUMERATED_PROCESSES:
|
||||
capped = True
|
||||
break
|
||||
pid = int(entry.name)
|
||||
if pid == self.self_pid or pid in result:
|
||||
continue
|
||||
try:
|
||||
result[pid] = process_stat(entry / "stat")
|
||||
except (OSError, ValueError):
|
||||
continue
|
||||
return capped, None
|
||||
|
||||
def _stats(self):
|
||||
result = {}
|
||||
capped = False
|
||||
try:
|
||||
ppid, start = process_stat(self.proc_root / str(self.root_pid) / "stat")
|
||||
if self.root_pid != self.self_pid:
|
||||
result[self.root_pid] = (ppid, start)
|
||||
except (OSError, ValueError):
|
||||
return result, capped, "proc-unavailable", "children", True
|
||||
queue = [self.root_pid]
|
||||
fallback = False
|
||||
while queue and len(result) < MAX_PROCESSES:
|
||||
parent = queue.pop(0)
|
||||
try:
|
||||
raw = bounded_bytes(
|
||||
self.proc_root / str(parent) / "task" / str(parent) / "children", MAX_CHILDREN_BYTES + 1,
|
||||
)
|
||||
except OSError:
|
||||
fallback = True
|
||||
continue
|
||||
if len(raw) > MAX_CHILDREN_BYTES:
|
||||
capped = True
|
||||
fallback = True
|
||||
continue
|
||||
for value in raw.split():
|
||||
if not value.isdigit():
|
||||
continue
|
||||
pid = int(value)
|
||||
if pid == self.self_pid or pid in result:
|
||||
continue
|
||||
if len(result) >= MAX_PROCESSES:
|
||||
capped = True
|
||||
break
|
||||
try:
|
||||
identity = process_stat(self.proc_root / str(pid) / "stat")
|
||||
except (OSError, ValueError):
|
||||
continue
|
||||
if identity[0] != parent:
|
||||
continue
|
||||
result[pid] = identity
|
||||
queue.append(pid)
|
||||
if queue:
|
||||
capped = True
|
||||
if fallback:
|
||||
fallback_capped, error = self._scan_fallback(result)
|
||||
capped = capped or fallback_capped
|
||||
return result, capped, error, "children+scan-fallback", True
|
||||
return result, capped, None, "children", capped
|
||||
|
||||
def scan(self):
|
||||
stats, enumeration_capped, provider_error, scope_method, scope_incomplete = self._stats()
|
||||
descendants = set()
|
||||
root = stats.get(self.root_pid)
|
||||
if self.root_identity is None and root is not None:
|
||||
self.root_identity = root
|
||||
if root is not None and self.root_identity != root:
|
||||
provider_error = "root-reused"
|
||||
elif root is not None:
|
||||
descendants.add(self.root_pid)
|
||||
changed = True
|
||||
while changed and len(descendants) < MAX_PROCESSES:
|
||||
changed = False
|
||||
for pid, (ppid, _) in stats.items():
|
||||
if pid not in descendants and ppid in descendants:
|
||||
descendants.add(pid)
|
||||
changed = True
|
||||
if len(descendants) >= MAX_PROCESSES:
|
||||
break
|
||||
if provider_error is None and root is None:
|
||||
provider_error = "root-unavailable"
|
||||
scope_capped = len(descendants) >= MAX_PROCESSES or enumeration_capped
|
||||
current = {}
|
||||
maps_state = {"readable": 0, "unavailable": 0, "capped": 0}
|
||||
for pid in sorted(descendants):
|
||||
process = self.proc_root / str(pid)
|
||||
try:
|
||||
expected = stats[pid]
|
||||
if process_stat(process / "stat") != expected:
|
||||
continue
|
||||
ppid, start = expected
|
||||
comm = (process / "comm").read_text(errors="replace")[:128].strip()
|
||||
cmdline = bounded_bytes(process / "cmdline", MAX_CMDLINE_BYTES)
|
||||
except (OSError, ValueError):
|
||||
continue
|
||||
key = (pid, start)
|
||||
try:
|
||||
libraries, state = graphics_libraries(process / "maps")
|
||||
except (OSError, ValueError):
|
||||
libraries, state = set(), "unavailable"
|
||||
maps_state[state] = maps_state.get(state, 0) + 1
|
||||
current[key] = {
|
||||
"ppid": ppid,
|
||||
"role": process_role(comm, cmdline),
|
||||
"libraries": libraries,
|
||||
"identity": expected,
|
||||
"mapState": state,
|
||||
}
|
||||
stable = {}
|
||||
for key, process in current.items():
|
||||
pid = key[0]
|
||||
try:
|
||||
if process_stat(self.proc_root / str(pid) / "stat") != process["identity"]:
|
||||
continue
|
||||
except (OSError, ValueError):
|
||||
continue
|
||||
stable[key] = process
|
||||
final = {}
|
||||
valid_pids = {self.root_pid} if any(key[0] == self.root_pid for key in stable) else set()
|
||||
changed = True
|
||||
while changed:
|
||||
changed = False
|
||||
for key, process in stable.items():
|
||||
pid = key[0]
|
||||
if key not in final and (pid == self.root_pid or process["ppid"] in valid_pids):
|
||||
final[key] = process
|
||||
valid_pids.add(pid)
|
||||
changed = True
|
||||
current = final
|
||||
try:
|
||||
root_final = process_stat(self.proc_root / str(self.root_pid) / "stat")
|
||||
except (OSError, ValueError):
|
||||
root_final = None
|
||||
if root_final is None:
|
||||
if provider_error is None:
|
||||
provider_error = "root-unavailable"
|
||||
current = {}
|
||||
elif self.root_identity != root_final:
|
||||
provider_error = "root-reused"
|
||||
current = {}
|
||||
maps_state = {"readable": 0, "unavailable": 0, "capped": 0}
|
||||
for process in current.values():
|
||||
state = process["mapState"]
|
||||
maps_state[state] = maps_state.get(state, 0) + 1
|
||||
started = sorted(set(current) - set(self.known))
|
||||
exited = sorted(set(self.known) - set(current))
|
||||
roles_changed = any(
|
||||
key in self.known and current[key]["role"] != self.known[key]["role"] for key in current
|
||||
)
|
||||
for key in started:
|
||||
self.tokens[key] = self.next_token
|
||||
self.next_token += 1
|
||||
state_changed = maps_state != self.last_maps_state or provider_error != self.last_provider_error
|
||||
payload = self._snapshot(
|
||||
current, started, exited, maps_state, scope_capped, provider_error, scope_method, scope_incomplete,
|
||||
)
|
||||
for key in exited:
|
||||
self.tokens.pop(key, None)
|
||||
self.known = current
|
||||
self.last_maps_state = maps_state
|
||||
self.last_provider_error = provider_error
|
||||
return payload, bool(started or exited or roles_changed or payload["librariesChanged"] or state_changed)
|
||||
|
||||
def _snapshot(self, current, started, exited, maps_state, scope_capped, provider_error,
|
||||
scope_method, scope_incomplete):
|
||||
previous_libraries = {item for process in self.known.values() for item in process["libraries"]}
|
||||
libraries = {item for process in current.values() for item in process["libraries"]}
|
||||
role_counts = {}
|
||||
for process in current.values():
|
||||
role = process["role"]
|
||||
role_counts[role] = role_counts.get(role, 0) + 1
|
||||
started_rows = [{"token": self.tokens[key], "role": current[key]["role"]} for key in started[:32]]
|
||||
exited_rows = [{"token": self.tokens.get(key, 0), "role": self.known[key]["role"]} for key in exited[:32]]
|
||||
library_rows = [{"name": name, "origin": origin} for name, origin in sorted(libraries)[:MAX_LIBRARIES]]
|
||||
return {
|
||||
"schema": SCHEMA,
|
||||
"event": "snapshot",
|
||||
"scope": "root-descendants",
|
||||
"scopeMethod": scope_method,
|
||||
"scopeIncomplete": scope_incomplete,
|
||||
"procView": "guest-visible",
|
||||
"alive": len(current),
|
||||
"roles": role_counts,
|
||||
"started": started_rows,
|
||||
"startedOmitted": max(0, len(started) - len(started_rows)),
|
||||
"exited": exited_rows,
|
||||
"exitedOmitted": max(0, len(exited) - len(exited_rows)),
|
||||
"libraries": library_rows,
|
||||
"librariesOmitted": max(0, len(libraries) - len(library_rows)),
|
||||
"librariesChanged": libraries != previous_libraries,
|
||||
"maps": maps_state,
|
||||
"scopeCapped": scope_capped,
|
||||
"providerStatus": provider_error or "available",
|
||||
}
|
||||
|
||||
|
||||
def parse_args(argv):
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--once", action="store_true")
|
||||
parser.add_argument("--watch", action="store_true")
|
||||
parser.add_argument("--root-pid", type=int, default=os.getppid())
|
||||
parser.add_argument("--proc-root", default="/proc")
|
||||
parser.add_argument("--interval-ms", type=int, default=DEFAULT_INTERVAL_MS)
|
||||
parser.add_argument("--duration-ms", type=int, default=DEFAULT_DURATION_MS)
|
||||
parser.add_argument("--max-records", type=int, default=DEFAULT_MAX_RECORDS)
|
||||
args = parser.parse_args(argv)
|
||||
if args.once == args.watch:
|
||||
parser.error("choose exactly one of --once or --watch")
|
||||
if args.root_pid <= 0:
|
||||
parser.error("--root-pid must be positive")
|
||||
args.interval_ms = min(60_000, max(250, args.interval_ms))
|
||||
args.duration_ms = min(DEFAULT_DURATION_MS, max(0, args.duration_ms))
|
||||
args.max_records = min(1_024, max(3, args.max_records))
|
||||
return args
|
||||
|
||||
|
||||
def main(argv=None, environ=None, output=sys.stdout):
|
||||
environ = os.environ if environ is None else environ
|
||||
if environ.get("DROIDDECK_ENHANCED_DIAGNOSTICS") != "1":
|
||||
return 0
|
||||
args = parse_args(sys.argv[1:] if argv is None else argv)
|
||||
collector = Collector(args.proc_root, args.root_pid)
|
||||
emit({
|
||||
"schema": SCHEMA,
|
||||
"event": "provider",
|
||||
"mode": "once" if args.once else "watch",
|
||||
"intervalMs": args.interval_ms,
|
||||
"durationMs": 0 if args.once else args.duration_ms,
|
||||
"maxRecords": args.max_records,
|
||||
"scope": "root-descendants",
|
||||
"procView": "guest-visible",
|
||||
}, output)
|
||||
records = 1
|
||||
started = time.monotonic()
|
||||
last_heartbeat = started
|
||||
ended_normally = False
|
||||
while records < args.max_records - 1:
|
||||
payload, changed = collector.scan()
|
||||
now = time.monotonic()
|
||||
if changed or records == 1 or (now - last_heartbeat) * 1000 >= HEARTBEAT_MS:
|
||||
if not changed and records > 1:
|
||||
payload["event"] = "heartbeat"
|
||||
payload.pop("libraries", None)
|
||||
payload["librariesUnchanged"] = True
|
||||
payload["elapsedMs"] = int((now - started) * 1000)
|
||||
emit(payload, output)
|
||||
records += 1
|
||||
last_heartbeat = now
|
||||
if args.once or payload["providerStatus"] in {"root-unavailable", "root-reused"} or \
|
||||
(now - started) * 1000 >= args.duration_ms:
|
||||
ended_normally = True
|
||||
break
|
||||
time.sleep(args.interval_ms / 1000)
|
||||
if not ended_normally:
|
||||
emit({"schema": SCHEMA, "event": "limit", "reason": "max-records"}, output)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
@@ -970,7 +970,7 @@ def ego_core_plan(command, env):
|
||||
return "%s had no thread plan for %d cores; added a copy of its %s-core plan" % (EGO_RESTRICTIONS, count, source.group(2))
|
||||
|
||||
|
||||
def wait_forwarding_signals(process):
|
||||
def wait_forwarding_signals_raw(process):
|
||||
def forward(signum, frame):
|
||||
try:
|
||||
process.send_signal(signum)
|
||||
@@ -983,22 +983,55 @@ def wait_forwarding_signals(process):
|
||||
finally:
|
||||
for signum, handler in previous.items():
|
||||
signal.signal(signum, handler)
|
||||
return code
|
||||
|
||||
|
||||
def wait_forwarding_signals(process):
|
||||
code = wait_forwarding_signals_raw(process)
|
||||
return 128 - code if code < 0 else code
|
||||
|
||||
|
||||
def start(launch, launch_env, digest, after=None):
|
||||
def diagnostic_game_event(event, app_id, values=None):
|
||||
fields = ["event=" + event, "app_id=" + app_id]
|
||||
fields.extend("%s=%s" % item for item in (values or {}).items())
|
||||
print("DROIDDECK_DIAGNOSTICS " + " ".join(fields), file=sys.stderr, flush=True)
|
||||
|
||||
|
||||
def diagnostic_game_exit(app_id, raw_code, source=None, wrapper_status=None):
|
||||
normalized = 128 - raw_code if raw_code < 0 else raw_code
|
||||
values = {
|
||||
"raw_status": raw_code,
|
||||
"normalized_status": normalized,
|
||||
"wrapper_status": normalized if wrapper_status is None else wrapper_status,
|
||||
"signal": -raw_code if raw_code < 0 else 0,
|
||||
}
|
||||
if source is not None:
|
||||
values["source"] = source
|
||||
diagnostic_game_event("game_exit", app_id, values)
|
||||
|
||||
|
||||
def start(launch, launch_env, digest, after=None, diagnostic_app_id=None):
|
||||
if len(launch) > 1 and launch[1] == "waitforexitandrun":
|
||||
ubisoft_composition_off(launch[0], launch_env)
|
||||
if after:
|
||||
if after or diagnostic_app_id is not None:
|
||||
process = subprocess.Popen(launch, env=launch_env)
|
||||
if diagnostic_app_id is not None:
|
||||
diagnostic_game_event("game_start", diagnostic_app_id)
|
||||
try:
|
||||
return wait_forwarding_signals(process)
|
||||
raw_code = wait_forwarding_signals_raw(process)
|
||||
finally:
|
||||
try:
|
||||
after()
|
||||
except OSError as error:
|
||||
print("droiddeck-game-env: DiRT telemetry fix: prefix ws2_32 not put back (%s); the next launch does it" % error,
|
||||
file=sys.stderr)
|
||||
if after:
|
||||
try:
|
||||
after()
|
||||
except OSError as error:
|
||||
print("droiddeck-game-env: DiRT telemetry fix: prefix ws2_32 not put back (%s); the next launch does it" % error,
|
||||
file=sys.stderr)
|
||||
code = 128 - raw_code if raw_code < 0 else raw_code
|
||||
if digest and after is None and code == 0:
|
||||
record_install_scripts(digest, launch_env)
|
||||
if diagnostic_app_id is not None:
|
||||
diagnostic_game_exit(diagnostic_app_id, raw_code)
|
||||
return code
|
||||
if digest:
|
||||
code = subprocess.run(launch, env=launch_env, check=False).returncode
|
||||
if code == 0:
|
||||
@@ -1023,10 +1056,11 @@ def main():
|
||||
except OSError:
|
||||
digest = None
|
||||
app_id = game_id(env)
|
||||
waiting = bool(app_id and len(command) > 1 and command[1] == "waitforexitandrun")
|
||||
diagnostic_app_id = app_id if waiting and os.environ.get("DROIDDECK_ENHANCED_DIAGNOSTICS") == "1" else None
|
||||
dirt_prefix = None
|
||||
if app_id:
|
||||
gl_default = gl_vsync(env)
|
||||
waiting = len(command) > 1 and command[1] == "waitforexitandrun"
|
||||
if waiting:
|
||||
game_images(env)
|
||||
fixes = {}
|
||||
@@ -1104,6 +1138,8 @@ def main():
|
||||
print("droiddeck-game-env: Xbox launch could not start (%s)" % error, file=sys.stderr)
|
||||
return 1
|
||||
if xbox_result is not None:
|
||||
if diagnostic_app_id is not None and isinstance(xbox_result, int):
|
||||
diagnostic_game_exit(diagnostic_app_id, xbox_result, "xbox", xbox_result % 256)
|
||||
return xbox_result
|
||||
after = None
|
||||
prefix = env.get("STEAM_COMPAT_DATA_PATH", "").rstrip("/")
|
||||
@@ -1129,13 +1165,13 @@ def main():
|
||||
launch, launch_env = select_sync(command, env, sync)
|
||||
if launch[0] != command[0]:
|
||||
try:
|
||||
return start(launch, launch_env, digest, after)
|
||||
return start(launch, launch_env, digest, after, diagnostic_app_id)
|
||||
except OSError as error:
|
||||
print("droiddeck-game-env: %s could not start (%s); stock launch" % (launch[0], error), file=sys.stderr)
|
||||
launch, launch_env = command, without_pack(launch_env, env)
|
||||
record_stock(sync, launch, launch_env)
|
||||
try:
|
||||
return start(launch, launch_env, digest, after)
|
||||
return start(launch, launch_env, digest, after, diagnostic_app_id)
|
||||
except OSError:
|
||||
if after:
|
||||
try:
|
||||
|
||||
@@ -22,6 +22,19 @@ if [ -n "${BL_LOG:-}" ] && [ -z "${BL_INSIDE:-}" ]; then
|
||||
echo "== rootfs: $(cat /.version 2>/dev/null || echo unversioned)"
|
||||
fi
|
||||
|
||||
start_diagnostic_inventory() {
|
||||
[ "${DROIDDECK_ENHANCED_DIAGNOSTICS:-0}" = 1 ] || return 0
|
||||
[ -z "${BL_INSIDE:-}" ] || return 0
|
||||
if ! command -v droiddeck-diagnostic-inventory >/dev/null 2>&1; then
|
||||
printf '%s\n' 'DROIDDECK_PROCESS_TRACE {"schema":1,"event":"provider","status":"unavailable"}'
|
||||
return 0
|
||||
fi
|
||||
droiddeck-diagnostic-inventory --watch --root-pid "$$" &
|
||||
_bl_diagnostic_inventory=$!
|
||||
trap 'kill "$_bl_diagnostic_inventory" 2>/dev/null || true; wait "$_bl_diagnostic_inventory" 2>/dev/null || true' EXIT
|
||||
}
|
||||
start_diagnostic_inventory
|
||||
|
||||
sync_timezone() {
|
||||
local zone=${TZ:-}
|
||||
case "$zone" in ''|/*|*..*) return 0 ;; esac
|
||||
@@ -141,8 +154,13 @@ run_gamescope() (
|
||||
BL_STEAM_EXIT_FILE="$status_file" gamescope "$@"
|
||||
compositor_status=$?
|
||||
if read -r child_status < "$status_file" && [[ $child_status =~ ^[0-9]{1,3}$ ]] \
|
||||
&& [ "$child_status" -gt 0 ] && [ "$child_status" -le 255 ]; then
|
||||
exit "$child_status"
|
||||
&& [ "$child_status" -le 255 ]; then
|
||||
if [ "${DROIDDECK_ENHANCED_DIAGNOSTICS:-0}" = 1 ]; then
|
||||
printf 'DROIDDECK_DIAGNOSTICS event=session_exit compositor_status=%s steam_status=%s\n' "$compositor_status" "$child_status"
|
||||
fi
|
||||
[ "$child_status" -eq 0 ] || exit "$child_status"
|
||||
elif [ "${DROIDDECK_ENHANCED_DIAGNOSTICS:-0}" = 1 ]; then
|
||||
printf 'DROIDDECK_DIAGNOSTICS event=session_exit compositor_status=%s steam_status=unavailable\n' "$compositor_status"
|
||||
fi
|
||||
exit "$compositor_status"
|
||||
)
|
||||
@@ -1489,6 +1507,9 @@ case $mode in
|
||||
wait "$desktop_ui_pid" 2>/dev/null || true
|
||||
fi
|
||||
echo "== steam exited rc=$rc"
|
||||
if [ "${DROIDDECK_ENHANCED_DIAGNOSTICS:-0}" = 1 ]; then
|
||||
printf 'DROIDDECK_DIAGNOSTICS event=steam_exit shell_status=%s elapsed_seconds=%s\n' "$rc" "$steam_ran"
|
||||
fi
|
||||
collect_steam_logs
|
||||
if [ -f "$HOME/.config/droiddeck/fex-wanted" ] && [ -x /usr/local/bin/droiddeck-fex ]; then
|
||||
/usr/local/bin/droiddeck-fex status >/dev/null 2>&1 || true
|
||||
|
||||
@@ -0,0 +1,234 @@
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import runpy
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
SCRIPT = ROOT / "tools/linuxfs/overlay/usr/local/bin/droiddeck-diagnostic-inventory"
|
||||
MODULE = runpy.run_path(str(SCRIPT), run_name="droiddeck_diagnostic_inventory")
|
||||
|
||||
|
||||
def write_process(root, pid, ppid, start, comm, cmdline, maps=None):
|
||||
process = root / str(pid)
|
||||
process.mkdir(parents=True)
|
||||
children = process / "task" / str(pid) / "children"
|
||||
children.parent.mkdir(parents=True)
|
||||
children.write_text("")
|
||||
fields = ["S", str(ppid)] + ["0"] * 17 + [str(start)]
|
||||
(process / "stat").write_text(f"{pid} ({comm}) " + " ".join(fields) + "\n")
|
||||
(process / "comm").write_text(comm + "\n")
|
||||
(process / "cmdline").write_bytes(cmdline.replace(" ", "\0").encode() + b"\0")
|
||||
if maps is not None:
|
||||
(process / "maps").write_text("".join(
|
||||
f"1000-2000 r-xp 00000000 00:00 0 {path}\n" for path in maps
|
||||
))
|
||||
parent_children = root / str(ppid) / "task" / str(ppid) / "children"
|
||||
if parent_children.is_file():
|
||||
existing = parent_children.read_text().split()
|
||||
if str(pid) not in existing:
|
||||
parent_children.write_text(" ".join(existing + [str(pid)]) + "\n")
|
||||
return process
|
||||
|
||||
|
||||
def rows(text):
|
||||
prefix = MODULE["PREFIX"]
|
||||
return [json.loads(line.removeprefix(prefix)) for line in text.splitlines() if line.startswith(prefix)]
|
||||
|
||||
|
||||
class DiagnosticInventoryTest(unittest.TestCase):
|
||||
def test_default_off_produces_no_output(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
output = io.StringIO()
|
||||
result = MODULE["main"](
|
||||
["--once", "--root-pid", "100", "--proc-root", directory], {}, output,
|
||||
)
|
||||
self.assertEqual(result, 0)
|
||||
self.assertEqual(output.getvalue(), "")
|
||||
|
||||
def test_once_scopes_processes_and_reports_only_safe_graphics_identity(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
proc = Path(directory)
|
||||
write_process(proc, 100, 1, 10, "droiddeck-session", "/usr/local/bin/droiddeck-session steam", [
|
||||
"/usr/lib/libvulkan.so.1",
|
||||
])
|
||||
write_process(proc, 101, 100, 11, "steam", "/secret/account/steam -login private-token", [
|
||||
"/data/user/0/com.droiddeck.launcher/files/components/system-vulkan/abc/libVkLayer_hybris_compat.so",
|
||||
"/data/user/0/com.droiddeck.launcher/files/components/system-vulkan/abc/libvulkan-private-account.so",
|
||||
"/data/user/0/com.droiddeck.launcher/files/components/system-vulkan/abc/libdrm_accountSecret.so",
|
||||
"/data/user/0/com.droiddeck.launcher/files/components/system-vulkan/abc/libxcb-sessionSecret.so",
|
||||
"/data/user/0/com.droiddeck.launcher/files/components/system-vulkan/abc/libvkd3d-userSecret.so",
|
||||
"/data/user/0/com.droiddeck.launcher/files/components/system-vulkan/abc/libdrm_amdgpu.so.1.0.0",
|
||||
"/home/private-user/not-graphics-secret.so",
|
||||
"/home/private-user/libvulkan-private-user.so",
|
||||
])
|
||||
write_process(proc, 102, 101, 12, "steamwebhelper", "steamwebhelper --user-data-dir=/secret/profile", [
|
||||
"/vendor/lib64/hw/vulkan.samsung.so",
|
||||
"/tmp/libvulkan-secret with spaces.so",
|
||||
])
|
||||
write_process(proc, 103, 101, 13, "private-game-title", "private-game-title --token=child-secret", [])
|
||||
write_process(proc, 200, 1, 20, "unrelated", "unrelated --password=hunter2", [
|
||||
"/vendor/lib64/hw/vulkan.unrelated.so",
|
||||
])
|
||||
output = io.StringIO()
|
||||
MODULE["main"](
|
||||
["--once", "--root-pid", "100", "--proc-root", directory],
|
||||
{"DROIDDECK_ENHANCED_DIAGNOSTICS": "1"}, output,
|
||||
)
|
||||
payloads = rows(output.getvalue())
|
||||
self.assertEqual(payloads[0]["event"], "provider")
|
||||
snapshot = payloads[1]
|
||||
self.assertEqual(snapshot["alive"], 4)
|
||||
self.assertEqual(snapshot["roles"], {
|
||||
"game-or-helper": 1, "session": 1, "steam-client": 1, "steam-webhelper": 1,
|
||||
})
|
||||
self.assertEqual(snapshot["providerStatus"], "available")
|
||||
self.assertEqual(snapshot["scopeMethod"], "children")
|
||||
self.assertFalse(snapshot["scopeIncomplete"])
|
||||
libraries = {(item["name"], item["origin"]) for item in snapshot["libraries"]}
|
||||
self.assertIn(("libvulkan.so.1", "guest-runtime"), libraries)
|
||||
self.assertIn(("libVkLayer_hybris_compat.so", "droiddeck-component"), libraries)
|
||||
self.assertIn(("libdrm_amdgpu.so.1.0.0", "droiddeck-component"), libraries)
|
||||
self.assertIn(("vulkan.samsung.so", "android-vendor"), libraries)
|
||||
self.assertTrue(any(name.startswith("sha256:") and origin == "other" for name, origin in libraries))
|
||||
self.assertGreaterEqual(sum(name.startswith("sha256:") and origin == "droiddeck-component"
|
||||
for name, origin in libraries), 4)
|
||||
text = output.getvalue()
|
||||
for secret in ("private-token", "private-user", "child-secret", "private-game-title", "hunter2",
|
||||
"accountSecret", "sessionSecret", "userSecret", "unrelated", "/vendor/", "/data/user/"):
|
||||
self.assertNotIn(secret, text)
|
||||
|
||||
def test_missing_maps_and_proc_are_explicit(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
proc = Path(directory)
|
||||
write_process(proc, 100, 1, 10, "droiddeck-session", "droiddeck-session")
|
||||
collector = MODULE["Collector"](proc, 100)
|
||||
snapshot, _ = collector.scan()
|
||||
self.assertEqual(snapshot["maps"]["unavailable"], 1)
|
||||
self.assertEqual(snapshot["providerStatus"], "available")
|
||||
missing = MODULE["Collector"](proc / "missing", 100)
|
||||
snapshot, _ = missing.scan()
|
||||
self.assertEqual(snapshot["providerStatus"], "proc-unavailable")
|
||||
|
||||
def test_children_fallback_is_explicitly_incomplete(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
proc = Path(directory)
|
||||
process = write_process(proc, 100, 1, 10, "droiddeck-session", "droiddeck-session", [])
|
||||
write_process(proc, 101, 100, 11, "steam", "steam", [])
|
||||
(process / "task" / "100" / "children").unlink()
|
||||
collector = MODULE["Collector"](proc, 100)
|
||||
snapshot, _ = collector.scan()
|
||||
self.assertEqual(snapshot["alive"], 2)
|
||||
self.assertEqual(snapshot["scopeMethod"], "children+scan-fallback")
|
||||
self.assertTrue(snapshot["scopeIncomplete"])
|
||||
|
||||
def test_pid_reuse_is_an_exit_and_a_new_process(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
proc = Path(directory)
|
||||
write_process(proc, 99, 1, 9, "droiddeck-session", "droiddeck-session", [])
|
||||
process = write_process(proc, 100, 99, 10, "steam", "steam", [])
|
||||
collector = MODULE["Collector"](proc, 99)
|
||||
first, _ = collector.scan()
|
||||
first_token = next(row["token"] for row in first["started"] if row["role"] == "steam-client")
|
||||
fields = ["S", "99"] + ["0"] * 17 + ["20"]
|
||||
(process / "stat").write_text("100 (steam) " + " ".join(fields) + "\n")
|
||||
second, changed = collector.scan()
|
||||
self.assertTrue(changed)
|
||||
self.assertEqual(next(row["token"] for row in second["exited"] if row["role"] == "steam-client"), first_token)
|
||||
self.assertNotEqual(
|
||||
next(row["token"] for row in second["started"] if row["role"] == "steam-client"), first_token,
|
||||
)
|
||||
|
||||
def test_exec_role_change_is_reported_without_pid_reuse(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
proc = Path(directory)
|
||||
process = write_process(proc, 100, 1, 10, "droiddeck-session", "droiddeck-session", [])
|
||||
collector = MODULE["Collector"](proc, 100)
|
||||
collector.scan()
|
||||
(process / "comm").write_text("gamescope\n")
|
||||
(process / "cmdline").write_bytes(b"gamescope\0--backend\0wayland\0")
|
||||
snapshot, changed = collector.scan()
|
||||
self.assertTrue(changed)
|
||||
self.assertEqual(snapshot["roles"], {"gamescope": 1})
|
||||
|
||||
def test_process_scope_is_bounded(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
proc = Path(directory)
|
||||
write_process(proc, 100, 1, 10, "droiddeck-session", "droiddeck-session", [])
|
||||
for pid in range(101, 370):
|
||||
write_process(proc, pid, 100, pid, "helper", "helper", [])
|
||||
collector = MODULE["Collector"](proc, 100)
|
||||
snapshot, _ = collector.scan()
|
||||
self.assertLessEqual(snapshot["alive"], MODULE["MAX_PROCESSES"])
|
||||
self.assertTrue(snapshot["scopeCapped"])
|
||||
|
||||
def test_reused_root_pid_is_not_adopted(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
proc = Path(directory)
|
||||
process = write_process(proc, 100, 1, 10, "droiddeck-session", "droiddeck-session", [])
|
||||
collector = MODULE["Collector"](proc, 100)
|
||||
collector.scan()
|
||||
fields = ["S", "1"] + ["0"] * 17 + ["20"]
|
||||
(process / "stat").write_text("100 (unrelated-app) " + " ".join(fields) + "\n")
|
||||
snapshot, _ = collector.scan()
|
||||
self.assertEqual(snapshot["providerStatus"], "root-reused")
|
||||
self.assertEqual(snapshot["alive"], 0)
|
||||
self.assertNotIn("unrelated-app", json.dumps(snapshot))
|
||||
|
||||
def test_reparented_child_is_rejected_after_process_reads(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
proc = Path(directory)
|
||||
write_process(proc, 100, 1, 10, "droiddeck-session", "droiddeck-session", [])
|
||||
child = write_process(proc, 101, 100, 11, "steam", "steam", [])
|
||||
globals_ = MODULE["Collector"].scan.__globals__
|
||||
original = globals_["process_stat"]
|
||||
calls = 0
|
||||
|
||||
def racing(path):
|
||||
nonlocal calls
|
||||
if path == child / "stat":
|
||||
calls += 1
|
||||
if calls == 3:
|
||||
fields = ["S", "1"] + ["0"] * 17 + ["11"]
|
||||
path.write_text("101 (steam) " + " ".join(fields) + "\n")
|
||||
return original(path)
|
||||
|
||||
globals_["process_stat"] = racing
|
||||
try:
|
||||
collector = MODULE["Collector"](proc, 100)
|
||||
snapshot, _ = collector.scan()
|
||||
finally:
|
||||
globals_["process_stat"] = original
|
||||
self.assertEqual(snapshot["roles"], {"session": 1})
|
||||
self.assertEqual(snapshot["alive"], 1)
|
||||
|
||||
def test_watch_is_bounded_and_emits_heartbeats_without_process_changes(self):
|
||||
globals_ = MODULE["main"].__globals__
|
||||
original = globals_["HEARTBEAT_MS"]
|
||||
globals_["HEARTBEAT_MS"] = 40
|
||||
try:
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
proc = Path(directory)
|
||||
write_process(proc, 100, 1, 10, "droiddeck-session", "droiddeck-session", [])
|
||||
output = io.StringIO()
|
||||
MODULE["main"](
|
||||
["--watch", "--root-pid", "100", "--proc-root", directory,
|
||||
"--interval-ms", "250", "--duration-ms", "520", "--max-records", "4"],
|
||||
{"DROIDDECK_ENHANCED_DIAGNOSTICS": "1"}, output,
|
||||
)
|
||||
payloads = rows(output.getvalue())
|
||||
self.assertEqual(payloads[0]["event"], "provider")
|
||||
self.assertEqual(payloads[1]["event"], "snapshot")
|
||||
self.assertEqual(payloads[2]["event"], "heartbeat")
|
||||
self.assertNotIn("libraries", payloads[2])
|
||||
self.assertTrue(payloads[2]["librariesUnchanged"])
|
||||
self.assertLessEqual(len(payloads), 4)
|
||||
finally:
|
||||
globals_["HEARTBEAT_MS"] = original
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,50 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
|
||||
SESSION = Path(__file__).resolve().parents[1] / 'linuxfs/overlay/usr/local/bin/droiddeck-session'
|
||||
|
||||
|
||||
class DiagnosticSessionIntegrationTest(unittest.TestCase):
|
||||
def run_inventory(self, enabled, inside=False, installed=True):
|
||||
source = SESSION.read_text()
|
||||
match = re.search(r'^start_diagnostic_inventory\(\) \{\n.*?^\}\n', source, re.M | re.S)
|
||||
self.assertIsNotNone(match)
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
marker = root / 'called'
|
||||
if installed:
|
||||
helper = root / 'droiddeck-diagnostic-inventory'
|
||||
helper.write_text('#!/bin/bash\nprintf "%s\\n" "$@" > "$MARKER"\n')
|
||||
helper.chmod(0o755)
|
||||
env = dict(os.environ, PATH=str(root) + os.pathsep + os.environ['PATH'],
|
||||
MARKER=str(marker), DROIDDECK_ENHANCED_DIAGNOSTICS='1' if enabled else '0')
|
||||
env['BL_INSIDE'] = '1' if inside else ''
|
||||
script = match.group() + '\nstart_diagnostic_inventory\n'
|
||||
if installed and enabled and not inside:
|
||||
script += 'wait "$_bl_diagnostic_inventory"\n'
|
||||
result = subprocess.run(['bash', '-c', script], env=env, capture_output=True, text=True, timeout=10)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
return marker.read_text().splitlines() if marker.exists() else [], result.stdout
|
||||
|
||||
def test_starts_for_an_enhanced_outer_session(self):
|
||||
arguments, _ = self.run_inventory(True)
|
||||
self.assertEqual(arguments[:2], ['--watch', '--root-pid'])
|
||||
self.assertTrue(arguments[2].isdigit())
|
||||
|
||||
def test_does_not_start_when_disabled_or_inside_gamescope(self):
|
||||
self.assertEqual(self.run_inventory(False)[0], [])
|
||||
self.assertEqual(self.run_inventory(True, inside=True)[0], [])
|
||||
|
||||
def test_reports_when_the_provider_is_not_installed(self):
|
||||
_, output = self.run_inventory(True, installed=False)
|
||||
self.assertIn('DROIDDECK_PROCESS_TRACE', output)
|
||||
self.assertIn('"status":"unavailable"', output)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -0,0 +1,186 @@
|
||||
import contextlib
|
||||
import io
|
||||
import os
|
||||
from pathlib import Path
|
||||
import runpy
|
||||
import signal
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
from unittest import mock
|
||||
import unittest
|
||||
|
||||
|
||||
BIN = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin"
|
||||
GAME_ENV = BIN / "droiddeck-game-env"
|
||||
MODULE = runpy.run_path(str(GAME_ENV))
|
||||
|
||||
|
||||
class GameExitDiagnosticsTest(unittest.TestCase):
|
||||
def run_child(self, body, app_id="42"):
|
||||
with contextlib.redirect_stderr(io.StringIO()) as said:
|
||||
status = MODULE["start"](
|
||||
[sys.executable, "-c", body], os.environ.copy(), None,
|
||||
diagnostic_app_id=app_id,
|
||||
)
|
||||
return status, said.getvalue()
|
||||
|
||||
def test_clean_and_nonzero_exits_are_authoritative(self):
|
||||
for child_status in (0, 7):
|
||||
with self.subTest(status=child_status):
|
||||
status, said = self.run_child("import sys; sys.exit(%d)" % child_status)
|
||||
self.assertEqual(status, child_status)
|
||||
self.assertIn("event=game_start app_id=42", said)
|
||||
self.assertIn(
|
||||
"event=game_exit app_id=42 raw_status=%d normalized_status=%d wrapper_status=%d signal=0" %
|
||||
(child_status, child_status, child_status), said,
|
||||
)
|
||||
|
||||
def test_signal_exit_is_normalized_and_records_the_signal(self):
|
||||
status, said = self.run_child("import os, signal; os.kill(os.getpid(), signal.SIGTERM)")
|
||||
self.assertEqual(status, 128 + signal.SIGTERM)
|
||||
self.assertIn(
|
||||
"event=game_exit app_id=42 raw_status=-15 normalized_status=143 wrapper_status=143 signal=15", said,
|
||||
)
|
||||
|
||||
def test_xbox_exit_is_recorded_without_inventing_a_start(self):
|
||||
with contextlib.redirect_stderr(io.StringIO()) as said:
|
||||
MODULE["diagnostic_game_exit"]("42", -signal.SIGTERM, "xbox", 241)
|
||||
self.assertNotIn("event=game_start", said.getvalue())
|
||||
self.assertIn(
|
||||
"event=game_exit app_id=42 raw_status=-15 normalized_status=143 wrapper_status=241 signal=15 source=xbox",
|
||||
said.getvalue(),
|
||||
)
|
||||
|
||||
def test_signal_handler_forwards_to_the_child(self):
|
||||
class Process:
|
||||
def __init__(self):
|
||||
self.forwarded = []
|
||||
|
||||
def send_signal(self, signum):
|
||||
self.forwarded.append(signum)
|
||||
|
||||
def wait(self):
|
||||
os.kill(os.getpid(), signal.SIGTERM)
|
||||
return -signal.SIGTERM
|
||||
|
||||
process = Process()
|
||||
self.assertEqual(MODULE["wait_forwarding_signals"](process), 128 + signal.SIGTERM)
|
||||
self.assertEqual(process.forwarded, [signal.SIGTERM])
|
||||
|
||||
def test_default_path_still_execs_in_place_without_diagnostic_output(self):
|
||||
called = []
|
||||
with mock.patch("os.execvpe", side_effect=lambda *args: called.append(args)), \
|
||||
contextlib.redirect_stderr(io.StringIO()) as said:
|
||||
MODULE["start"](["/game", "arg"], {"A": "B"}, None)
|
||||
self.assertEqual(called, [("/game", ["/game", "arg"], {"A": "B"})])
|
||||
self.assertNotIn("DROIDDECK_DIAGNOSTICS", said.getvalue())
|
||||
|
||||
def test_failed_selected_launch_does_not_invent_a_start_or_exit(self):
|
||||
with mock.patch("subprocess.Popen", side_effect=FileNotFoundError("missing")), \
|
||||
contextlib.redirect_stderr(io.StringIO()) as said:
|
||||
with self.assertRaises(FileNotFoundError):
|
||||
MODULE["start"](["/missing"], {}, None, diagnostic_app_id="42")
|
||||
self.assertNotIn("DROIDDECK_DIAGNOSTICS", said.getvalue())
|
||||
|
||||
def test_cleanup_runs_after_a_diagnostic_child(self):
|
||||
cleaned = []
|
||||
with contextlib.redirect_stderr(io.StringIO()):
|
||||
status = MODULE["start"](
|
||||
[sys.executable, "-c", "pass"], os.environ.copy(), None,
|
||||
after=lambda: cleaned.append(True), diagnostic_app_id="42",
|
||||
)
|
||||
self.assertEqual(status, 0)
|
||||
self.assertEqual(cleaned, [True])
|
||||
|
||||
def test_diagnostic_install_script_keeps_success_recording(self):
|
||||
recorded = []
|
||||
with mock.patch.dict(MODULE["start"].__globals__, record_install_scripts=lambda digest, env: recorded.append((digest, env))), \
|
||||
contextlib.redirect_stderr(io.StringIO()):
|
||||
status = MODULE["start"](
|
||||
[sys.executable, "-c", "pass"], {"CUSTOM": "kept"}, "digest",
|
||||
diagnostic_app_id="42",
|
||||
)
|
||||
self.assertEqual(status, 0)
|
||||
self.assertEqual(recorded, [("digest", {"CUSTOM": "kept"})])
|
||||
|
||||
def test_cleanup_path_keeps_the_original_install_recording_precedence(self):
|
||||
recorded = []
|
||||
with mock.patch.dict(MODULE["start"].__globals__, record_install_scripts=lambda digest, env: recorded.append((digest, env))):
|
||||
status = MODULE["start"](
|
||||
[sys.executable, "-c", "pass"], {"CUSTOM": "kept"}, "digest",
|
||||
after=lambda: None,
|
||||
)
|
||||
self.assertEqual(status, 0)
|
||||
self.assertEqual(recorded, [])
|
||||
|
||||
def test_main_only_traces_valid_waitforexitandrun_games(self):
|
||||
with tempfile.TemporaryDirectory(prefix="game-exit-diagnostics-") as directory:
|
||||
root = Path(directory)
|
||||
probe = root / "probe"
|
||||
probe.write_text("#!" + sys.executable + "\nimport sys\nsys.exit(7)\n")
|
||||
probe.chmod(0o755)
|
||||
base = dict(os.environ, HOME=directory, PATH=os.defpath,
|
||||
DROIDDECK_ENHANCED_DIAGNOSTICS="1")
|
||||
valid = subprocess.run(
|
||||
[sys.executable, str(GAME_ENV), str(probe), "waitforexitandrun"],
|
||||
env={**base, "STEAM_COMPAT_DATA_PATH": "/compatdata/42"},
|
||||
capture_output=True, text=True, timeout=15,
|
||||
)
|
||||
self.assertEqual(valid.returncode, 7, valid.stderr)
|
||||
self.assertIn("event=game_start app_id=42", valid.stderr)
|
||||
self.assertIn(
|
||||
"event=game_exit app_id=42 raw_status=7 normalized_status=7 wrapper_status=7 signal=0", valid.stderr,
|
||||
)
|
||||
|
||||
for verb, prefix in (("run", "/compatdata/42"), ("waitforexitandrun", "/compatdata/not-a-game")):
|
||||
result = subprocess.run(
|
||||
[sys.executable, str(GAME_ENV), str(probe), verb],
|
||||
env={**base, "STEAM_COMPAT_DATA_PATH": prefix},
|
||||
capture_output=True, text=True, timeout=15,
|
||||
)
|
||||
self.assertEqual(result.returncode, 7, result.stderr)
|
||||
self.assertNotIn("DROIDDECK_DIAGNOSTICS", result.stderr)
|
||||
|
||||
def test_main_records_xbox_result_without_changing_it(self):
|
||||
launch = lambda command, env: 23
|
||||
with tempfile.TemporaryDirectory(prefix="xbox-exit-diagnostics-") as directory, \
|
||||
mock.patch.dict(os.environ, {
|
||||
"HOME": directory,
|
||||
"PATH": os.defpath,
|
||||
"STEAM_COMPAT_DATA_PATH": "/compatdata/42",
|
||||
"DROIDDECK_ENHANCED_DIAGNOSTICS": "1",
|
||||
}, clear=True), \
|
||||
mock.patch("sys.argv", ["droiddeck-game-env", "/proton", "waitforexitandrun", "game.exe"]), \
|
||||
mock.patch("runpy.run_path", return_value={"launch": launch}), \
|
||||
contextlib.redirect_stderr(io.StringIO()) as said:
|
||||
status = MODULE["main"]()
|
||||
self.assertEqual(status, 23)
|
||||
self.assertNotIn("event=game_start", said.getvalue())
|
||||
self.assertIn(
|
||||
"event=game_exit app_id=42 raw_status=23 normalized_status=23 wrapper_status=23 signal=0 source=xbox",
|
||||
said.getvalue(),
|
||||
)
|
||||
|
||||
def test_main_preserves_negative_xbox_result_and_reports_wrapper_status(self):
|
||||
launch = lambda command, env: -signal.SIGTERM
|
||||
with tempfile.TemporaryDirectory(prefix="xbox-signal-diagnostics-") as directory, \
|
||||
mock.patch.dict(os.environ, {
|
||||
"HOME": directory,
|
||||
"PATH": os.defpath,
|
||||
"STEAM_COMPAT_DATA_PATH": "/compatdata/42",
|
||||
"DROIDDECK_ENHANCED_DIAGNOSTICS": "1",
|
||||
}, clear=True), \
|
||||
mock.patch("sys.argv", ["droiddeck-game-env", "/proton", "waitforexitandrun", "game.exe"]), \
|
||||
mock.patch("runpy.run_path", return_value={"launch": launch}), \
|
||||
contextlib.redirect_stderr(io.StringIO()) as said:
|
||||
status = MODULE["main"]()
|
||||
self.assertEqual(status, -signal.SIGTERM)
|
||||
self.assertIn(
|
||||
"event=game_exit app_id=42 raw_status=-15 normalized_status=143 wrapper_status=241 signal=15 source=xbox",
|
||||
said.getvalue(),
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,133 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
PATCH = ROOT / "tools/gamescope/patches/0900-enhanced-frame-diagnostics.patch"
|
||||
|
||||
|
||||
def added_file(patch, name):
|
||||
lines = patch.read_text().splitlines()
|
||||
marker = f"diff --git a/{name} b/{name}"
|
||||
start = lines.index(marker)
|
||||
output = []
|
||||
in_hunk = False
|
||||
for line in lines[start + 1:]:
|
||||
if line.startswith("diff --git "):
|
||||
break
|
||||
if line.startswith("@@"):
|
||||
in_hunk = True
|
||||
elif in_hunk and line.startswith("+") and not line.startswith("+++"):
|
||||
output.append(line[1:])
|
||||
return "\n".join(output) + "\n"
|
||||
|
||||
|
||||
class GamescopeDiagnosticsTest(unittest.TestCase):
|
||||
def test_patch_covers_each_frame_boundary_without_payload_logging(self):
|
||||
text = PATCH.read_text()
|
||||
for path in ("src/wlserver.cpp", "src/steamcompmgr.cpp", "src/Backends/WaylandBackend.cpp"):
|
||||
self.assertIn(f"diff --git a/{path} b/{path}", text)
|
||||
self.assertIn("diff --git a/src/main.cpp b/src/main.cpp", text)
|
||||
self.assertIn("droiddeck::frame_trace::Start();", text)
|
||||
self.assertIn("droiddeck::frame_trace::Tick();", text)
|
||||
self.assertIn("pTraceFocus->focusWindow == w", text)
|
||||
self.assertNotIn("GetFocusForWindow( w ) != nullptr", text)
|
||||
for event in (
|
||||
"X11Damage", "X11DamageCurrent", "X11DamageOther", "SurfaceCommit",
|
||||
"SurfaceCommitBuffer", "SurfaceCommitNoBuffer", "CommitDequeued",
|
||||
"CommitDequeuedCurrent", "CommitDequeuedOther", "ImportSucceeded",
|
||||
"ImportSucceededCurrent", "ImportSucceededOther", "ImportFailed",
|
||||
"ImportFailedCurrent", "ImportFailedOther", "FenceReady", "FenceWaited",
|
||||
"CommitDone", "CommitDoneCurrent", "CommitDoneOther", "BaseLatched",
|
||||
"BaseLatchedCurrent", "BaseLatchedOther",
|
||||
"OutputPresent", "OutputAttach", "OutputDetach",
|
||||
"OutputCommit", "OutputRelease",
|
||||
):
|
||||
self.assertIn(f"Event::{event}", text)
|
||||
header = added_file(PATCH, "src/droiddeck_frame_trace.hpp")
|
||||
self.assertIn('std::getenv( "DROIDDECK_ENHANCED_DIAGNOSTICS" )', header)
|
||||
self.assertIn("DROIDDECK_FRAME_TRACE_FAST_INTERVAL_MS 2000", header)
|
||||
self.assertIn("DROIDDECK_FRAME_TRACE_SLOW_INTERVAL_MS 15000", header)
|
||||
self.assertIn("DROIDDECK_FRAME_TRACE_DURATION_MS 86400000", header)
|
||||
self.assertNotRegex(header, re.compile(r"title|pixel|address|argv", re.I))
|
||||
|
||||
def test_collector_is_default_off_bounded_and_thread_safe(self):
|
||||
compiler = shutil.which(os.environ.get("CXX", "c++"))
|
||||
if not compiler:
|
||||
self.skipTest("a C++ compiler is required")
|
||||
with tempfile.TemporaryDirectory(prefix="gamescope-frame-trace-") as directory:
|
||||
work = Path(directory)
|
||||
(work / "droiddeck_frame_trace.hpp").write_text(
|
||||
added_file(PATCH, "src/droiddeck_frame_trace.hpp"))
|
||||
(work / "trace.cpp").write_text(r'''
|
||||
#include "droiddeck_frame_trace.hpp"
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
int main() {
|
||||
droiddeck::frame_trace::Start();
|
||||
std::vector<std::thread> threads;
|
||||
for (int i = 0; i < 4; ++i)
|
||||
threads.emplace_back([] { for (int n = 0; n < 1000; ++n)
|
||||
droiddeck::frame_trace::RecordWindow(
|
||||
droiddeck::frame_trace::Event::X11Damage,
|
||||
droiddeck::frame_trace::Event::X11DamageCurrent,
|
||||
droiddeck::frame_trace::Event::X11DamageOther,
|
||||
false); });
|
||||
for (auto &thread : threads) thread.join();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(60));
|
||||
droiddeck::frame_trace::Tick();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(70));
|
||||
droiddeck::frame_trace::Tick();
|
||||
droiddeck::frame_trace::Record(droiddeck::frame_trace::Event::SurfaceCommit);
|
||||
droiddeck::frame_trace::RecordWindow(
|
||||
droiddeck::frame_trace::Event::ImportSucceeded,
|
||||
droiddeck::frame_trace::Event::ImportSucceededCurrent,
|
||||
droiddeck::frame_trace::Event::ImportSucceededOther,
|
||||
true);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(70));
|
||||
droiddeck::frame_trace::Tick();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(120));
|
||||
droiddeck::frame_trace::Tick();
|
||||
droiddeck::frame_trace::Record(droiddeck::frame_trace::Event::OutputPresent);
|
||||
droiddeck::frame_trace::Tick();
|
||||
}
|
||||
''')
|
||||
program = work / "trace"
|
||||
built = subprocess.run([
|
||||
compiler, "-std=c++20", "-Wall", "-Wextra", "-Werror", "-pthread",
|
||||
"-DDROIDDECK_FRAME_TRACE_FAST_INTERVAL_MS=50",
|
||||
"-DDROIDDECK_FRAME_TRACE_SLOW_INTERVAL_MS=60",
|
||||
"-DDROIDDECK_FRAME_TRACE_FAST_DURATION_MS=100",
|
||||
"-DDROIDDECK_FRAME_TRACE_DURATION_MS=300",
|
||||
str(work / "trace.cpp"), "-o", str(program),
|
||||
], capture_output=True, text=True)
|
||||
self.assertEqual(0, built.returncode, built.stdout + built.stderr)
|
||||
quiet = subprocess.run([str(program)], capture_output=True, text=True, timeout=10)
|
||||
self.assertEqual(0, quiet.returncode, quiet.stdout + quiet.stderr)
|
||||
self.assertEqual("", quiet.stderr)
|
||||
env = os.environ.copy()
|
||||
env["DROIDDECK_ENHANCED_DIAGNOSTICS"] = "1"
|
||||
traced = subprocess.run([str(program)], env=env, capture_output=True, text=True, timeout=10)
|
||||
self.assertEqual(0, traced.returncode, traced.stdout + traced.stderr)
|
||||
self.assertEqual(1, traced.stderr.count("schema=1"))
|
||||
summaries = [line for line in traced.stderr.splitlines() if "t_ms=" in line]
|
||||
self.assertIn("t_ms=0 x11_damage=0", summaries[0])
|
||||
self.assertTrue(any("x11_damage=4000" in line and "x11_damage_current=0" in line and
|
||||
"x11_damage_other=4000" in line and "surface_commit=0" in line
|
||||
for line in summaries[1:]))
|
||||
self.assertTrue(any("surface_commit=1" in line for line in summaries[1:]))
|
||||
self.assertTrue(any("import_ok=1" in line and "import_ok_current=1" in line and
|
||||
"import_ok_other=0" in line for line in summaries[1:]))
|
||||
self.assertIn("t_ms=300", summaries[-1])
|
||||
self.assertIn("output_present=0", summaries[-1])
|
||||
self.assertLessEqual(len(summaries), 5)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -11,7 +11,7 @@ SESSION = Path(__file__).resolve().parents[1] / 'linuxfs/overlay/usr/local/bin/d
|
||||
|
||||
class SteamExitStatusTest(unittest.TestCase):
|
||||
def run_session(self, child_status, compositor_status=0, report=True, report_value=None,
|
||||
stale_status=None):
|
||||
stale_status=None, diagnostics=False, output=False):
|
||||
source = SESSION.read_text()
|
||||
function = re.search(r'^run_gamescope\(\) \(\n.*?^\)\n', source, re.M | re.S)
|
||||
self.assertIsNotNone(function)
|
||||
@@ -31,6 +31,7 @@ class SteamExitStatusTest(unittest.TestCase):
|
||||
child.chmod(0o755)
|
||||
env = dict(os.environ, PATH=str(root) + os.pathsep + os.environ['PATH'],
|
||||
XDG_RUNTIME_DIR=str(root))
|
||||
env['DROIDDECK_ENHANCED_DIAGNOSTICS'] = '1' if diagnostics else '0'
|
||||
result = subprocess.run(['bash', '-c', function.group() + '\nrun_gamescope "$@"',
|
||||
'session', str(child), str(child_status),
|
||||
str(report_value) if report_value is not None else ''], env=env,
|
||||
@@ -38,7 +39,7 @@ class SteamExitStatusTest(unittest.TestCase):
|
||||
self.assertEqual(list(root.glob('droiddeck-steam-exit.??????')), [])
|
||||
if stale_status is not None:
|
||||
self.assertEqual(stale_file.read_text(), str(stale_status) + '\n')
|
||||
return result.returncode
|
||||
return result if output else result.returncode
|
||||
|
||||
def test_steam_crash_survives_successful_compositor_shutdown(self):
|
||||
self.assertEqual(self.run_session(139), 139)
|
||||
@@ -64,6 +65,21 @@ class SteamExitStatusTest(unittest.TestCase):
|
||||
def test_stale_marker_does_not_affect_a_new_launch(self):
|
||||
self.assertEqual(self.run_session(0, report=False, stale_status=139), 0)
|
||||
|
||||
def test_diagnostics_preserve_separate_steam_and_compositor_statuses(self):
|
||||
result = self.run_session(139, diagnostics=True, output=True)
|
||||
self.assertEqual(result.returncode, 139)
|
||||
self.assertIn('event=session_exit compositor_status=0 steam_status=139', result.stdout)
|
||||
|
||||
def test_diagnostics_report_an_unavailable_child_status(self):
|
||||
result = self.run_session(0, compositor_status=1, report=False, diagnostics=True, output=True)
|
||||
self.assertEqual(result.returncode, 1)
|
||||
self.assertIn('event=session_exit compositor_status=1 steam_status=unavailable', result.stdout)
|
||||
|
||||
def test_diagnostics_are_disabled_by_default(self):
|
||||
result = self.run_session(0, output=True)
|
||||
self.assertEqual(result.returncode, 0)
|
||||
self.assertNotIn('DROIDDECK_DIAGNOSTICS', result.stdout)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user