1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
#!/usr/bin/env python3
"""Estimate steady GUI redraw cost by subtracting matched short and long runs."""
import argparse
import json
from pathlib import Path
import statistics
import subprocess
import tempfile
import time
ROOT = Path(__file__).resolve().parents[2]
p = argparse.ArgumentParser(description=__doc__)
p.add_argument('--gui', type=Path, default=ROOT / 'gui/zig-out/bin/ztrace-gui')
p.add_argument('--c', type=Path, required=True)
p.add_argument('--v8', type=Path, required=True)
p.add_argument('--out', type=Path, default=Path('/tmp/ztrace-gui-redraw-ui.json'))
a = p.parse_args()
results = {}
with tempfile.TemporaryDirectory(prefix='ztrace-redraw-') as directory:
work = Path(directory)
for name, recording in [('c', a.c), ('v8', a.v8)]:
samples = {30: [], 330: []}
for _ in range(3):
for count in samples:
script = work / 'draw.script'
script.write_text(f'console open {recording.resolve()}\nframes {count}\n')
start = time.perf_counter_ns()
subprocess.run([str(a.gui.resolve()), '--headless', '--fresh', '--state', str(work / 'draw.state'),
'--script', str(script)], stdout=subprocess.DEVNULL, stderr=subprocess.PIPE, check=True)
samples[count].append((time.perf_counter_ns() - start) / 1e6)
results[name] = dict(elapsed_ms=samples,
incremental_frame_ms=(statistics.median(samples[330]) - statistics.median(samples[30])) / 300)
print(name, json.dumps(results[name]), flush=True)
a.out.write_text(json.dumps(results, indent=2) + '\n')
|