Download code/validate_windows.py from harry1332/agentbench-avalon-sampled-cpu-trace: direct link, hf CLI and curl.
- Browser
- Download file 1.48 kB
-
https://huggingface.co/datasets/harry1332/agentbench-avalon-sampled-cpu-trace/resolve/main/code/validate_windows.py
- Command line
-
hf download hf://datasets/harry1332/agentbench-avalon-sampled-cpu-trace/code/validate_windows.py
-
curl -L -o validate_windows.py https://huggingface.co/datasets/harry1332/agentbench-avalon-sampled-cpu-trace/resolve/main/code/validate_windows.py
1.48 kB
| """Convert and validate every raw window; a process indir selects only window 0.""" | |
| import json | |
| from pathlib import Path | |
| import re | |
| import subprocess | |
| import sys | |
| root = Path(sys.argv[1]) | |
| dr = '/data/cpu-tracing/tools/DynamoRIO-Linux-11.91.20708/bin64/drrun' | |
| records = [] | |
| for window in sorted((root / 'native').glob('*/raw/window.*')): | |
| label = window.parent.parent.name + '-' + window.name | |
| log = root / 'validation' / (label + '.log') | |
| log.parent.mkdir(exist_ok=True) | |
| # Converter needs the parent trace directory to exist for the first window. | |
| (window.parent.parent / 'trace').mkdir(exist_ok=True) | |
| cmd = [dr, '-t', 'drmemtrace', '-indir', str(window), | |
| '-tool', 'basic_counts:invariant_checker', '-jobs', '1'] | |
| with log.open('w') as stream: | |
| rc = subprocess.run(cmd, stdout=stream, stderr=subprocess.STDOUT, | |
| timeout=600).returncode | |
| text = log.read_text() | |
| count = re.search(r'(\d+) total \(fetched\) instructions', text) | |
| record = {'window': str(window.relative_to(root)), 'command': cmd, | |
| 'returncode': rc, 'invariants_passed': 'Trace invariant checks passed' in text, | |
| 'fetched_instructions': int(count[1]) if count else None} | |
| records.append(record) | |
| print(json.dumps(record), flush=True) | |
| (root / 'validation.json').write_text(json.dumps(records, indent=2)) | |
| if not records or any(r['returncode'] or not r['invariants_passed'] for r in records): | |
| sys.exit(1) | |