summaryrefslogtreecommitdiffstats
path: root/tools/guest-diag/qmp_record.py
diff options
context:
space:
mode:
authorArthur Hanson Rasmusson <arthur@vgpu.io>2026-11-17 08:44:36 -0500
committerArthur Hanson Rasmusson <arthur@vgpu.io>2026-11-17 08:44:36 -0500
commit007d1c9d51b607d9b3e1dd4b969e4e37f843d15d (patch)
treef0c2c5365435d9e45733253913d6f317c025cf16 /tools/guest-diag/qmp_record.py
parent86ee35bd03a51abf115812540dcd6d711d79e9e9 (diff)
downloadopen-iov-007d1c9d51b607d9b3e1dd4b969e4e37f843d15d.tar.gz
open-iov-007d1c9d51b607d9b3e1dd4b969e4e37f843d15d.zip
vgsp: phys_gr_dump_push_all (per-draw MME body scan); guest video harness
- gsp_phys_booter: phys_gr_dump_push_all scans every beef and 0x1000013 push for the MME IR/SA ports (0x114/0x118/0x11c/0x120) with a one-line PUSH-SCAN receipt and full-dumps upload-bearing pushes. c1030/c1035 receipts: 14895-word beef push m114=0/m11c=0; draw push 0x400f9d8 m114=0 m1b00=6 (CALL(0) 0x3800 data=0xd48 present, no macro body). - cycle-r1780: kill QEMU by exact pidfile PID (never pkill -f), refuse a foreign qemu, poll the pidfile after daemonize, virtio-vga display. - params-r1624: enable dump-all + any-channel prelude capture + draw census; fix the stale gsp_phys_gr_dump_push parameter name. - tools/guest-diag: demo-video.sh (Xvfb+XFCE desktop, nvidia-smi, GZDoom segment, honest CUDA battery) and qmp_record.py (QMP screendump).
Diffstat (limited to 'tools/guest-diag/qmp_record.py')
-rw-r--r--tools/guest-diag/qmp_record.py112
1 files changed, 112 insertions, 0 deletions
diff --git a/tools/guest-diag/qmp_record.py b/tools/guest-diag/qmp_record.py
new file mode 100644
index 0000000..026a0d8
--- /dev/null
+++ b/tools/guest-diag/qmp_record.py
@@ -0,0 +1,112 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright (c) 2026 Open-IOV contributors
+"""
+qmp_record.py - record the QEMU graphic console via QMP screendump.
+
+The guest desktop is shown on a QEMU display device (virtio-vga); QMP
+`screendump` returns the scanout as a PPM file with no guest-side capture
+agent. This script paces the dumps at a fixed rate; the host then encodes
+the numbered PPM sequence with ffmpeg.
+
+Usage:
+ qmp_record.py --out DIR [--fps 12] [--duration 90] [--socket PATH]
+ qmp_record.py --out DIR --until-file /tmp/stop # stop when file exists
+
+Every screendump is written as DIR/f000001.ppm (6-digit counter). A
+`record.log` line per second records the achieved rate and any QMP error.
+Bounded: never runs without a duration or a stop file.
+"""
+import argparse
+import json
+import os
+import socket
+import sys
+import time
+
+
+def connect(path, timeout=10.0):
+ s = socket.socket(socket.AF_UNIX)
+ s.settimeout(timeout)
+ s.connect(path)
+ f = s.makefile("rwb", buffering=0)
+ greet = json.loads(f.readline())
+ if "QMP" not in greet:
+ raise RuntimeError("not a QMP greeting: %r" % (greet,))
+ f.write(json.dumps({"execute": "qmp_capabilities"}).encode() + b"\n")
+ while True:
+ r = json.loads(f.readline())
+ if "return" in r:
+ break
+ if "error" in r:
+ raise RuntimeError("qmp_capabilities: %r" % (r,))
+ return s, f
+
+
+def main():
+ ap = argparse.ArgumentParser()
+ ap.add_argument("--socket", default="/tmp/qemu-qmp.sock")
+ ap.add_argument("--out", required=True)
+ ap.add_argument("--fps", type=float, default=12.0)
+ ap.add_argument("--duration", type=float, default=0.0)
+ ap.add_argument("--until-file", default="")
+ ap.add_argument("--max-frames", type=int, default=100000)
+ a = ap.parse_args()
+
+ if a.duration <= 0 and not a.until_file:
+ print("refusing to record unbounded (need --duration or --until-file)",
+ file=sys.stderr)
+ return 2
+ os.makedirs(a.out, exist_ok=True)
+ log = open(os.path.join(a.out, "record.log"), "w", buffering=1)
+
+ sock, f = connect(a.socket)
+ period = 1.0 / a.fps
+ t0 = time.monotonic()
+ deadline = t0 + a.duration if a.duration > 0 else 0.0
+ n = 0
+ nerr = 0
+ next_t = t0
+ last_log = t0
+ while n < a.max_frames:
+ now = time.monotonic()
+ if deadline and now >= deadline:
+ break
+ if a.until_file and os.path.exists(a.until_file):
+ break
+ if now < next_t:
+ time.sleep(next_t - now)
+ now = time.monotonic()
+ next_t += period
+ if next_t < now: # fell behind: resynchronise, do not burst
+ next_t = now
+ path = os.path.join(a.out, "f%06d.ppm" % (n + 1))
+ try:
+ f.write(json.dumps({"execute": "screendump",
+ "arguments": {"filename": path}}).encode() + b"\n")
+ r = json.loads(f.readline())
+ if "error" in r:
+ nerr += 1
+ log.write("ERROR %s %r\n" % (path, r["error"]))
+ else:
+ n += 1
+ except (socket.timeout, OSError) as e:
+ log.write("CONN %s %s\n" % (path, e))
+ break
+ if now - last_log >= 1.0:
+ log.write("t=%.1f frames=%d err=%d\n" %
+ (now - t0, n, nerr))
+ last_log = now
+ log.write("DONE frames=%d err=%d secs=%.2f\n" %
+ (n, nerr, time.monotonic() - t0))
+ log.close()
+ try:
+ sock.close()
+ except OSError:
+ pass
+ print("RECORDED %d frames in %.1fs (errors=%d)" % (n, time.monotonic() - t0, nerr))
+ return 0 if n else 1
+
+
+if __name__ == "__main__":
+ sys.exit(main())