"""Measure only Home hero -> Continue Watching on the authorized onn release. Run without competing UI tests. Captures and traces remain private. """ import argparse,json,time from device import adb,OUT from verify_ui import launch,key,wait,focus,focused def frames(raw): result=[] for block in raw.split('---PROFILEDATA---')[1::2]: lines=[line.strip() for line in block.splitlines() if line.strip()] if not lines:continue names=lines[0].rstrip(',').split(',') for line in lines[1:]: values=line.rstrip(',').split(',') if len(values)!=len(names):continue row=dict(zip(names,map(int,values))) if row['Flags']==0 and row['FrameCompleted']>row['IntendedVsync']: result.append((row['FrameCompleted']-row['IntendedVsync'])/1e6) return result def percentile(values,p):return sorted(values)[min(len(values)-1,int((len(values)-1)*p))] def main(): parser=argparse.ArgumentParser();parser.add_argument('label');parser.add_argument('--cycles',type=int,default=5);parser.add_argument('--trace',action='store_true');parser.add_argument('--cold',action='store_true');args=parser.parse_args() assert args.cycles>0,'At least one transition is required' launch();key(20);wait(lambda r:focus(r) in ('Play','Resume'),'Hero action') # Warm the same row and artwork once, then return to the hero before timing. if not args.cold: key(20);wait(lambda r:focus(r) not in ('','Home','Play','Resume'),'Continue Watching card');time.sleep(.7) key(19);wait(lambda r:focus(r) in ('Play','Resume'),'Return to hero');time.sleep(.7) if args.trace:adb('shell','atrace','--async_start','-b','32768','-a','tv.kaleido.app','gfx','view','sched','freq') all_frames=[];runs=[] try: for index in range(args.cycles): adb('shell','dumpsys','gfxinfo','tv.kaleido.app','reset') adb('shell','input','keyevent','20');time.sleep(1) raw=adb('shell','dumpsys','gfxinfo','tv.kaleido.app','framestats').decode(errors='replace') (OUT/f'home-{args.label}-{index}-frames.txt').write_text(raw) sample=frames(raw);assert sample,'No measured frames' all_frames.extend(sample);runs.append({'frames':len(sample),'median':percentile(sample,.5),'p95':percentile(sample,.95),'max':max(sample)}) print('Down transition',index+1,json.dumps(runs[-1]),flush=True) wait(lambda r:focus(r) not in ('','Home','Play','Resume'),'Continue Watching focus') key(19);wait(lambda r:focus(r) in ('Play','Resume'),'Hero focus restored');time.sleep(.7) finally: if args.trace: raw=adb('shell','atrace','--async_stop','-a','tv.kaleido.app','gfx','view','sched','freq') (OUT/f'home-{args.label}-atrace.txt').write_bytes(raw) result={'runs':runs,'frames':len(all_frames),'median':percentile(all_frames,.5),'p95':percentile(all_frames,.95),'over33msPercent':100*sum(x>33.34 for x in all_frames)/len(all_frames),'max':max(all_frames)} (OUT/f'home-{args.label}-results.json').write_text(json.dumps(result,indent=2)+'\n') print(json.dumps(result),flush=True) key(19);focused('Home') assert result['p95']<33.34,f"Hero-to-row p95 {result['p95']:.1f} ms exceeds two 60Hz frame intervals" if __name__=='__main__':main()