Download code/validate_long.py from harry1332/swe-agent-cpu-dynamorio-validated-private: direct link, hf CLI and curl.
- Browser
- Download file 3.78 kB
-
https://huggingface.co/datasets/harry1332/swe-agent-cpu-dynamorio-validated-private/resolve/main/code/validate_long.py
- Command line
-
hf download hf://datasets/harry1332/swe-agent-cpu-dynamorio-validated-private/code/validate_long.py
-
curl -L -o validate_long.py https://huggingface.co/datasets/harry1332/swe-agent-cpu-dynamorio-validated-private/resolve/main/code/validate_long.py
3.78 kB
| """Retry only unfinished traces, in fresh views, with explicit coverage gaps.""" | |
| import concurrent.futures | |
| import json | |
| import os | |
| from pathlib import Path | |
| import signal | |
| import subprocess | |
| import time | |
| root=Path('/data/cpu-tracing/pilot-v1') | |
| out=root/'validation-long-v1' | |
| out.mkdir(exist_ok=False) | |
| dr='/data/cpu-tracing/tools/DynamoRIO-Linux-11.91.20708/bin64/drrun' | |
| records=[] | |
| pending=[] | |
| for src in sorted((root/'traces').glob('*.dir')): | |
| original=root/'validation'/(src.name+'.counts.log') | |
| recovered=root/'derived-without-empty-fragments'/src.name/'validation.log' | |
| passed=next((p for p in (original,recovered) if p.exists() and 'Trace invariant checks passed' in p.read_text()),None) | |
| if passed: | |
| records.append({'directory':src.name,'status':'previously_validated','log':str(passed)}) | |
| continue | |
| raw=src/'raw' | |
| if any(not (raw/n).exists() or not (raw/n).stat().st_size for n in ['modules.log','encodings.bin']): | |
| records.append({'directory':src.name,'status':'coverage_gap','reason':'Missing module/encoding metadata'}) | |
| continue | |
| pending.append(src) | |
| pending.sort(key=lambda d:sum(p.stat().st_size for p in (d/'raw').glob('*.raw*')),reverse=True) | |
| (out/'plan.json').write_text(json.dumps({'pending':[p.name for p in pending],'prior':records,'timeout_per_process_seconds':64800,'storage_guard_bytes':170*1024**3},indent=2)) | |
| print(f'Retrying {len(pending)} traces; preserving {len(records)} prior results/gaps.',flush=True) | |
| def used_bytes(): | |
| return sum(p.stat().st_size for p in Path('/data/cpu-tracing').rglob('*') if p.is_file() and not p.is_symlink()) | |
| def check(src): | |
| dest=out/src.name | |
| (dest/'raw').mkdir(parents=True) | |
| excluded=[] | |
| for p in (src/'raw').iterdir(): | |
| if not p.is_file():continue | |
| if p.name.endswith('.raw.lz4') and p.stat().st_size==7 and p.read_bytes().hex()=='04224d18405077': | |
| excluded.append({'file':p.name,'bytes':7,'reason':'Empty LZ4 fork/exec fragment'}) | |
| else:os.symlink(p,dest/'raw'/p.name) | |
| result={'directory':src.name,'excluded':excluded,'status':'running'} | |
| (dest/'exclusions.json').write_text(json.dumps(result,indent=2)) | |
| cmd=[dr,'-t','drmemtrace','-indir',str(dest),'-tool','basic_counts:invariant_checker','-jobs','1'] | |
| (dest/'command.json').write_text(json.dumps(cmd)) | |
| start=time.time() | |
| with (dest/'validation.log').open('w') as log: | |
| proc=subprocess.Popen(cmd,stdout=log,stderr=subprocess.STDOUT,start_new_session=True) | |
| reason=None | |
| while proc.poll() is None: | |
| if time.time()-start>64800:reason='timeout' | |
| elif used_bytes()>170*1024**3:reason='storage_guard' | |
| if reason: | |
| os.killpg(proc.pid,signal.SIGTERM) | |
| try:proc.wait(timeout=15) | |
| except subprocess.TimeoutExpired: | |
| os.killpg(proc.pid,signal.SIGKILL);proc.wait() | |
| break | |
| time.sleep(30) | |
| text=(dest/'validation.log').read_text() | |
| result.update(seconds=time.time()-start,returncode=proc.returncode, | |
| status=reason or ('validated_populated_streams' if proc.returncode==0 and 'Trace invariant checks passed' in text else 'failed')) | |
| (dest/'result.json').write_text(json.dumps(result,indent=2)) | |
| return result | |
| with concurrent.futures.ThreadPoolExecutor(max_workers=2) as pool: | |
| for future in concurrent.futures.as_completed([pool.submit(check,p) for p in pending]): | |
| r=future.result();records.append(r) | |
| (out/'progress.json').write_text(json.dumps(records,indent=2)) | |
| print(json.dumps(r),flush=True) | |
| (out/'completed.json').write_text(json.dumps({'records':records,'scope':'User-space CPU; excluded fork/exec fragments remain gaps. No dead-state conclusion.'},indent=2)) | |