import subprocess,time,resource,json,sys
from pathlib import Path
p=Path(sys.argv[1]);p.mkdir(exist_ok=True,parents=True)
args=['perf','record','-F','99','-g','--call-graph','dwarf,8192','-o',str(p/'perf.data'),'--',str(p/'compiler'),'c600-init.ipucfg','--device-lock','artifacts/layout-sweep/device.lock','--package',str(p/'model.ipuexe'),'--workload','siglip-attention-benchmark','--attention-strategy','auto','--attention-batch','1','--attention-products','auto','--inspect-exchanges']
start=time.monotonic()
with (p/'run.log').open('w') as f:
 result=subprocess.run(args,stdout=f,stderr=subprocess.STDOUT)
r=resource.getrusage(resource.RUSAGE_CHILDREN)
(p/'time.json').write_text(json.dumps(dict(wall_seconds=time.monotonic()-start,user_seconds=r.ru_utime,system_seconds=r.ru_stime,max_rss_kib=r.ru_maxrss,exit_code=result.returncode),indent=2))
raise SystemExit(result.returncode)
