#!/usr/bin/env python3 """Preflight and run JMeter; record actual timing for external power measurements.""" import xml.etree.ElementTree as E import argparse, csv, datetime as dt, hashlib, json, os, platform, subprocess, time, ssl, urllib.request from pathlib import Path from perfmon import check_agent, summarize import shelly HERE=Path(__file__).resolve().parent p=argparse.ArgumentParser() p.add_argument('scenario',choices=['recording','review','correction','professional','mixed','idle']) p.add_argument('--host',required=True);p.add_argument('--port',type=int,default=5443) p.add_argument('--ca');p.add_argument('--users-file');p.add_argument('--users',type=int,default=50) p.add_argument('--warmup',type=int,default=1800);p.add_argument('--duration',type=int,default=14400);p.add_argument('--ramp',type=int,default=120) p.add_argument('--think-mean-ms',type=int,default=4000);p.add_argument('--think-stddev-ms',type=int,default=2000) p.add_argument('--session-pause-ms',type=int,default=120000) p.add_argument('--session-stddev-ms',type=int,default=30000);p.add_argument('--seed',type=int,default=42) p.add_argument('--output',required=True);p.add_argument('--jmeter',default=str(Path.home()/'.local/bin/jmeter')) p.add_argument('--allow-shared-read-account',action='store_true') p.add_argument('--perfmon-host');p.add_argument('--perfmon-port',type=int,default=4444) p.add_argument('--perfmon-interval-ms',type=int,default=5000);p.add_argument('--no-perfmon',action='store_true') p.add_argument('--shelly-host',default='192.168.1.44');p.add_argument('--shelly-port',type=int,default=80) p.add_argument('--shelly-switch-id',type=int,default=0);p.add_argument('--shelly-interval-ms',type=int,default=5000);p.add_argument('--no-shelly',action='store_true') a=p.parse_args() if a.users<1 or a.duration<1 or a.warmup<0 or a.ramp<0 or min(a.think_mean_ms,a.think_stddev_ms,a.session_pause_ms,a.session_stddev_ms)<0: p.error('Invalid timing/concurrency') if a.scenario!='idle' and not a.users_file: p.error('--users-file is required') if a.scenario!='idle' and not a.ca: p.error('--ca is required for application scenarios') if a.scenario=='idle' and a.users_file:p.error('Idle does not use accounts; omit --users-file') if a.perfmon_interval_ms<1000 or a.perfmon_interval_ms%1000: p.error('PerfMon interval must be a whole number of seconds, at least 1000 ms') agent_host=a.perfmon_host or a.host if not a.no_perfmon: check_agent(agent_host,a.perfmon_port) if a.shelly_interval_ms<1000 or a.shelly_switch_id<0:p.error('Invalid Shelly interval/switch ID') shelly_info=None if a.no_shelly else shelly.check_plug(a.shelly_host,a.shelly_port,a.shelly_switch_id) rows=[] if a.users_file: with open(a.users_file,newline='') as f: reader=csv.DictReader(f) if reader.fieldnames!=['account_id','password','patient_id']: p.error('CSV columns must be account_id,password,patient_id') rows=list(reader) if not rows or any(not all(r.values()) or any(c in v for v in r.values() for c in ',\n\r"') for r in rows): p.error('CSV contains empty or unsupported values') if len({r['account_id'] for r in rows})!=len(rows): p.error('CSV must contain distinct accounts') if len(rows)