57 lines
2.4 KiB
Python
57 lines
2.4 KiB
Python
"""Read-only numeric performance samples; no device identity or WiFi payloads."""
|
|
import argparse
|
|
import json
|
|
from pathlib import Path
|
|
import shlex
|
|
from remote_support import connect, execute
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument('--seconds', type=int, default=120)
|
|
parser.add_argument('--output', type=Path, required=True)
|
|
args = parser.parse_args()
|
|
if not 5 <= args.seconds <= 600:
|
|
parser.error('seconds must be 5..600')
|
|
if args.output.exists():
|
|
parser.error('output already exists; do not overwrite evidence')
|
|
script = r'''
|
|
import json,time,urllib.request
|
|
rows=[]
|
|
start=time.monotonic()
|
|
while time.monotonic()-start < DURATION:
|
|
with urllib.request.urlopen('http://127.0.0.1:8080/api/status',timeout=5) as response:
|
|
s=json.load(response)
|
|
d=s['screen']['driver_status'];r=s['resources']
|
|
rows.append(dict(elapsed_seconds=round(time.monotonic()-start,3),
|
|
connected=s['mobile']['connected'],animation_active=s['state']['animation_active'],
|
|
refresh_hz=d['actual_refresh_rate_hz'],frames=d['completed_frames'],
|
|
deadline_misses=d['deadline_misses'],oe_faults=d['oe_pulse_faults'],
|
|
driver_error_present=bool(d['last_error'] or d['oe_timing_error']),
|
|
cpu_application_percent=r['cpu']['application_percent'],
|
|
memory_application_bytes=r['memory']['application_bytes']))
|
|
time.sleep(1)
|
|
print(json.dumps(rows))
|
|
'''.replace('DURATION', str(args.seconds))
|
|
client, fields = connect()
|
|
try:
|
|
code, output, _ = execute(client, 'python3 -c ' + shlex.quote(script), timeout=args.seconds + 20)
|
|
if code:
|
|
raise RuntimeError('Performance collection failed; raw output withheld')
|
|
rows = json.loads(output)
|
|
args.output.parent.mkdir(parents=True, exist_ok=True)
|
|
with args.output.open('x', encoding='utf-8') as stream:
|
|
json.dump(rows, stream, ensure_ascii=False, indent=2)
|
|
stream.write('\n')
|
|
print(json.dumps(dict(samples=len(rows),connected_samples=sum(r['connected'] for r in rows),
|
|
deadline_misses_delta=rows[-1]['deadline_misses']-rows[0]['deadline_misses'],
|
|
oe_faults_delta=rows[-1]['oe_faults']-rows[0]['oe_faults'],
|
|
min_refresh_hz=min(r['refresh_hz'] for r in rows),
|
|
driver_error_seen=any(r['driver_error_present'] for r in rows))))
|
|
finally:
|
|
client.close()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|