The question is which capture route to ship for live streaming and agent eyes. Speed alone does not decide it, so every route now also reports producer CPU and RSS, machine CPU from /proc/stat, the compositor's own CPU, and a per-frame buffer footprint -- all sampled around the measured loop, with an idle control sample so an animating page's cost is not attributed to the capture. The baseline forks a process per frame and spends 95% of each frame waiting, so the interesting finding is not which route is faster but which one leaves the compositor able to do its job: in-process acquisition roughly halves the compositor's per-frame CPU even though the machine saturates either way.
102 lines
3.8 KiB
Python
102 lines
3.8 KiB
Python
#!/usr/bin/env python3
|
|
"""Smoke test: connect to the compositor and list the globals it advertises.
|
|
|
|
Before any capture is written, this answers the question the whole route depends
|
|
on -- **which capture protocols does this compositor actually offer?** -- and
|
|
proves pywayland can bind them from this environment at all. No capture happens
|
|
here; it is the cheapest possible "is the ground solid" check.
|
|
|
|
python3 smoke_globals.py
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import sys
|
|
|
|
from pywayland.client import Display
|
|
|
|
#: Everything this spike cares about, plus the source managers the newer
|
|
#: protocol pairs with. Anything else is printed as "other" so a reader can see
|
|
#: we did not filter away a surprise.
|
|
#:
|
|
#: Note the two source managers: `ext-image-capture-source-v1` defines **one per
|
|
#: source kind**, not a single generic manager. Looking for
|
|
#: `ext_image_capture_source_manager_v1` finds nothing and reads as "the modern
|
|
#: protocol is unusable here" -- which is exactly the wrong conclusion, and this
|
|
#: spike drew it once before checking the real global list.
|
|
INTERESTING = (
|
|
"wl_shm",
|
|
"wl_output",
|
|
"zwlr_screencopy_manager_v1",
|
|
"ext_image_copy_capture_manager_v1",
|
|
"ext_output_image_capture_source_manager_v1",
|
|
"ext_foreign_toplevel_image_capture_source_manager_v1",
|
|
"ext_foreign_toplevel_list_v1",
|
|
)
|
|
|
|
|
|
def main() -> int:
|
|
display = Display()
|
|
display.connect()
|
|
registry = display.get_registry()
|
|
|
|
found: dict[str, int] = {}
|
|
all_globals: list[tuple[int, str, int]] = []
|
|
|
|
# pywayland hands the *proxy* in as the first argument, so the signature is
|
|
# (registry, name, interface, version) -- not the three a reader expects.
|
|
# Getting this wrong is silent-ish: it raises inside the dispatcher.
|
|
def on_global(registry, name: int, interface: str, version: int) -> None:
|
|
all_globals.append((name, interface, version))
|
|
if interface in INTERESTING:
|
|
found[interface] = version
|
|
|
|
registry.dispatcher["global"] = on_global
|
|
display.roundtrip()
|
|
|
|
print(f"connected: WAYLAND_DISPLAY={os.environ.get('WAYLAND_DISPLAY')!r}")
|
|
print(f"compositor fd: {display.get_fd()}")
|
|
for interface in INTERESTING:
|
|
version = found.get(interface)
|
|
mark = "yes" if version else "NO "
|
|
print(f" {mark} {interface:<38} {f'v{version}' if version else ''}")
|
|
|
|
protocols = {
|
|
"zwlr_screencopy (outputs only, deprecated)": "zwlr_screencopy_manager_v1" in found,
|
|
"ext-image-copy-capture (outputs)": (
|
|
"ext_image_copy_capture_manager_v1" in found
|
|
and "ext_output_image_capture_source_manager_v1" in found
|
|
),
|
|
"ext-image-copy-capture (single windows)": (
|
|
"ext_image_copy_capture_manager_v1" in found
|
|
and "ext_foreign_toplevel_image_capture_source_manager_v1" in found
|
|
),
|
|
}
|
|
print("\navailable capture protocols:")
|
|
for name, available in protocols.items():
|
|
print(f" {'yes' if available else 'NO '} {name}")
|
|
|
|
if not any(protocols.values()):
|
|
print(
|
|
"\nnothing to capture with: neither protocol is advertised. Check that "
|
|
"WAYLAND_DISPLAY points at the headless compositor and that "
|
|
"XDG_RUNTIME_DIR is NOT set to /run/hypr-stream (you do not own it).",
|
|
file=sys.stderr,
|
|
)
|
|
return 1
|
|
|
|
print(f"\nevery global the compositor advertises ({len(all_globals)}):")
|
|
for _, interface, version in sorted(all_globals, key=lambda row: row[1]):
|
|
print(f" v{version:<3} {interface}")
|
|
|
|
# Without this, pywayland can segfault during interpreter teardown -- after
|
|
# the work is done and the answer is printed, which makes a green run look
|
|
# like a crashed one (exit 139) to any runner reading the exit code.
|
|
display.disconnect()
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|