Add WiVRn-native Perfetto via Perfetto SDK
Optional server profiling built on the Perfetto SDK. Adds CPU spans (compositor, encoder, network), GPU encode/copy slices from Vulkan timestamp queries (Vulkan/NVENC/VAAPI), and headset feedback markers from dump_time. WIVRN_TRACING enables tracing and selects the backend (system, inprocess, or both); WIVRN_USE_PERFETTO gates it at build time and compiles it out otherwise. WIVRN_TRACE_MONADO additionally drives Monado's percetto tracing from the same switch so WiVRn and Monado land on one timeline. Tooling: server-tracing[-monado] presets and a CI build, two Perfetto configs (WiVRn-only and full-system), a wivrn_capture.py capture wrapper, a pftrace summary script, and docs/profiling.md.
This commit is contained in:
@@ -0,0 +1,235 @@
|
||||
#!/usr/bin/env python3
|
||||
# Perfetto pftrace summarizer — pairs BEGIN/END by trusted_packet_sequence_id.
|
||||
# Single file: per-slice stats table.
|
||||
# Two files: side-by-side diff table (pass in either order).
|
||||
|
||||
import collections
|
||||
import statistics
|
||||
import sys
|
||||
|
||||
|
||||
def read_varint(buf, off):
|
||||
v = 0
|
||||
shift = 0
|
||||
while True:
|
||||
b = buf[off]
|
||||
off += 1
|
||||
v |= (b & 0x7F) << shift
|
||||
if not (b & 0x80):
|
||||
return v, off
|
||||
shift += 7
|
||||
|
||||
|
||||
def read_tag(buf, off):
|
||||
tag, off = read_varint(buf, off)
|
||||
return tag >> 3, tag & 7, off
|
||||
|
||||
|
||||
def skip(buf, off, wt):
|
||||
if wt == 0:
|
||||
_, off = read_varint(buf, off)
|
||||
return off
|
||||
if wt == 1:
|
||||
return off + 8
|
||||
if wt == 2:
|
||||
ln, off = read_varint(buf, off)
|
||||
return off + ln
|
||||
if wt == 5:
|
||||
return off + 4
|
||||
raise ValueError(f"unknown wt {wt}")
|
||||
|
||||
|
||||
def parse_track_event(buf, off, end):
|
||||
name = None
|
||||
ev_type = None
|
||||
while off < end:
|
||||
fid, wt, off = read_tag(buf, off)
|
||||
if fid == 23 and wt == 2:
|
||||
ln, off = read_varint(buf, off)
|
||||
name = buf[off : off + ln].decode("utf-8", "replace")
|
||||
off += ln
|
||||
elif fid == 9 and wt == 0:
|
||||
ev_type, off = read_varint(buf, off)
|
||||
else:
|
||||
off = skip(buf, off, wt)
|
||||
return name, ev_type
|
||||
|
||||
|
||||
def parse(path):
|
||||
with open(path, "rb") as f:
|
||||
buf = f.read()
|
||||
durations = collections.defaultdict(list)
|
||||
open_stack = collections.defaultdict(list) # seq_id -> [(name, ts)]
|
||||
ts_min = ts_max = None
|
||||
|
||||
off = 0
|
||||
n = len(buf)
|
||||
while off < n:
|
||||
fid, wt, off = read_tag(buf, off)
|
||||
if fid != 1 or wt != 2:
|
||||
off = skip(buf, off, wt)
|
||||
continue
|
||||
ln, off = read_varint(buf, off)
|
||||
end = off + ln
|
||||
ts = None
|
||||
seq = None
|
||||
te_name = None
|
||||
te_type = None
|
||||
while off < end:
|
||||
f2, wt2, off = read_tag(buf, off)
|
||||
if f2 == 8 and wt2 == 0:
|
||||
ts, off = read_varint(buf, off)
|
||||
elif f2 == 10 and wt2 == 0:
|
||||
seq, off = read_varint(buf, off)
|
||||
elif f2 == 11 and wt2 == 2:
|
||||
ln2, off = read_varint(buf, off)
|
||||
te_name, te_type = parse_track_event(buf, off, off + ln2)
|
||||
off += ln2
|
||||
else:
|
||||
off = skip(buf, off, wt2)
|
||||
if (
|
||||
ts is not None and te_type is not None
|
||||
): # only real events, not metadata packets with ts=0
|
||||
if ts_min is None or ts < ts_min:
|
||||
ts_min = ts
|
||||
if ts_max is None or ts > ts_max:
|
||||
ts_max = ts
|
||||
if te_type is not None:
|
||||
if te_type == 1 and te_name and ts is not None:
|
||||
open_stack[seq].append((te_name, ts))
|
||||
elif te_type == 2 and ts is not None and open_stack[seq]:
|
||||
bname, bts = open_stack[seq].pop()
|
||||
durations[bname].append(ts - bts)
|
||||
|
||||
span = (ts_max - ts_min) if ts_min is not None else 0
|
||||
return dict(durations), span, len(buf)
|
||||
|
||||
|
||||
def _is_instant(dur_list):
|
||||
return all(d == 0 for d in dur_list)
|
||||
|
||||
|
||||
def _stats(dur_list, span):
|
||||
srt = sorted(dur_list)
|
||||
p99 = srt[int(len(srt) * 0.99)] if len(srt) > 1 else srt[0]
|
||||
rate = len(dur_list) / (span / 1e9) if span else 0
|
||||
return (
|
||||
len(dur_list),
|
||||
statistics.mean(dur_list) / 1e6,
|
||||
statistics.median(dur_list) / 1e6,
|
||||
p99 / 1e6,
|
||||
max(dur_list) / 1e6,
|
||||
rate,
|
||||
)
|
||||
|
||||
|
||||
def summarize(path):
|
||||
durations, span, size = parse(path)
|
||||
print(f"\n=== {path} ===")
|
||||
print(f" file size: {size:,} bytes")
|
||||
print(f" trace span: {span / 1e9:.3f} s")
|
||||
|
||||
rows = []
|
||||
for name, dur_list in durations.items():
|
||||
if not dur_list or _is_instant(dur_list):
|
||||
continue
|
||||
rows.append((name,) + _stats(dur_list, span))
|
||||
rows.sort(key=lambda r: -r[1])
|
||||
print(
|
||||
f" {'slice':<32} {'n':>6} {'mean ms':>9} {'p50 ms':>8} {'p99 ms':>8} {'max ms':>8} {'rate/s':>8}"
|
||||
)
|
||||
for r in rows[:30]:
|
||||
print(
|
||||
f" {r[0]:<32} {r[1]:>6} {r[2]:>9.3f} {r[3]:>8.3f} {r[4]:>8.3f} {r[5]:>8.3f} {r[6]:>8.1f}"
|
||||
)
|
||||
|
||||
instants = [(n, _stats(d, span)) for n, d in durations.items() if d and _is_instant(d)]
|
||||
if instants:
|
||||
instants.sort(key=lambda x: -x[1][5])
|
||||
print(f"\n {'instant':<32} {'n':>6} {'rate/s':>8}")
|
||||
for name, st in instants:
|
||||
print(f" {name:<32} {st[0]:>6} {st[5]:>8.1f}")
|
||||
|
||||
|
||||
def compare(path_a, path_b):
|
||||
dur_a, span_a, size_a = parse(path_a)
|
||||
dur_b, span_b, size_b = parse(path_b)
|
||||
|
||||
label_a = path_a.rsplit("/", 1)[-1]
|
||||
label_b = path_b.rsplit("/", 1)[-1]
|
||||
|
||||
print(f"\n=== {label_a} vs {label_b} ===")
|
||||
print(
|
||||
f" A: {size_a:,} bytes {span_a / 1e9:.3f} s B: {size_b:,} bytes {span_b / 1e9:.3f} s"
|
||||
)
|
||||
|
||||
all_names = sorted(set(dur_a) | set(dur_b))
|
||||
span_names = [
|
||||
n
|
||||
for n in all_names
|
||||
if (dur_a.get(n) and not _is_instant(dur_a[n]))
|
||||
or (dur_b.get(n) and not _is_instant(dur_b[n]))
|
||||
]
|
||||
|
||||
def fmt_cell(dur_list, span):
|
||||
if not dur_list or _is_instant(dur_list):
|
||||
return f"{'–':>5} {'–':>8} {'–':>8} {'–':>8}"
|
||||
st = _stats(dur_list, span)
|
||||
return f"{st[0]:>5} {st[1]:>8.3f} {st[2]:>8.3f} {st[3]:>8.3f}"
|
||||
|
||||
def fmt_delta(da, db):
|
||||
if not da or _is_instant(da) or not db or _is_instant(db):
|
||||
return ""
|
||||
ma = statistics.mean(da) / 1e6
|
||||
mb = statistics.mean(db) / 1e6
|
||||
diff = mb - ma
|
||||
pct = diff / ma * 100 if ma else 0
|
||||
sign = "+" if diff >= 0 else ""
|
||||
return f"{sign}{diff:.3f} ms ({sign}{pct:.0f}%)"
|
||||
|
||||
col_w = 36 # n + mean + p50 + p99
|
||||
print(
|
||||
f"\n {'slice':<32} {'── A: ' + label_a[:26]:<{col_w}} {'── B: ' + label_b[:26]:<{col_w}} delta"
|
||||
)
|
||||
print(
|
||||
f" {'':32} {'n':>5} {'mean ms':>8} {'p50 ms':>8} {'p99 ms':>8}"
|
||||
f" {'n':>5} {'mean ms':>8} {'p50 ms':>8} {'p99 ms':>8}"
|
||||
)
|
||||
print(" " + "-" * 110)
|
||||
|
||||
# Sort by combined mean (largest first = most interesting)
|
||||
def sort_key(n):
|
||||
ma = statistics.mean(dur_a[n]) if dur_a.get(n) and not _is_instant(dur_a[n]) else 0
|
||||
mb = statistics.mean(dur_b[n]) if dur_b.get(n) and not _is_instant(dur_b[n]) else 0
|
||||
return -(ma + mb)
|
||||
|
||||
for name in sorted(span_names, key=sort_key):
|
||||
da = dur_a.get(name, [])
|
||||
db = dur_b.get(name, [])
|
||||
print(f" {name:<32} {fmt_cell(da, span_a)} {fmt_cell(db, span_b)} {fmt_delta(da, db)}")
|
||||
|
||||
instant_names = [
|
||||
n
|
||||
for n in all_names
|
||||
if (dur_a.get(n) and _is_instant(dur_a[n])) or (dur_b.get(n) and _is_instant(dur_b[n]))
|
||||
]
|
||||
if instant_names:
|
||||
print(f"\n {'instant':<32} {'rate/s (A)':>12} {'rate/s (B)':>12}")
|
||||
for name in sorted(instant_names):
|
||||
da = dur_a.get(name, [])
|
||||
db = dur_b.get(name, [])
|
||||
ra = f"{len(da) / (span_a / 1e9):.1f}" if da and span_a else "–"
|
||||
rb = f"{len(db) / (span_b / 1e9):.1f}" if db and span_b else "–"
|
||||
print(f" {name:<32} {ra:>12} {rb:>12}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) < 2:
|
||||
print("usage: pftrace_summary.py <trace.pftrace> [second.pftrace]", file=sys.stderr)
|
||||
sys.exit(2)
|
||||
if len(sys.argv) == 3:
|
||||
compare(sys.argv[1], sys.argv[2])
|
||||
else:
|
||||
for p in sys.argv[1:]:
|
||||
summarize(p)
|
||||
print("\n open in https://ui.perfetto.dev for the visual timeline")
|
||||
Executable
+317
@@ -0,0 +1,317 @@
|
||||
#!/usr/bin/env python3
|
||||
"""One-command Perfetto capture for wivrn-server (run with WIVRN_TRACING=system).
|
||||
|
||||
wivrn_capture.py # WiVRn-only (default)
|
||||
wivrn_capture.py --full # full-system capture
|
||||
wivrn_capture.py -c custom.pbtx # any perfetto config
|
||||
wivrn_capture.py --cpu-only # strip ftrace from config
|
||||
wivrn_capture.py --duration-ms 30000 -o my.pftrace
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import atexit
|
||||
import os
|
||||
import re
|
||||
import signal
|
||||
import stat
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import time
|
||||
import urllib.request
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
SCRIPT_DIR = Path(__file__).resolve().parent
|
||||
TRACEBOX_URL = "https://get.perfetto.dev/tracebox"
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Helpers
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def xdg(var, default_rel):
|
||||
"""Resolve an XDG base directory."""
|
||||
val = os.environ.get(var)
|
||||
return Path(val) if val else Path.home() / default_rel
|
||||
|
||||
|
||||
def strip_ftrace_blocks(text):
|
||||
"""Remove any data_sources { ... } block containing name: "linux.ftrace"."""
|
||||
lines = text.splitlines(keepends=True)
|
||||
result = []
|
||||
in_block = False
|
||||
depth = 0
|
||||
buf = []
|
||||
for line in lines:
|
||||
if not in_block:
|
||||
if re.match(r"^data_sources\s*\{", line):
|
||||
in_block = True
|
||||
depth = 1
|
||||
buf = [line]
|
||||
else:
|
||||
result.append(line)
|
||||
else:
|
||||
buf.append(line)
|
||||
depth += line.count("{") - line.count("}")
|
||||
if depth == 0:
|
||||
if not re.search(r'name:\s*"linux\.ftrace"', "".join(buf)):
|
||||
result.extend(buf)
|
||||
in_block = False
|
||||
buf = []
|
||||
return "".join(result)
|
||||
|
||||
|
||||
def needs_ftrace(text):
|
||||
return bool(re.search(r'name:\s*"linux\.ftrace"', text))
|
||||
|
||||
|
||||
def download_tracebox(url, dest):
|
||||
"""Download url to dest with a simple progress indicator."""
|
||||
print(f"wivrn_capture: downloading tracebox to {dest}")
|
||||
try:
|
||||
with urllib.request.urlopen(url) as resp:
|
||||
total = int(resp.headers.get("Content-Length", 0))
|
||||
downloaded = 0
|
||||
with open(dest, "wb") as f:
|
||||
while True:
|
||||
chunk = resp.read(65536)
|
||||
if not chunk:
|
||||
break
|
||||
f.write(chunk)
|
||||
downloaded += len(chunk)
|
||||
if total:
|
||||
pct = downloaded * 100 // total
|
||||
print(
|
||||
f"\r {downloaded / 1e6:.1f} / {total / 1e6:.1f} MB ({pct}%)",
|
||||
end="",
|
||||
flush=True,
|
||||
)
|
||||
else:
|
||||
print(f"\r {downloaded / 1e6:.1f} MB", end="", flush=True)
|
||||
print()
|
||||
except Exception as e:
|
||||
Path(dest).unlink(missing_ok=True)
|
||||
sys.exit(f"wivrn_capture: download failed: {e}")
|
||||
|
||||
|
||||
def ensure_tracebox(path):
|
||||
if path.is_file() and os.access(path, os.X_OK):
|
||||
return
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
download_tracebox(TRACEBOX_URL, path)
|
||||
path.chmod(path.stat().st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
|
||||
|
||||
|
||||
def pgrep(name):
|
||||
"""Return list of matching PIDs (as strings), or []."""
|
||||
r = subprocess.run(["pgrep", "-x", name], capture_output=True, text=True)
|
||||
return r.stdout.split() if r.returncode == 0 else []
|
||||
|
||||
|
||||
def socket_listening(sock_path):
|
||||
"""Return True if a Unix socket at sock_path is bound and listening."""
|
||||
r = subprocess.run(["ss", "-lxH", "src", str(sock_path)], capture_output=True, text=True)
|
||||
return bool(r.stdout.strip())
|
||||
|
||||
|
||||
def wait_for_producer(tracebox, env, timeout_s=20):
|
||||
"""True once a track_event data source registers (wivrn-server connected)."""
|
||||
deadline = time.time() + timeout_s
|
||||
while time.time() < deadline:
|
||||
r = subprocess.run(
|
||||
[str(tracebox), "perfetto", "--query"], env=env, capture_output=True, text=True
|
||||
)
|
||||
if "track_event" in r.stdout:
|
||||
return True
|
||||
time.sleep(0.5)
|
||||
return False
|
||||
|
||||
|
||||
def log(msg):
|
||||
print(f"wivrn_capture: {msg}")
|
||||
|
||||
|
||||
def err(msg):
|
||||
print(f"wivrn_capture: {msg}", file=sys.stderr)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Main
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def main():
|
||||
cache_dir = xdg("XDG_CACHE_HOME", ".cache") / "wivrn"
|
||||
tracebox = cache_dir / "tracebox"
|
||||
sock_dir = Path(os.environ.get("XDG_RUNTIME_DIR", "/tmp"))
|
||||
producer_sock = sock_dir / "wivrn-perfetto-producer.sock"
|
||||
consumer_sock = sock_dir / "wivrn-perfetto-consumer.sock"
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
prog=Path(sys.argv[0]).name,
|
||||
description="One-command Perfetto capture for wivrn-server.",
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||
epilog=f"Run: WIVRN_TRACING=system wivrn-server (socket: {producer_sock})",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-c",
|
||||
"--config",
|
||||
metavar="PATH",
|
||||
help="Perfetto config (default: wivrn_trace_cfg.pbtx — "
|
||||
"WiVRn track_event categories only, no ftrace)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--full",
|
||||
action="store_true",
|
||||
help="Shorthand for -c wivrn_full_trace_cfg.pbtx (every category + broader ftrace)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-o", "--output", metavar="PATH", help="Output .pftrace path (default: wivrn-<ts>.pftrace)"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--cpu-only",
|
||||
action="store_true",
|
||||
help="Strip any linux.ftrace data source from the config "
|
||||
"(no traced_probes / no sudo needed)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--duration-ms", metavar="N", type=int, help="Override duration_ms in the config"
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
# Resolve config.
|
||||
if args.full:
|
||||
cfg = SCRIPT_DIR / "wivrn_full_trace_cfg.pbtx"
|
||||
elif args.config:
|
||||
cfg = Path(args.config)
|
||||
else:
|
||||
cfg = SCRIPT_DIR / "wivrn_trace_cfg.pbtx"
|
||||
|
||||
# Resolve output filename.
|
||||
if args.output:
|
||||
out = Path(args.output)
|
||||
else:
|
||||
ts = datetime.now().strftime("%Y%m%d-%H%M%S")
|
||||
out = Path(f"wivrn-{ts}.pftrace")
|
||||
|
||||
if not cfg.is_file():
|
||||
sys.exit(f"wivrn_capture: missing config: {cfg}")
|
||||
log(f"using config {cfg}")
|
||||
|
||||
ensure_tracebox(tracebox)
|
||||
|
||||
# Build the runtime config (strip ftrace / override duration as needed).
|
||||
cfg_text = cfg.read_text()
|
||||
if args.cpu_only:
|
||||
cfg_text = strip_ftrace_blocks(cfg_text)
|
||||
if args.duration_ms is not None:
|
||||
cfg_text = re.sub(
|
||||
r"^duration_ms: \d+", f"duration_ms: {args.duration_ms}", cfg_text, flags=re.MULTILINE
|
||||
)
|
||||
|
||||
run_cfg_fd, run_cfg_path = tempfile.mkstemp(suffix=".pbtx")
|
||||
run_cfg = Path(run_cfg_path)
|
||||
try:
|
||||
os.write(run_cfg_fd, cfg_text.encode())
|
||||
finally:
|
||||
os.close(run_cfg_fd)
|
||||
|
||||
use_ftrace = needs_ftrace(cfg_text)
|
||||
sudo = ["sudo", "-E"] if use_ftrace else []
|
||||
user = os.environ.get("USER", os.getlogin())
|
||||
|
||||
log("run a client and stream during capture, or the trace is empty")
|
||||
|
||||
# Clean up stale sockets from crashed runs; traced won't reuse them.
|
||||
producer_sock.unlink(missing_ok=True)
|
||||
consumer_sock.unlink(missing_ok=True)
|
||||
|
||||
started_traced = False
|
||||
started_probes = False
|
||||
|
||||
def cleanup():
|
||||
run_cfg.unlink(missing_ok=True)
|
||||
if started_probes:
|
||||
subprocess.run([*sudo, "pkill", "-x", "traced_probes"], capture_output=True)
|
||||
if started_traced:
|
||||
subprocess.run([*sudo, "pkill", "-x", "traced"], capture_output=True)
|
||||
producer_sock.unlink(missing_ok=True)
|
||||
consumer_sock.unlink(missing_ok=True)
|
||||
|
||||
atexit.register(cleanup)
|
||||
|
||||
# Route SIGTERM / SIGINT through sys.exit so atexit cleanup runs.
|
||||
def _sig(signum, _frame):
|
||||
sys.exit(128 + signum)
|
||||
|
||||
signal.signal(signal.SIGTERM, _sig)
|
||||
signal.signal(signal.SIGINT, _sig)
|
||||
|
||||
# Reuse an existing traced only if it owns our sockets.
|
||||
existing = pgrep("traced")
|
||||
if existing:
|
||||
if not socket_listening(consumer_sock):
|
||||
pids = ", ".join(existing)
|
||||
err(f"traced (pid {pids}) not on {consumer_sock}; kill it and re-run")
|
||||
sys.exit(1)
|
||||
else:
|
||||
# traced reads socket paths from env vars, not CLI flags.
|
||||
env = {
|
||||
**os.environ,
|
||||
"PERFETTO_PRODUCER_SOCK_NAME": str(producer_sock),
|
||||
"PERFETTO_CONSUMER_SOCK_NAME": str(consumer_sock),
|
||||
}
|
||||
traced_cmd = [*sudo, str(tracebox), "traced", "--background"]
|
||||
if use_ftrace:
|
||||
traced_cmd += ["--set-socket-permissions", f"{user}:0660:{user}:0660"]
|
||||
subprocess.run(traced_cmd, env=env, check=True)
|
||||
started_traced = True
|
||||
time.sleep(0.3)
|
||||
|
||||
if use_ftrace and not pgrep("traced_probes"):
|
||||
env = {**os.environ, "PERFETTO_PRODUCER_SOCK_NAME": str(producer_sock)}
|
||||
subprocess.run([*sudo, str(tracebox), "traced_probes", "--background"], env=env, check=True)
|
||||
started_probes = True
|
||||
time.sleep(0.3)
|
||||
|
||||
if not producer_sock.is_socket():
|
||||
err(f"traced did not bind {producer_sock}")
|
||||
sys.exit(1)
|
||||
|
||||
env = {
|
||||
**os.environ,
|
||||
"PERFETTO_PRODUCER_SOCK_NAME": str(producer_sock),
|
||||
"PERFETTO_CONSUMER_SOCK_NAME": str(consumer_sock),
|
||||
}
|
||||
|
||||
# Wait for the producer; abort rather than capture an empty trace.
|
||||
log("waiting for producer…")
|
||||
if not wait_for_producer(tracebox, env):
|
||||
err(
|
||||
"no track_event producer after 20s — is wivrn-server running with "
|
||||
"WIVRN_TRACING and a client streaming?"
|
||||
)
|
||||
err("(if it just worked, restart wivrn-server — the producer doesn't reconnect)")
|
||||
sys.exit(1)
|
||||
|
||||
log(f"capturing → {out}")
|
||||
subprocess.run(
|
||||
[str(tracebox), "perfetto", "-c", str(run_cfg), "--txt", "-o", str(out)],
|
||||
env=env,
|
||||
check=True,
|
||||
)
|
||||
|
||||
print()
|
||||
trace_bytes = out.stat().st_size if out.exists() else 0
|
||||
log(f"wrote {out} ({trace_bytes} bytes)")
|
||||
|
||||
if trace_bytes < 4096:
|
||||
err("trace looks empty — was a client streaming during capture?")
|
||||
else:
|
||||
log("open in https://ui.perfetto.dev")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,78 @@
|
||||
# Full-system Perfetto config: like wivrn_trace_cfg.pbtx but unfiltered — every
|
||||
# track_event category plus broad ftrace (sched, freq, GPU, IRQs, vblank). Use
|
||||
# it to see WiVRn in context with the rest of the system. Bigger traces, needs
|
||||
# sudo for ftrace.
|
||||
#
|
||||
# Capture: tools/perfetto/wivrn_capture.py --full
|
||||
# Manual setup and socket details: docs/profiling.md.
|
||||
|
||||
duration_ms: 5000
|
||||
|
||||
# Two buffers on purpose: in a shared ring buffer the high-volume ftrace stream
|
||||
# evicts the low-volume track_event chunks by age before the trace is written,
|
||||
# losing the WiVRn/Monado slices. Isolating track_event keeps it from eviction.
|
||||
buffers { # buffer 0: WiVRn + Monado track_event
|
||||
size_kb: 65536
|
||||
fill_policy: RING_BUFFER
|
||||
}
|
||||
buffers { # buffer 1: high-volume system data (ftrace + process/system info)
|
||||
size_kb: 262144
|
||||
fill_policy: RING_BUFFER
|
||||
}
|
||||
|
||||
# Unfiltered track_event: every category from every producer is recorded.
|
||||
data_sources {
|
||||
config {
|
||||
name: "track_event"
|
||||
target_buffer: 0
|
||||
track_event_config {
|
||||
enabled_categories: "*"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Broader system context than the default config: scheduling, frequency,
|
||||
# OpenXR/graphics frame timing, GPU frequency/memory, and IRQs.
|
||||
data_sources {
|
||||
config {
|
||||
name: "linux.ftrace"
|
||||
target_buffer: 1
|
||||
ftrace_config {
|
||||
ftrace_events: "sched/sched_switch"
|
||||
ftrace_events: "sched/sched_waking"
|
||||
ftrace_events: "sched/sched_process_exit"
|
||||
ftrace_events: "sched/sched_process_free"
|
||||
ftrace_events: "power/cpu_frequency"
|
||||
ftrace_events: "power/cpu_idle"
|
||||
ftrace_events: "power/gpu_frequency"
|
||||
ftrace_events: "power/suspend_resume"
|
||||
ftrace_events: "irq/irq_handler_entry"
|
||||
ftrace_events: "irq/irq_handler_exit"
|
||||
ftrace_events: "irq/softirq_entry"
|
||||
ftrace_events: "irq/softirq_exit"
|
||||
ftrace_events: "drm/drm_vblank_event"
|
||||
atrace_categories: "gfx"
|
||||
atrace_categories: "sched"
|
||||
atrace_categories: "freq"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Process/thread names so threads show up labelled in the UI.
|
||||
data_sources {
|
||||
config {
|
||||
name: "linux.process_stats"
|
||||
target_buffer: 1
|
||||
process_stats_config {
|
||||
scan_all_processes_on_start: true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# System info: CPU count, kernel, distro.
|
||||
data_sources {
|
||||
config {
|
||||
name: "linux.system_info"
|
||||
target_buffer: 1
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
# WiVRn-only Perfetto config: WiVRn track_event slices, no ftrace. Small,
|
||||
# encoder-focused traces. For system context use wivrn_full_trace_cfg.pbtx
|
||||
# (or --full).
|
||||
#
|
||||
# Capture: tools/perfetto/wivrn_capture.py
|
||||
# Manual setup and socket details: docs/profiling.md.
|
||||
|
||||
duration_ms: 15000
|
||||
buffers {
|
||||
size_kb: 65536
|
||||
fill_policy: RING_BUFFER
|
||||
}
|
||||
|
||||
data_sources {
|
||||
config {
|
||||
name: "track_event"
|
||||
target_buffer: 0
|
||||
track_event_config {
|
||||
# Allowlist must match the category names in
|
||||
# server/utils/wivrn_trace.cpp exactly (Perfetto does exact/glob,
|
||||
# not substring matching). Listing only WiVRn categories keeps the
|
||||
# trace WiVRn-only even when Monado is built with tracing.
|
||||
# Do NOT add `disabled_categories: "*"`: it also silences the
|
||||
# enabled allowlist, giving empty traces.
|
||||
enabled_categories: "wivrn_encoder"
|
||||
enabled_categories: "wivrn_encoder_gpu"
|
||||
enabled_categories: "wivrn_compositor"
|
||||
enabled_categories: "wivrn_network"
|
||||
enabled_categories: "wivrn_feedback"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user