Files
lucisv/docs/perf/take5-review-20260908/cli_probe.py
T

30 lines
2.5 KiB
Python

import subprocess, pathlib, os, time, json, re, shutil, hashlib
root=pathlib.Path('/Users/guoliangchen/repo/verilogrustformatter')
out=pathlib.Path('/tmp/lucisv-perf-review-20260908'); corpus='/Users/guoliangchen/repo/opentitan'
tree=corpus+'/hw/ip'
binaries={'0.51.0':str(root/'target/release/lucisv'),'0.50.0':'/Users/guoliangchen/.cache/lucisv-baselines/lucisv-0.50.0'}
initial=subprocess.check_output(['git','-C',corpus,'status','--porcelain'],text=True)
def run(label,kind,trial,args):
cmd=[str(root/'tools/guard.sh'),'-m','8','-t','1800','--','/usr/bin/time','-l',binaries[label]]+args+[tree]
load=os.getloadavg()
r=subprocess.run(cmd,cwd=root,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
log=r.stdout+r.stderr
(out/f'cli-{label}-{kind}-{trial}.log').write_bytes(log)
err=r.stderr.decode(errors='replace')
timing=re.search(r'([\d.]+) real\s+([\d.]+) user\s+([\d.]+) sys',err)
rss=re.search(r'(\d+)\s+maximum resident set size',err)
summary=[x for x in log.decode(errors='replace').splitlines() if re.search(r'^found \d+ violations|files? (checked|already|would|from)|violations? in|failed to format|files?,',x)]
record=dict(label=label,row=kind,trial=trial,command=cmd,exit=r.returncode,wall_s=float(timing[1]) if timing else None,user_s=float(timing[2]) if timing else None,sys_s=float(timing[3]) if timing else None,peak_rss_bytes=int(rss[1]) if rss else None,summary=summary[-4:],stdout_sha256=hashlib.sha256(r.stdout).hexdigest(),load_before=load,load_after=os.getloadavg(),corpus_unchanged=initial==subprocess.check_output(['git','-C',corpus,'status','--porcelain'],text=True))
with (out/'cli-results.jsonl').open('a') as f:f.write(json.dumps(record)+'\n')
print(label,kind,trial,record['wall_s'],record['summary'],flush=True)
if r.returncode not in (0,1,2) or not record['corpus_unchanged'] or not timing: raise RuntimeError(record)
for trial in range(1,4):
for label in (list(binaries) if trial%2 else list(reversed(binaries))):
for kind,args in [('default',['check']),('style',['check','--select','error,warning,style']),('style-no-unused-import',['check','--select','error,warning,style','--ignore','unused-import'])]:
if label=='0.43.0' and kind=='style-no-unused-import':continue
run(label,kind,trial,args)
cache=out/'cli-format-cache'
shutil.rmtree(cache,ignore_errors=True)
for warmth in ['cold','warm']:
run('0.51.0','format-'+warmth,trial,['format','--check','--cache-dir',str(cache)])