#!/usr/bin/env python3 """Replay: python3 composites.py RUN_DIR [SHOW_INDEX] Lists, for each sway repaint during one keyboard show cycle, the pixman_image_composite32 calls the composite shim (composite-shim.c.txt) logged inside that repaint: operator, source/mask/destination format and the source image size, summed as requested width x height (before the destination clip, so these are not painted pixel counts). """ import json, re, sys, bisect, collections d = sys.argv[1]; which = int(sys.argv[2]) if len(sys.argv) > 2 else 1 meta = json.load(open(d + '/meta.json')); off = meta['workload_start_mono'] - meta['workload_start'] text = open(d + '/shell-journal.txt').read() dmg = {int(m[1]): int(m[2]) for m in re.finditer(r'frame-damage run=\d+ frame_id=(\d+) rects=\d+ damage_px=(\d+)', text)} rep = [(int(m[2]) / 1e9, int(m[3]) / 1e9, dmg.get(int(m[1]), 0)) for m in re.finditer(r'repaint-timing run=\d+ frame_id=(\d+) scheduled_ns=\d+ delay_ms=-?\d+ start_ns=(\d+) commit_start_ns=(\d+)', text)] F = {0x20028888: 'argb', 0x20020888: 'xrgb', 0x10020565: '565', 0x8018000: 'a8', 0: '-'} OP = {0: 'CLEAR', 1: 'SRC', 3: 'OVER'} calls = [] for l in open(d + '/pxshim.log'): p = l.split() calls.append((float(p[0]), int(p[1]), int(p[2], 16), int(p[3], 16), int(p[4], 16), int(p[5]), int(p[6]), int(p[7]), int(p[8]))) ts = [c[0] for c in calls] evs = meta['events'] e = [x for x in evs if x['kind'] == 'show'][which]; i = evs.index(e) a = e['start'] + off; c = e['end'] + off; b = evs[i + 1]['start'] + off for s, cs, dm in rep: if a <= s < b: j = bisect.bisect_left(ts, s); k = bisect.bisect_left(ts, cs) agg = collections.Counter() for x in calls[j:k]: name = f"{OP.get(x[1], x[1])} {F.get(x[2], hex(x[2]))}{'/' + F.get(x[3], hex(x[3])) if x[3] else ''}->{F.get(x[4], hex(x[4]))} src{x[7]}x{x[8]}" agg[name] += x[5] * x[6] print(f"{(s - a) * 1e3:7.1f} {'C' if s <= c else 'S'} {(cs - s) * 1e3:5.1f}ms dmg={dm} " + '; '.join(f"{k2}:{v // 1000}k" for k2, v in agg.most_common()))