"""Public load workload plus actual process/cgroup snapshots on the same stand.""" import json import sys import time from verify import ROOT,BASE,CA,command,compose,save def stats(role): tag='src.app:app' if role.startswith('api') else 'src.worker' code="import psutil,json; p=next(p for p in psutil.process_iter() if p.name().startswith('python') and "+repr(tag)+" in p.cmdline()); procs=[p]+p.children(recursive=True); print(json.dumps({'cpu_seconds':sum(sum(x.cpu_times()[:2]) for x in procs),'rss_bytes':sum(x.memory_info().rss for x in procs)}))" return json.loads(compose('exec','-T',role,'python','-c',code)) if __name__=='__main__': before={r:stats(r) for r in ('api1','api2','worker')} started=time.monotonic() command([sys.executable,'-X','utf8','tests/load.py','--base-url',BASE,'--ca-file',CA,'--duration','30','--concurrency','4','--output','evidence/load.json'],'load.txt') elapsed=time.monotonic()-started after={r:stats(r) for r in before} ids=compose('ps','-q').split() containers=command(['docker','stats','--no-stream','--format','{{json .}}',*ids]) save('load-resources.json',{'before':before,'after':after,'wall_seconds':elapsed, 'CPU_cores':{r:(after[r]['cpu_seconds']-before[r]['cpu_seconds'])/elapsed for r in before}, 'cgroup_snapshots':[json.loads(line) for line in containers.splitlines()], 'clock_resolution_seconds':time.get_clock_info('monotonic').resolution, 'limitation':'Process snapshots include child workers, exclude client, DB, TLS sidecars and Collector from API CPU; container snapshots cover those separately. RSS is end snapshot, not worst-case peak.'}) print('PASS: public HTTPS load and process/container resource snapshots')