"""Capture app atrace sections around actual remote navigation.""" import re,time,collections from device import adb,OUT from verify_ui import launch,key launch();key(20);time.sleep(2) pid=adb('shell','pidof','tv.kaleido.app').decode().strip() adb('shell','atrace','--async_start','-b','16384','-a','tv.kaleido.app','gfx','view','sched') adb('shell','input','keyevent',*(['KEYCODE_DPAD_RIGHT']*15)) adb('shell','input','keyevent',*(['KEYCODE_DPAD_DOWN']*3)) adb('shell','input','keyevent',*(['KEYCODE_DPAD_UP']*6)) raw=adb('shell','atrace','--async_stop','-a','tv.kaleido.app','gfx','view','sched').decode(errors='replace') (OUT/'browse-atrace.txt').write_text(raw) stacks=collections.defaultdict(list);spans=[] for line in raw.splitlines(): match=re.search(r'-(\d+)\s+.*?\s(\d+\.\d+): tracing_mark_write: ([BE])(?:\|(.*))?',line) if not match:continue tid,stamp,kind,payload=match.groups();stamp=float(stamp) if kind=='B': owner,_,name=(payload or '').partition('|');stacks[tid].append((stamp,name,owner)) elif stacks[tid]: start,name,owner=stacks[tid].pop() if owner==pid:spans.append(((stamp-start)*1000,name,tid)) for duration,name,tid in sorted(spans,reverse=True)[:35]:print(f'{duration:8.2f}ms tid={tid} {name}')