22 lines
1.0 KiB
Python
22 lines
1.0 KiB
Python
"""Sequential single-connection A/B experiment. Always restore normal nice."""
|
|
import json
|
|
import pathlib
|
|
import subprocess
|
|
import time
|
|
pid = int(subprocess.check_output(['pgrep', '-x', 'moonlight']))
|
|
tasks = pathlib.Path('/proc') / str(pid) / 'task'
|
|
tids = [int(p.name) for p in tasks.iterdir() if (p / 'comm').read_text().strip() == 'PacerRender']
|
|
assert len(tids) == 1
|
|
tid = tids[0]
|
|
results = []
|
|
try:
|
|
for label, priority in [('A', 0), ('B', -10)]:
|
|
assert int(subprocess.check_output(['pgrep', '-x', 'moonlight'])) == pid
|
|
subprocess.run(['sudo', '-n', 'renice', '-n', str(priority), '-p', str(tid)], check=True, stdout=subprocess.DEVNULL)
|
|
begin = time.time()
|
|
data = json.loads(subprocess.check_output(['python3', '/tmp/vdi-response-50.py'], timeout=150))
|
|
results.append(dict(label=label, nice=priority, started=begin, ended=time.time(), data=data))
|
|
print(json.dumps(results[-1]), flush=True)
|
|
finally:
|
|
subprocess.run(['sudo', '-n', 'renice', '-n', '0', '-p', str(tid)], stdout=subprocess.DEVNULL)
|