54 lines
2.3 KiB
Python
54 lines
2.3 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")
|
||
|
|
NIC = "以太网 2"
|
||
|
|
|
||
|
|
def ps(cmd):
|
||
|
|
r = subprocess.check_output(["powershell","-NoProfile","-Command",cmd],
|
||
|
|
text=True, encoding="utf-8", errors="replace")
|
||
|
|
return r.strip()
|
||
|
|
|
||
|
|
def set_prio(level="RealTime"):
|
||
|
|
p = int(ps("(Get-Process ecat_native).Id"))
|
||
|
|
ps(f"$p=Get-Process -Id {p}; $p.PriorityClass='{level}'; $p.PriorityClass")
|
||
|
|
return p
|
||
|
|
|
||
|
|
def meter(tag, secs=18):
|
||
|
|
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"))
|
||
|
|
return json.load(open(os.path.join(LAB, files[-1]), encoding="utf-8"))
|
||
|
|
|
||
|
|
def main():
|
||
|
|
restore = "--restore" in sys.argv
|
||
|
|
ids = ["ms_tcpip", "ms_tcpip6"]
|
||
|
|
for cid in ids:
|
||
|
|
if restore:
|
||
|
|
ps(f"Enable-NetAdapterBinding -Name '{NIC}' -ComponentID '{cid}' -Confirm:$false")
|
||
|
|
else:
|
||
|
|
ps(f"Disable-NetAdapterBinding -Name '{NIC}' -ComponentID '{cid}' -Confirm:$false")
|
||
|
|
print(ps(f"Get-NetAdapterBinding -Name '{NIC}' -ComponentID '{cid}' | Select-Object ComponentID,Enabled | ConvertTo-Json -Compress"))
|
||
|
|
if restore:
|
||
|
|
return
|
||
|
|
print("pid", set_prio("RealTime"))
|
||
|
|
time.sleep(3)
|
||
|
|
data = meter("bind_noip", 18)
|
||
|
|
row = {
|
||
|
|
"late_per_s": data["late_per_s"], "skip_per_s": data["skip_per_s"],
|
||
|
|
"late_frac_pct": data["late_frac_pct"], "achieved_hz": data["achieved_hz"],
|
||
|
|
"n_late": data["n_late"],
|
||
|
|
"send_stall_frac": data["send_stall_frac"], "rx_stall_frac": data["rx_stall_frac"],
|
||
|
|
"work_p50": data["window_cyc_us"]["work"]["p50"],
|
||
|
|
"rx_p50": data["window_cyc_us"]["rx"]["p50"],
|
||
|
|
"send_p50": data["window_cyc_us"]["send"]["p50"],
|
||
|
|
}
|
||
|
|
print(json.dumps(row, ensure_ascii=False, indent=2))
|
||
|
|
out = os.path.join(LAB, f"summary_bind_noip_{int(time.time())}.json")
|
||
|
|
json.dump(row, open(out,"w",encoding="utf-8"), ensure_ascii=False, indent=2)
|
||
|
|
print("WROTE", out)
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
main()
|