- esp32_server: Popen 后外部 SetPriorityClass(RT/High),native 自设会被钳成 High - 入库 skip_* 标定/实验脚本与 REPORT_ecat_skip_opt_20260917 - 前端 WIP:layout/app/polling/boot_ecat/index - 不含 lab/skip_meter 原始采样与 preview 截图
45 lines
1.8 KiB
Python
45 lines
1.8 KiB
Python
#!/usr/bin/env python3
|
|
import json, os, subprocess, sys, time
|
|
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
LAB = os.path.join(ROOT, "lab", "skip_meter")
|
|
|
|
def set_prio(level="RealTime"):
|
|
p = int(subprocess.check_output(["powershell","-NoProfile","-Command","(Get-Process ecat_native).Id"], text=True).strip())
|
|
subprocess.check_output(["powershell","-NoProfile","-Command",
|
|
f"$p=Get-Process -Id {p}; $p.PriorityClass='{level}'; $p.PriorityClass"], text=True)
|
|
return p
|
|
|
|
def meter(tag, secs=15):
|
|
subprocess.run([sys.executable, os.path.join(ROOT,"scripts","skip_rate_meter.py"),
|
|
"--tag", tag, "--secs", str(secs)],
|
|
capture_output=True, text=True, encoding="utf-8", errors="replace")
|
|
files = sorted(f for f in os.listdir(LAB) if f.startswith(tag+"_") and f.endswith(".json"))
|
|
d = json.load(open(os.path.join(LAB, files[-1]), encoding="utf-8"))
|
|
return {
|
|
"tag": tag,
|
|
"late_per_s": d["late_per_s"], "skip_per_s": d["skip_per_s"],
|
|
"achieved_hz": d["achieved_hz"], "n_late": d["n_late"],
|
|
"work_p50": d["window_cyc_us"]["work"]["p50"],
|
|
"rx_p50": d["window_cyc_us"]["rx"]["p50"],
|
|
"send_p50": d["window_cyc_us"]["send"]["p50"],
|
|
"work_p90": d["window_cyc_us"]["work"]["p90"],
|
|
}
|
|
|
|
def main():
|
|
set_prio("RealTime")
|
|
rows = []
|
|
for i in range(1, 4):
|
|
print(f"round {i} settle...")
|
|
time.sleep(4)
|
|
r = meter(f"multirt_{i}", 15)
|
|
print(r)
|
|
rows.append(r)
|
|
lates = [x["late_per_s"] for x in rows]
|
|
print("mean late", sum(lates)/len(lates), "min", min(lates), "max", max(lates))
|
|
path = os.path.join(LAB, f"summary_multirt_{int(time.time())}.json")
|
|
json.dump(rows, open(path,"w",encoding="utf-8"), ensure_ascii=False, indent=2)
|
|
print("WROTE", path)
|
|
|
|
if __name__ == "__main__":
|
|
main()
|