MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / measure

Function measure

tools/materialize-bench/imported_guest.py:227–315  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

225
226
227def measure(args):
228 if platform.system() != 'Linux':
229 raise ValueError('guest-only Linux cache reset required')
230 if args.iterations < 2 or args.iterations % 2:
231 raise ValueError('use an even number of iterations >= 2')
232 root = args.root.resolve()
233 check_owned_root(root)
234 prepared = json.loads((root / 'prepared.json').read_text())
235 manifest = json.loads((root / 'manifest.json').read_text())
236 validate_manifest(manifest)
237 env = isolated_env(root)
238 if args.trace_span_context:
239 env['ATOMIC_TRACE_SPAN_RENDER'] = '1'
240 filesystem = command(['findmnt', '-n', '-o', 'FSTYPE,SOURCE,TARGET', '-T', root], env).decode().strip()
241 if filesystem.split()[0] != 'ext4':
242 raise ValueError('use a guest-local ext4 disk, not a host-shared mount: ' + filesystem)
243 output = args.output.resolve()
244 output.mkdir(parents=True, exist_ok=False)
245 binary = output / 'imported_materialize_bench'
246 shutil.copy2(args.probe, binary)
247 binary.chmod(0o700)
248 binary_sha = digest(binary)
249 samples = []
250 metadata = dict(outcome='incomplete', cache_policy='sync + guest Linux drop_caches=3 before every fresh process',
251 host_cache_policy='uncontrolled; NOT physical-disk-cold or host-cache-cold',
252 filesystem=filesystem, iterations=args.iterations, rayon_threads=2,
253 binary_sha256=binary_sha, fixture=prepared, platform=platform.platform(),
254 logical_cpus=os.cpu_count(), guest_meminfo=meminfo(),
255 diagnostic_trace=args.trace_span_context,
256 timing='API total includes open, render/materialize and close; verification excluded; process wall includes verification')
257 try:
258 for iteration in range(args.iterations):
259 for case in CASES:
260 for offset in range(2):
261 backend = BACKENDS[(iteration + offset) % 2]
262 repo = root / backend
263 if digest(root / (backend + '-baseline.redb')) != prepared['fixtures'][backend]['database_sha256']:
264 raise ValueError('baseline database changed')
265 reset_fixture(root, backend, manifest, case)
266 os.sync()
267 before = meminfo()
268 Path('/proc/sys/vm/drop_caches').write_text('3\n')
269 after = meminfo()
270 stem = output / f'{iteration:02}-{case}-{backend}'
271 report = stem.with_suffix('.json')
272 command_line = [binary, '--repo', repo, '--manifest', root / 'manifest.json',
273 '--output', report, '--backend', backend, '--case', case]
274 started = time.monotonic()
275 command(command_line, env, log=stem)
276 wall = time.monotonic() - started
277 sample = json.loads(report.read_text())
278 if sample['debug_build'] or not sample['head_verified'] or sample['verified_files'] != len(manifest['files']):
279 raise ValueError('unverified or debug benchmark sample')
280 if sample['git_tip'] != manifest['git_tip'] or sample['backend'] != backend or sample['case'] != case:
281 raise ValueError('wrong sample identity')
282 if digest(repo / '.git/index') != prepared['fixtures'][backend]['git_index_sha256']:
283 raise ValueError('measurement changed Git index')
284 sample.update(iteration=iteration, backend_order=offset,

Callers 1

mainFunction · 0.70

Calls 14

check_owned_rootFunction · 0.85
isolated_envFunction · 0.85
meminfoFunction · 0.85
rangeFunction · 0.85
reset_fixtureFunction · 0.85
validate_manifestFunction · 0.70
commandFunction · 0.70
digestFunction · 0.70
distributionFunction · 0.70
getMethod · 0.65
resolveMethod · 0.45
decodeMethod · 0.45

Tested by

no test coverage detected