41 lines
1.4 KiB
Python
41 lines
1.4 KiB
Python
# TC-NET-604 诊断:芯片 TX 分包粒度探测(= SET_TCP_MSS 有效值)
|
|
# 向回显端发送 N 字节,紧循环小包 recv + 计时,输出到达分块分布。
|
|
# 芯片 TX 包 = MSS 大小 → 到达粒度 ≈ 芯片发包大小(同交换机微秒级间隔,按 1ms 窗口聚合)。
|
|
import socket, sys, time
|
|
|
|
ip, port = sys.argv[1] if len(sys.argv) > 1 else "192.168.1.100", 8080
|
|
size = int(sys.argv[2]) if len(sys.argv) > 2 else 4096
|
|
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
s.settimeout(30)
|
|
s.connect((ip, int(port)))
|
|
payload = bytes(i & 0xFF for i in range(size))
|
|
t0 = time.perf_counter()
|
|
s.sendall(payload)
|
|
|
|
# 紧循环非阻塞式读取(recv 4096 上限,记录每次 recv 的字节数与相对时刻)
|
|
s.setblocking(False)
|
|
chunks = []
|
|
got = 0
|
|
deadline = time.time() + 10.0
|
|
while got < size and time.time() < deadline:
|
|
try:
|
|
b = s.recv(4096)
|
|
if b:
|
|
chunks.append((round((time.perf_counter() - t0) * 1000, 1), len(b)))
|
|
got += len(b)
|
|
except BlockingIOError:
|
|
time.sleep(0.001)
|
|
|
|
s.close()
|
|
print(f"sent={size} got={got} in {round((time.perf_counter()-t0)*1000,1)}ms")
|
|
if chunks:
|
|
from collections import Counter
|
|
c = Counter(n for _, n in chunks)
|
|
print("arrival chunks (ms, bytes):")
|
|
for t, n in chunks:
|
|
print(f" +{t:7.1f}ms {n:5d}B")
|
|
print("size histogram:", dict(sorted(c.items())))
|
|
else:
|
|
print("NO DATA (stall?)")
|