feat(monitor): 网页加 CPU 占用卡(总占用环 + 28 核逐核条),psutil 采样缓存 1 秒;顺便重启控制台让之前的补量进度口径与停止补杀生效

This commit is contained in:
cbb
2026-10-18 13:57:48 +08:00
parent e6418da084
commit 9ed213417b
2 changed files with 33 additions and 1 deletions
+18 -1
View File
@@ -68,6 +68,23 @@ def read_log(name, offset):
return {'records': recs, 'offset': offset + end, 'size': size, 'reset': offset == 0, 'mtime': os.path.getmtime(f)}
_CPU_CACHE = {'t': 0.0, 'v': {}}
def cpu():
"""CPU 占用:总百分比 + 每核(psutil 已装;没装就返回空,页面不显示这块)。"""
if time.time() - _CPU_CACHE['t'] < 1.0: return _CPU_CACHE['v']
try:
import psutil
per = psutil.cpu_percent(interval=None, percpu=True)
out = {'total': round(sum(per) / max(1, len(per)), 1), 'per': [round(x, 0) for x in per], 'n': len(per),
'load1': round(os.getloadavg()[0], 2) if hasattr(os, 'getloadavg') else None}
except Exception:
out = {}
_CPU_CACHE.update(t=time.time(), v=out)
return out
_GPU_CACHE = {'t': 0.0, 'v': []}
@@ -203,7 +220,7 @@ def status():
pb = jload(P(RUNS, 'policy_bench.json'))
if pb: pb = {k: {kk: v.get(kk) for kk in ('n', 'ok', 'reached', 'collisionFrames', 'brakeRate', 'recoveryRate', 'livelock', 'inferMsP99', 'safetyMsP99')}
for k, v in pb.items() if isinstance(v, dict) and 'n' in v}
return {'now': time.time(), 'gpu': gpu(),
return {'now': time.time(), 'gpu': gpu(), 'cpu': cpu(),
'vram_budget_gb': float(os.environ.get('VRAM_BUDGET_GB', 20)), # 本机桌面常驻占 4–5 GB,给训练的预算 19–20 GB
'pipeline': pl, 'check': CHECK.get(), 'lock': lock_info(), # 2026-10-18 第八轮修:上一版这三项被行尾注释吞掉,网页步骤条/锁状态拿不到
'stage_meta': [{'id': k, 'name': n, 'est_h': h, 'timeout_h': pstate.TIMEOUT_H[k]} for k, n, h in pstate.STAGES],