teamsmith 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/package.json +1 -1
- package/skills/teamsmith/CHANGELOG.md +69 -0
- package/skills/teamsmith/SKILL.md +20 -13
- package/skills/teamsmith/extension/team-inbox-watch.ts +5 -3
- package/skills/teamsmith/extension/team-notify.ts +37 -6
- package/skills/teamsmith/extension/team.ts +438 -0
- package/skills/teamsmith/references/config.md +39 -6
- package/skills/teamsmith/references/migration.md +197 -47
- package/skills/teamsmith/references/protocol.md +201 -30
- package/skills/teamsmith/references/troubleshooting.md +130 -10
- package/skills/teamsmith/references/workflows.md +36 -2
- package/skills/teamsmith/scripts/lib/cmd-agents.sh +318 -23
- package/skills/teamsmith/scripts/lib/cmd-bootstrap.sh +2 -2
- package/skills/teamsmith/scripts/lib/cmd-config.sh +349 -67
- package/skills/teamsmith/scripts/lib/cmd-draft.sh +4 -4
- package/skills/teamsmith/scripts/lib/cmd-help.sh +677 -0
- package/skills/teamsmith/scripts/lib/cmd-init.sh +157 -5
- package/skills/teamsmith/scripts/lib/cmd-interrupt.sh +461 -0
- package/skills/teamsmith/scripts/lib/cmd-meeting.sh +2 -25
- package/skills/teamsmith/scripts/lib/cmd-project.sh +30 -103
- package/skills/teamsmith/scripts/lib/cmd-reap.sh +277 -0
- package/skills/teamsmith/scripts/lib/cmd-reply.sh +3 -3
- package/skills/teamsmith/scripts/lib/cmd-review.sh +182 -32
- package/skills/teamsmith/scripts/lib/cmd-status.sh +234 -21
- package/skills/teamsmith/scripts/lib/cmd-update.sh +36 -7
- package/skills/teamsmith/scripts/lib/cmd-watch.sh +564 -46
- package/skills/teamsmith/scripts/lib/common.sh +1004 -245
- package/skills/teamsmith/scripts/lib/gate-lock.sh +582 -0
- package/skills/teamsmith/scripts/panel/draft-send.sh +11 -1
- package/skills/teamsmith/scripts/panel/panel.js +211 -211
- package/skills/teamsmith/scripts/panel/src/App.tsx +58 -21
- package/skills/teamsmith/scripts/panel/src/clipboard.ts +12 -5
- package/skills/teamsmith/scripts/panel/src/compose.ts +6 -3
- package/skills/teamsmith/scripts/panel/src/data.ts +51 -5
- package/skills/teamsmith/scripts/panel/src/layout.ts +209 -69
- package/skills/teamsmith/scripts/panel/src/main.tsx +37 -8
- package/skills/teamsmith/scripts/panel/src/strings/en.ts +39 -29
- package/skills/teamsmith/scripts/panel/src/strings/zh.ts +41 -31
- package/skills/teamsmith/scripts/panel/src/types.ts +28 -3
- package/skills/teamsmith/scripts/replies.mjs +4 -1
- package/skills/teamsmith/scripts/shim/killall +10 -0
- package/skills/teamsmith/scripts/shim/pgrep +10 -0
- package/skills/teamsmith/scripts/shim/pidof +10 -0
- package/skills/teamsmith/scripts/shim/pkill +10 -0
- package/skills/teamsmith/scripts/shim/signal-gate +108 -31
- package/skills/teamsmith/scripts/shim/tmux +18 -0
- package/skills/teamsmith/scripts/strings/commands.tsv +86 -0
- package/skills/teamsmith/scripts/strings/help.en.tsv +503 -0
- package/skills/teamsmith/scripts/strings/help.zh.tsv +489 -0
- package/skills/teamsmith/scripts/team +19 -6
- package/skills/teamsmith/templates/AGENTS.section.md.tmpl +8 -1
- package/skills/teamsmith/templates/config.sh.tmpl +20 -1
- package/skills/teamsmith/templates/pm-prompt.md.tmpl +21 -0
- package/skills/teamsmith/tests/README.md +31 -0
- package/skills/teamsmith/tests/bg-ledger-harness.mjs +464 -40
- package/skills/teamsmith/tests/bg-ledger.sh +168 -10
- package/skills/teamsmith/tests/checkout-shape-probe.sh +83 -54
- package/skills/teamsmith/tests/config-cli.sh +184 -32
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/scenario.sh +7 -1
- package/skills/teamsmith/tests/fixtures/p287/lint-good.sh.in +3 -0
- package/skills/teamsmith/tests/fixtures/p287/lint-hardcoded.sh.in +3 -0
- package/skills/teamsmith/tests/fixtures/p287/lint-no-ns.sh.in +3 -0
- package/skills/teamsmith/tests/fixtures/p55/flip-p49.sh +18 -6
- package/skills/teamsmith/tests/flip-m33.sh +5 -3
- package/skills/teamsmith/tests/flip-p158.sh +2 -1
- package/skills/teamsmith/tests/flip-p308-skip-not-pass.sh +151 -0
- package/skills/teamsmith/tests/flip-p310-lock.sh +210 -0
- package/skills/teamsmith/tests/flip-p310-socket.sh +125 -0
- package/skills/teamsmith/tests/gate-guard.sh +52 -79
- package/skills/teamsmith/tests/help-surface.sh +1664 -0
- package/skills/teamsmith/tests/install-shape.sh +359 -22
- package/skills/teamsmith/tests/key-replies-pty.sh +9 -10
- package/skills/teamsmith/tests/key-replies-ui.sh +2 -8
- package/skills/teamsmith/tests/key-replies.sh +281 -28
- package/skills/teamsmith/tests/ledger-ban.sh +5 -4
- package/skills/teamsmith/tests/ledger-claim.sh +2 -1
- package/skills/teamsmith/tests/lib/bounded-spin.sh +90 -0
- package/skills/teamsmith/tests/lib/model-policy.sh +4 -0
- package/skills/teamsmith/tests/lib/model-routing-flips.py +51 -0
- package/skills/teamsmith/tests/lib/pty-wait.sh +21 -111
- package/skills/teamsmith/tests/lib/reply-fixture.sh +4 -9
- package/skills/teamsmith/tests/lib/section-guard.sh +316 -164
- package/skills/teamsmith/tests/lib/tmp-root.sh +139 -27
- package/skills/teamsmith/tests/lib/tmux-cap.sh +10 -1
- package/skills/teamsmith/tests/lib/tmux-iso.sh +31 -13
- package/skills/teamsmith/tests/loop-inventory.tsv +83 -77
- package/skills/teamsmith/tests/panel-b2.sh +430 -352
- package/skills/teamsmith/tests/panel-b3-stub.sh +112 -4
- package/skills/teamsmith/tests/panel-b3.sh +314 -62
- package/skills/teamsmith/tests/panel-choices.sh +11 -6
- package/skills/teamsmith/tests/panel-cpu.sh +43 -130
- package/skills/teamsmith/tests/panel-p21.sh +251 -265
- package/skills/teamsmith/tests/panel-snapshots.sh +41 -225
- package/skills/teamsmith/tests/panel-strings.mjs +33 -18
- package/skills/teamsmith/tests/perf.sh +187 -396
- package/skills/teamsmith/tests/routes.sh +440 -117
- package/skills/teamsmith/tests/seat-interrupt.sh +1012 -0
- package/skills/teamsmith/tests/seat-visibility.sh +675 -0
- package/skills/teamsmith/tests/section-guard.sh +13 -102
- package/skills/teamsmith/tests/section-needs-audit.sh +24 -7
- package/skills/teamsmith/tests/section-paths.tsv +32 -18
- package/skills/teamsmith/tests/section-select.sh +371 -19
- package/skills/teamsmith/tests/signal-gate.sh +249 -27
- package/skills/teamsmith/tests/signal-lint-legacy.txt +4 -1
- package/skills/teamsmith/tests/slash-team-e2e.sh +323 -0
- package/skills/teamsmith/tests/slash-team.sh +617 -0
- package/skills/teamsmith/tests/slice-coverage.sh +206 -0
- package/skills/teamsmith/tests/smoke.sh +3595 -788
- package/skills/teamsmith/tests/task-model-routing.sh +530 -15
- package/skills/teamsmith/tests/team-bg-stop.sh +18 -10
- package/skills/teamsmith/tests/tmp-hygiene.sh +782 -45
- package/skills/teamsmith/tests/tmux-identity-leak.sh +773 -0
- package/skills/teamsmith/tests/tmux-lint-legacy.txt +12 -18
- package/skills/teamsmith/tests/upgrade-recipe.sh +537 -0
- package/skills/teamsmith/tests/workflow-entry.sh +207 -0
- package/skills/teamsmith-init/SKILL.md +12 -12
- package/skills/teamsmith-init/references/bootstrap.md +3 -3
- package/skills/teamsmith/tests/flip-glue.sh +0 -162
- package/skills/teamsmith/tests/flip-m12-26c.sh +0 -129
- package/skills/teamsmith/tests/flip-m12.sh +0 -185
- package/skills/teamsmith/tests/flip-m16.sh +0 -166
- package/skills/teamsmith/tests/flip-m17.sh +0 -204
- package/skills/teamsmith/tests/flip-m34.sh +0 -96
- package/skills/teamsmith/tests/flip-m37.sh +0 -185
- package/skills/teamsmith/tests/flip-m4.3.sh +0 -375
- package/skills/teamsmith/tests/flip-m43.sh +0 -128
- package/skills/teamsmith/tests/flip-m45.sh +0 -244
- package/skills/teamsmith/tests/flip-m46.sh +0 -238
- package/skills/teamsmith/tests/flip-m48.sh +0 -304
- package/skills/teamsmith/tests/flip-m6.2.sh +0 -205
- package/skills/teamsmith/tests/flip-m6.3.sh +0 -283
- package/skills/teamsmith/tests/flip-m6.4.sh +0 -267
- package/skills/teamsmith/tests/flip-m6.5.sh +0 -113
- package/skills/teamsmith/tests/flip-m7.1.sh +0 -135
- package/skills/teamsmith/tests/flip-m7.2.sh +0 -321
- package/skills/teamsmith/tests/flip-p144.sh +0 -112
- package/skills/teamsmith/tests/flip-p156.sh +0 -133
- package/skills/teamsmith/tests/flip-p160.sh +0 -182
- package/skills/teamsmith/tests/flip-p171.sh +0 -249
- package/skills/teamsmith/tests/flip-p18.1.sh +0 -95
- package/skills/teamsmith/tests/flip-p20.sh +0 -286
- package/skills/teamsmith/tests/flip-p201.sh +0 -249
- package/skills/teamsmith/tests/flip-p210.sh +0 -239
- package/skills/teamsmith/tests/flip-p211.sh +0 -152
- package/skills/teamsmith/tests/flip-p217.sh +0 -288
- package/skills/teamsmith/tests/flip-p22.sh +0 -123
- package/skills/teamsmith/tests/flip-p23.sh +0 -239
- package/skills/teamsmith/tests/flip-p25.sh +0 -165
- package/skills/teamsmith/tests/flip-p71.sh +0 -184
- package/skills/teamsmith/tests/flip-p72.sh +0 -202
- package/skills/teamsmith/tests/load-experiment.sh +0 -290
- package/skills/teamsmith/tests/panel-cpu-premise.sh +0 -173
- package/skills/teamsmith/tests/panel-flip-m54.sh +0 -207
- package/skills/teamsmith/tests/panel-flip-p123.sh +0 -278
- package/skills/teamsmith/tests/panel-flip-p125.sh +0 -318
- package/skills/teamsmith/tests/panel-flip-p128.sh +0 -259
- package/skills/teamsmith/tests/panel-keyprobe-stub.sh +0 -41
- package/skills/teamsmith/tests/panel-keyprobe.sh +0 -82
- package/skills/teamsmith/tests/panel-knobs.sh +0 -83
- package/skills/teamsmith/tests/section-budgets.tsv +0 -154
- package/skills/teamsmith/tests/team-bg-flip.sh +0 -239
- package/skills/teamsmith/tests/team-inbox-watch-flip.sh +0 -191
|
@@ -1,58 +1,39 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
# teamsmith ·
|
|
2
|
+
# teamsmith · 性能**参考读数**(M58 · perf-suite-split;P316 按用户裁定改成「只参考、不阻塞」)
|
|
3
3
|
#
|
|
4
4
|
# bash skills/teamsmith/tests/perf.sh # 默认:参考环境(钉死镜像)——同 --container
|
|
5
5
|
# bash skills/teamsmith/tests/perf.sh --container # 参考环境:ci/Containerfile 的钉死镜像
|
|
6
|
-
# bash skills/teamsmith/tests/perf.sh --in-container #
|
|
7
|
-
# #
|
|
8
|
-
# # TEAM_PERF_PINNED_CONTAINER=1 + rootfs 标识文件
|
|
9
|
-
# # /etc/teamsmith-gate-image(内容逐字节等于封闭 token,
|
|
10
|
-
# # 且不得是挂载点 —— 挂来的不算镜像烘焙的),
|
|
11
|
-
# # 缺哪个/错哪个点名哪个 → 可见拒绝 exit 3
|
|
6
|
+
# bash skills/teamsmith/tests/perf.sh --in-container # 镜像内部用:必须带镜像自身的身份证明
|
|
7
|
+
# # (ENV 信号 + rootfs 标识文件 + 非挂载点)
|
|
12
8
|
# bash skills/teamsmith/tests/perf.sh --host # 宿主:明确标注「非参考环境」
|
|
13
9
|
# bash skills/teamsmith/tests/perf.sh --tree DIR # 测哪棵树(默认:本文件所在的 checkout)
|
|
14
10
|
#
|
|
15
|
-
#
|
|
16
|
-
#
|
|
17
|
-
#
|
|
18
|
-
#
|
|
19
|
-
#
|
|
20
|
-
#
|
|
21
|
-
# ② 由本套件直接测(夹具仓库里 5 次 `team monitor --print --no-activity`)。
|
|
11
|
+
# 用户裁定(2026-10-19,第二条):「性能只能作为参考指标,不能作为阻塞」。本套件只**测量并打印**:
|
|
12
|
+
# ① 交互首帧(三次独立 spawn 的中位,由 tests/panel-cpu.sh 量)
|
|
13
|
+
# ② 帧装配线(夹具仓库里 5 次 `team monitor --print --no-activity` 的中位)
|
|
14
|
+
# ③ 稳态窗格 CPU(同一个采样窗三等分的中位,由 tests/panel-cpu.sh 量)
|
|
15
|
+
# 以及 loadavg / 核数 / CPU 配额 / JS 运行时 / tmux / 被测版本。行首一律是「· 参考」;
|
|
16
|
+
# **没有阈值红线、没有负载前提、没有 SKIP 结论**:机器多忙都照打数字,数字多大都不改变退出码。
|
|
22
17
|
#
|
|
23
|
-
# 退出码:**0**
|
|
24
|
-
#
|
|
25
|
-
#
|
|
26
|
-
#
|
|
27
|
-
#
|
|
28
|
-
# · 参考环境 = `ci/Containerfile` 的钉死镜像;`--host` 明确标注「非参考环境」。
|
|
29
|
-
# · --in-container 只信镜像自身的身份证明(M66 · M64 F2 → M69 → M73):① 镜像 ENV 的身份信号
|
|
30
|
-
# TEAM_PERF_PINNED_CONTAINER=1(单独不够 —— 导出的变量宿主也能伪造,M64 F2 复验成立);
|
|
31
|
-
# ② rootfs 标识文件 /etc/teamsmith-gate-image 内容逐字节等于封闭 token(/run/.containerenv
|
|
32
|
-
# 不能当证据:开发宿主本身就是 distrobox,那文件在宿主也存在);③ 该标识文件**不得是挂载点**
|
|
33
|
-
# (M73 · M64 F2 第三轮:token 写在公开的 ci/Containerfile 里,谁都能挂一份同内容文件进容器 ——
|
|
34
|
-
# 内容对只证明文件对,证明不了「来自镜像 rootfs」;真镜像里它在 overlayfs 上,/proc/self/mounts
|
|
35
|
-
# 没有它的条目;套件自己的 wrapper 只挂 /work 与主仓,从不挂它)。缺哪个/错哪个点名哪个,
|
|
36
|
-
# 可见拒绝 exit 3,宿主读数绝不记在参考环境名下;老镜像(无标识文件)同样 exit 3 并点名重建。
|
|
37
|
-
# · 引擎/镜像缺失 → 打印原因 + 精确的 build/run 命令 + 「参考环境不可用,本次为宿主判定,结论不作为
|
|
38
|
-
# 验收依据」,宿主读数照打但**不计成结论**(全部记 SKIP)→ exit 4。绝不静默把宿主数当参考。
|
|
39
|
-
# · 锁:自己的 TEAM_PERF_LOCK(flock --close -w + holder);**从不**拿正确性门禁的 TEAM_SMOKE_LOCK,
|
|
40
|
-
# 只在测量前对它做一次**只读**非阻塞探活(有人持锁就打印持有者与提示)。
|
|
41
|
-
# · 夹具旋钮(只在 TEAM_PERF_FIXTURE=1 时生效,真路径一律忽略并打印):TEAM_PERF_LOADAVG /
|
|
42
|
-
# TEAM_PERF_CORES / TEAM_PERF_FRAME_DELAY_MS。
|
|
18
|
+
# 退出码:**0** 读数都打完了;**3** 搭建失败(缺 tmux / JS 运行时 / 面板 bundle)或 --in-container
|
|
19
|
+
# 的身份证明缺失/不符(M66→M69→M73:拒绝以参考环境自居)。没有 2/4。
|
|
20
|
+
# · 参考环境 = `ci/Containerfile` 的钉死镜像;引擎/镜像不可用时照打宿主读数,只标注「非参考环境」。
|
|
21
|
+
# · 锁:自己的 TEAM_PERF_LOCK(flock --close -w + holder),两次读数不重叠;运行期间互斥被破坏时
|
|
22
|
+
# 打一行「读数可能受并发影响」,**不改变退出码**(它不是对产品的判定)。
|
|
43
23
|
set -uo pipefail
|
|
44
24
|
|
|
45
|
-
# ──
|
|
46
|
-
PERF_FRAME_BUDGET_MS=2000
|
|
47
|
-
PERF_CPU_MAX_PCT=1
|
|
48
|
-
PERF_ASSEMBLY_PREMISE_FACTOR=0.75
|
|
49
|
-
PERF_FIRST_FRAME_PREMISE_FACTOR=0.25
|
|
50
|
-
PERF_CPU_PREMISE_FACTOR=0.25
|
|
25
|
+
# ── 读数参数(P316:这些数字只是采样方式,不是阈值)───────────────────────────────────────
|
|
51
26
|
PERF_SAMPLES=5
|
|
52
27
|
|
|
53
28
|
here="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
54
29
|
# P53:临时根的唯一创建者(${TMPDIR:-/tmp} + owned 家族 + 回收)
|
|
55
30
|
. "$here/lib/tmp-root.sh"
|
|
31
|
+
# P287:门禁锁的伴生锁路径与「记录读哪一份」只在 scripts/lib/gate-lock.sh 里实现一次 ——
|
|
32
|
+
# 只读探活要按新位置读(互斥在伴生锁上,发布路径是兼容声明;旧写入者的记录仍在发布路径边上)
|
|
33
|
+
if [ -f "$here/../scripts/lib/gate-lock.sh" ]; then
|
|
34
|
+
# shellcheck source=../scripts/lib/gate-lock.sh
|
|
35
|
+
. "$here/../scripts/lib/gate-lock.sh"
|
|
36
|
+
fi
|
|
56
37
|
self="$here/perf.sh"
|
|
57
38
|
ORIG_ARGS=("$@")
|
|
58
39
|
tree=""
|
|
@@ -72,9 +53,8 @@ usage() {
|
|
|
72
53
|
--tree DIR 被测 checkout(默认:本文件所在的 checkout)。
|
|
73
54
|
--help 这一屏。
|
|
74
55
|
|
|
75
|
-
退出码:0
|
|
76
|
-
旋钮:TEAM_PERF_IMAGE / TEAM_PERF_ENGINE / TEAM_PERF_LOCK / TEAM_PERF_LOCK_WAIT /
|
|
77
|
-
TEAM_PERF_FIXTURE=1 + TEAM_PERF_LOADAVG / TEAM_PERF_CORES / TEAM_PERF_FRAME_DELAY_MS
|
|
56
|
+
退出码:0 读数打完了(性能不参与绿红)| 3 搭建失败 / --in-container 身份证明拒绝。
|
|
57
|
+
旋钮:TEAM_PERF_IMAGE / TEAM_PERF_ENGINE / TEAM_PERF_LOCK / TEAM_PERF_LOCK_WAIT / TEAM_PANEL_CPU_SECS
|
|
78
58
|
EOF
|
|
79
59
|
}
|
|
80
60
|
|
|
@@ -91,7 +71,7 @@ done
|
|
|
91
71
|
tree="${tree:-$(cd -P "$here/../../.." && pwd)}"
|
|
92
72
|
team_bin="$tree/skills/teamsmith/scripts/team"
|
|
93
73
|
panel_bundle="$tree/skills/teamsmith/scripts/panel/panel.js"
|
|
94
|
-
|
|
74
|
+
panel_cpu="$tree/skills/teamsmith/tests/panel-cpu.sh"
|
|
95
75
|
|
|
96
76
|
say() { printf '%s\n' "$*"; }
|
|
97
77
|
hdr() { printf '\n\033[1m== %s ==\033[0m\n' "$*"; }
|
|
@@ -164,105 +144,138 @@ perf_require_pinned_container() {
|
|
|
164
144
|
|
|
165
145
|
# ── 锁:自己一把(TEAM_PERF_LOCK),绝不拿门禁锁 ─────────────────────────────────────────────
|
|
166
146
|
# 两次性能运行必须串行(夹具量的是真 pane / CPU 份额,互相测量会让数字失去意义)。
|
|
167
|
-
#
|
|
168
|
-
#
|
|
147
|
+
# P287(D4 裁定「性能套件那把锁一并」):与正确性门禁**同一套锁机器** ——
|
|
148
|
+
# ① 两把锁、顺序固定(发布路径 = 兼容声明 → 伴生锁 = 运行互斥;同行同目录、`.machine`、点开头);
|
|
149
|
+
# 性能锁没有外部旧写入者,但同一套纪律买的是同一件事:别人的清理命令够不着互斥。
|
|
150
|
+
# ② 取锁的进程自己握 fd,套件跑在它的**子进程**里、两个锁 fd 关掉(`8>&- 9>&-`)——
|
|
151
|
+
# M23 的漏锁教训在这里同样是构造性关掉的;收尾只删**自己的记录**,锁文件永不 unlink。
|
|
152
|
+
# ③ 记录写在伴生锁边上(`<companion>.holder`),带 `lock_identity=fd|path` 与 `lock_dev_ino`。
|
|
153
|
+
# ④ 运行期间互斥被破坏(伴生锁被删/被换)⇒ 只打印一行「读数可能受并发影响」(P316:不判红)。
|
|
154
|
+
perf_lock_companion() { printf '%s\n' "$(gate_lock_companion_path "${1:-${TEAM_PERF_LOCK:-$(team_tmp_root)/teamsmith-perf.lock}}")"; }
|
|
169
155
|
perf_lock_or_continue() {
|
|
170
|
-
[ "${
|
|
156
|
+
[ "${PERF_LOCK_TAKEN:-0}" = "1" ] && return 0 # 子进程(真正跑套件的那个):锁由父进程取到了
|
|
157
|
+
# 容器里的那一层由**宿主这一层**持锁(引擎是 P0 的子进程,锁 fd 已被 8>&- 9>&- 关掉):
|
|
158
|
+
# 不再取锁、也不认领(认领判据在宿主那层已经判过)。
|
|
159
|
+
[ "${TEAM_PERF_LOCK_HELD_BY_RUNNER:-0}" = "1" ] && { note "性能锁由调用方(宿主运行)持有 → 容器内不再取锁"; return 0; }
|
|
171
160
|
[ "${TEAM_PERF_NO_LOCK:-0}" = "1" ] && { note "TEAM_PERF_NO_LOCK=1 → 不与别的性能运行串行(自担并发干扰)"; return 0; }
|
|
172
161
|
if ! command -v flock >/dev/null 2>&1; then
|
|
173
162
|
note "本机没有 flock → 不与别的性能运行串行(自担并发干扰)"
|
|
174
163
|
return 0
|
|
175
164
|
fi
|
|
176
|
-
local lock="${TEAM_PERF_LOCK:-$
|
|
165
|
+
local lock="${TEAM_PERF_LOCK:-$(team_tmp_root)/teamsmith-perf.lock}" wait_s="${TEAM_PERF_LOCK_WAIT:-1800}"
|
|
177
166
|
case "$wait_s" in ''|*[!0-9]*) wait_s=1800 ;; esac
|
|
167
|
+
local comp; comp="$(perf_lock_companion "$lock")"
|
|
178
168
|
mkdir -p "$(dirname "$lock")" 2>/dev/null || true
|
|
179
169
|
: >>"$lock" 2>/dev/null || { note "锁文件 $lock 建不了 → 不串行"; return 0; }
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
170
|
+
# 有界轮询取两把锁(每轮重算上限:跟着持有者心跳 —— 心跳在动则 4×wait_s,否则 wait_s;性能锁的
|
|
171
|
+
# 持有者记录不公布心跳,所以这里实际总是 wait_s)——
|
|
172
|
+
# 上限到点留下可读的一句(性能套件的退出码是 0/3:读到了 / 建立失败或拿不到锁 = 没结论(P316 起没有判定码 2/4))。
|
|
173
|
+
local rc=0 t0 queued=0 cap wait_used=0
|
|
174
|
+
t0="$(date +%s)"
|
|
175
|
+
while :; do
|
|
176
|
+
rc=0; gate_lock_acquire_pair "$lock" || rc=$?
|
|
177
|
+
[ "$rc" = "0" ] && break
|
|
178
|
+
if [ "$rc" = "2" ]; then
|
|
179
|
+
note "锁文件 $lock 建不了 → 不串行"; return 0
|
|
180
|
+
fi
|
|
181
|
+
IFS=$'\t' read -r cap _ _ _ < <(gate_lock_patience_pair "$lock" "$wait_s")
|
|
182
|
+
case "$cap" in ''|*[!0-9]*) cap="$wait_s" ;; esac
|
|
183
|
+
if [ "$queued" = "0" ]; then
|
|
184
|
+
queued=1
|
|
185
|
+
say "另一个性能运行正在跑($(gate_lock_describe_pair "$lock"));本次排队,最多等 ${cap}s"
|
|
186
|
+
fi
|
|
187
|
+
wait_used=$(( $(date +%s) - t0 ))
|
|
188
|
+
if [ "$wait_used" -ge "$cap" ]; then
|
|
189
|
+
printf 'perf: 等待 %ss 仍拿不到性能锁(持有者:%s)—— 另一个性能运行还没结束;不并发测量(exit 3)\n' \
|
|
190
|
+
"$wait_used" "$(gate_lock_describe_pair "$lock")" >&2
|
|
191
|
+
exit 3
|
|
192
|
+
fi
|
|
193
|
+
sleep 1
|
|
194
|
+
done
|
|
195
|
+
# 记录由**取锁的进程**(本 shell)写;两把锁的 mtime 刷一次(按 age 的清理器不该删活锁)
|
|
196
|
+
touch "$lock" "$comp" 2>/dev/null || true
|
|
197
|
+
local ident ino
|
|
198
|
+
IFS=$'\t' read -r ident ino < <(gate_lock_claim_identity "$comp")
|
|
199
|
+
gate_lock_write_holder "$comp" "$$" top "perf.sh" "perf" "$PWD" "$(date +%s)" - - - 0 - - "$ident" "$ino" || true
|
|
200
|
+
export PERF_LOCK_TAKEN=1 PERF_LOCK_CLAIMER_PID="$$" PERF_LOCK_CLAIMER_IDENTITY="$ident" PERF_LOCK_CLAIMER_DEV_INO="$ino"
|
|
201
|
+
export PERF_LOCK="$lock" PERF_LOCK_COMPANION="$comp"
|
|
202
|
+
local rc2=0
|
|
203
|
+
bash "$self" "${ORIG_ARGS[@]}" 8>&- 9>&- || rc2=$?
|
|
204
|
+
# 收尾:只删自己的记录;两把锁文件都留着(unlink 一个还有等待者阻塞在它 inode 上的锁,正是要消灭的静默分裂)
|
|
205
|
+
if gate_lock_holder_claimable "$comp" "$$"; then gate_lock_remove_holder "$comp"; fi
|
|
206
|
+
rmdir "$comp.runs" 2>/dev/null || true
|
|
207
|
+
exit "$rc2"
|
|
208
|
+
}
|
|
209
|
+
# 子进程认领:两条独立证据(记录里活着的是它 / 它的 /proc 里真有一个身份相符的锁描述符),
|
|
210
|
+
# 环境变量单独不作数;认领人还必须是**我的严格祖辈**(子套件那一层)。
|
|
211
|
+
perf_lock_claim_from_parent() {
|
|
212
|
+
[ "${PERF_LOCK_TAKEN:-0}" = "1" ] || return 0
|
|
213
|
+
[ -n "${PERF_LOCK_CLAIMER_PID:-}" ] || return 0
|
|
214
|
+
PERF_LOCK="${PERF_LOCK:-${TEAM_PERF_LOCK:-$(team_tmp_root)/teamsmith-perf.lock}}"
|
|
215
|
+
PERF_LOCK_COMPANION="$(perf_lock_companion "$PERF_LOCK")"
|
|
216
|
+
local p q ok=0
|
|
217
|
+
for q in $(gate_lock_ancestry_chain "$$"); do [ "$q" = "$PERF_LOCK_CLAIMER_PID" ] && ok=1 && break; done
|
|
218
|
+
[ "$ok" = "1" ] || { printf 'perf: 锁认领人 pid=%s 不在我的进程链上 → 按未持锁处理\n' "$PERF_LOCK_CLAIMER_PID" >&2; PERF_LOCK_TAKEN=0; return 0; }
|
|
219
|
+
if [ -s "$(gate_lock_holder_file "$PERF_LOCK_COMPANION")" ] \
|
|
220
|
+
&& [ "$(gate_lock_record_get "$(gate_lock_holder_file "$PERF_LOCK_COMPANION")" pid)" = "$PERF_LOCK_CLAIMER_PID" ] \
|
|
221
|
+
&& gate_lock_record_live "$(gate_lock_holder_file "$PERF_LOCK_COMPANION")"; then
|
|
222
|
+
PERF_LOCK_DEV_INO="$(gate_lock_record_get "$(gate_lock_holder_file "$PERF_LOCK_COMPANION")" lock_dev_ino)"
|
|
223
|
+
PERF_LOCK_IDENTITY="$(gate_lock_record_get "$(gate_lock_holder_file "$PERF_LOCK_COMPANION")" lock_identity)"
|
|
224
|
+
elif [ -n "${PERF_LOCK_CLAIMER_DEV_INO:-}" ] \
|
|
225
|
+
&& gate_lock_pid_holds_path "$PERF_LOCK_CLAIMER_PID" "$PERF_LOCK_COMPANION" "$PERF_LOCK_CLAIMER_DEV_INO"; then
|
|
226
|
+
PERF_LOCK_DEV_INO="$PERF_LOCK_CLAIMER_DEV_INO"; PERF_LOCK_IDENTITY="${PERF_LOCK_CLAIMER_IDENTITY:-fd}"
|
|
227
|
+
else
|
|
228
|
+
printf 'perf: 自述持锁(pid=%s)但记录与 /proc 都对不上 → 按未持锁处理(不并发测量)\n' "$PERF_LOCK_CLAIMER_PID" >&2
|
|
229
|
+
PERF_LOCK_TAKEN=0
|
|
194
230
|
fi
|
|
195
|
-
exit "$rc"
|
|
196
231
|
}
|
|
232
|
+
# 运行期间互斥被破坏 ⇒ 读数可能受并发影响(P316:只提示,不改变退出码)
|
|
233
|
+
perf_lock_identity_check() {
|
|
234
|
+
[ "${PERF_LOCK_TAKEN:-0}" = "1" ] && [ -n "${PERF_LOCK_DEV_INO:-}" ] || return 0
|
|
235
|
+
local r; r="$(gate_lock_snapshot "$PERF_LOCK_COMPANION" "${PERF_LOCK_IDENTITY:-fd}" "$PERF_LOCK_DEV_INO" "$PERF_LOCK_CLAIMER_PID")"
|
|
236
|
+
case "$r" in
|
|
237
|
+
ok|'') return 0 ;;
|
|
238
|
+
*) printf '\n · 参考 注意:运行期间性能锁的互斥被破坏(%s)—— 读数可能受并发影响(性能不参与绿红)\n' "$(printf '%s' "$r" | tr '\t' ' ')"
|
|
239
|
+
return 0 ;;
|
|
240
|
+
esac
|
|
241
|
+
}
|
|
242
|
+
if [ "${PERF_LOCK_TAKEN:-0}" = "1" ]; then perf_lock_claim_from_parent; fi
|
|
197
243
|
# --in-container 先验身份信号:缺了在这里就 exit 3,锁、临时目录、测量一样不沾。
|
|
198
244
|
if [ "$IN_CONTAINER" = "1" ]; then perf_require_pinned_container; fi
|
|
199
245
|
perf_lock_or_continue
|
|
200
|
-
if [ "${
|
|
201
|
-
|
|
202
|
-
|
|
246
|
+
if [ "${PERF_LOCK_TAKEN:-0}" = "1" ]; then
|
|
247
|
+
printf ' · 性能锁:互斥在伴生锁 %s(发布路径 %s 是兼容声明;两把都永不 unlink)\n' \
|
|
248
|
+
"$PERF_LOCK_COMPANION" "$PERF_LOCK"
|
|
203
249
|
fi
|
|
204
250
|
|
|
205
251
|
# 只读探活门禁锁:门禁在跑时性能读数会被它影响,打印持有者;**不排队等它**(性能锁独立)。
|
|
206
252
|
perf_smoke_lock_probe() {
|
|
207
|
-
local lock="${TEAM_SMOKE_LOCK:-$
|
|
208
|
-
|
|
209
|
-
if
|
|
210
|
-
|
|
253
|
+
local lock="${TEAM_SMOKE_LOCK:-$(team_tmp_root)/teamsmith-smoke.lock}" comp probe busy=0
|
|
254
|
+
comp="$lock"
|
|
255
|
+
if declare -F gate_lock_companion_path >/dev/null 2>&1; then comp="$(gate_lock_companion_path "$lock")"; fi
|
|
256
|
+
if ! command -v flock >/dev/null 2>&1; then return 0; fi
|
|
257
|
+
# P287:互斥在**伴生锁**上(发布路径是兼容声明,P287 之前的写入者只认它)—— 两把都只读探一次,
|
|
258
|
+
# 任一把被持有就算「门禁在跑」;记录按 pair 读(伴生锁边上优先,退回发布路径那条并标 version=legacy)。
|
|
259
|
+
for probe in "$comp" "$lock"; do
|
|
260
|
+
[ -e "$probe" ] || continue
|
|
261
|
+
flock -n "$probe" true 2>/dev/null || { busy=1; break; }
|
|
262
|
+
done
|
|
263
|
+
[ "$busy" = "1" ] || return 0
|
|
264
|
+
local who
|
|
265
|
+
if declare -F gate_lock_describe_pair >/dev/null 2>&1; then
|
|
266
|
+
who="$(gate_lock_describe_pair "$lock")"
|
|
267
|
+
else
|
|
268
|
+
who="$(cat "$lock.holder" 2>/dev/null || printf '持有者未知')"
|
|
211
269
|
fi
|
|
270
|
+
note "正确性门禁正在跑($who)—— 本次性能读数可能受它影响(性能锁独立,不等它)"
|
|
212
271
|
}
|
|
213
272
|
|
|
214
|
-
# ──
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
perf_load_reading() {
|
|
218
|
-
if [ -n "${TEAM_PERF_LOADAVG:-}" ]; then
|
|
219
|
-
if perf_fixture_on; then printf '%s\n' "$TEAM_PERF_LOADAVG"; return 0; fi
|
|
220
|
-
perf_notice TEAM_PERF_LOADAVG "$TEAM_PERF_LOADAVG"
|
|
221
|
-
fi
|
|
222
|
-
cut -d' ' -f1 /proc/loadavg 2>/dev/null || printf '?'
|
|
223
|
-
}
|
|
224
|
-
perf_cores() {
|
|
225
|
-
if [ -n "${TEAM_PERF_CORES:-}" ]; then
|
|
226
|
-
if perf_fixture_on; then printf '%s\n' "$TEAM_PERF_CORES"; return 0; fi
|
|
227
|
-
perf_notice TEAM_PERF_CORES "$TEAM_PERF_CORES"
|
|
228
|
-
fi
|
|
229
|
-
nproc 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null || printf '0'
|
|
230
|
-
}
|
|
231
|
-
perf_inject_ms() {
|
|
232
|
-
local v="${TEAM_PERF_FRAME_DELAY_MS:-}"
|
|
233
|
-
if [ -n "$v" ]; then
|
|
234
|
-
if perf_fixture_on; then printf '%s\n' "$v"; return 0; fi
|
|
235
|
-
perf_notice TEAM_PERF_FRAME_DELAY_MS "$v"
|
|
236
|
-
fi
|
|
237
|
-
printf '0\n'
|
|
238
|
-
}
|
|
273
|
+
# ── 机器读数(P316:只打印,不设前提、不判绿红)──────────────────────────────────────────
|
|
274
|
+
perf_load_reading() { cut -d' ' -f1 /proc/loadavg 2>/dev/null || printf '?'; }
|
|
275
|
+
perf_cores() { nproc 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null || printf '0'; }
|
|
239
276
|
perf_median() { printf '%s\n' "$@" | sort -n | awk '{a[NR] = $1} END {print a[int((NR + 1) / 2)]}'; }
|
|
240
277
|
|
|
241
278
|
# ── 判定(纯逻辑;真实路径与自检用**同一组**函数,所以自检不是另写一套)──────────────────────
|
|
242
|
-
# 前提:loadavg_1m ≤ factor × 逻辑核数(核数/读数不可用一律算不成立 —— 测不准就不判红)。
|
|
243
|
-
perf_premise_rc() { # <load> <cores> <factor> → 0 成立 / 1 不成立
|
|
244
|
-
local load="$1" cores="$2" factor="$3" thr
|
|
245
|
-
case "$load" in ''|*[!0-9.]*) return 1 ;; esac
|
|
246
|
-
case "$cores" in ''|*[!0-9]*) return 1 ;; esac
|
|
247
|
-
[ "$cores" -gt 0 ] 2>/dev/null || return 1
|
|
248
|
-
thr="$(awk -v c="$cores" -v f="$factor" 'BEGIN { printf "%.2f", f * c }')"
|
|
249
|
-
awk -v l="$load" -v t="$thr" 'BEGIN { exit !(l <= t) }'
|
|
250
|
-
}
|
|
251
|
-
# 帧预算判定:mode=le(装配,≤ 绿)或 lt(交互首帧,< 绿,≥ 红)。
|
|
252
|
-
perf_budget_rc() { # <值> <load> <cores> <factor> <le|lt> → 0 绿 / 1 红 / 2 SKIP
|
|
253
|
-
perf_premise_rc "$2" "$3" "$4" || return 2
|
|
254
|
-
if [ "$5" = "lt" ]; then
|
|
255
|
-
awk -v v="$1" -v b="$PERF_FRAME_BUDGET_MS" 'BEGIN { exit !(v < b) }'
|
|
256
|
-
else
|
|
257
|
-
awk -v v="$1" -v b="$PERF_FRAME_BUDGET_MS" 'BEGIN { exit !(v <= b) }'
|
|
258
|
-
fi
|
|
259
|
-
}
|
|
260
|
-
# 稳态窗格 CPU:< 1% 单核为绿。
|
|
261
|
-
perf_cpu_rc() { # <百分比> <load> <cores> <factor> → 0 / 1 / 2
|
|
262
|
-
perf_premise_rc "$2" "$3" "$4" || return 2
|
|
263
|
-
awk -v v="$1" -v b="$PERF_CPU_MAX_PCT" 'BEGIN { exit !(v < b) }'
|
|
264
|
-
}
|
|
265
|
-
|
|
266
279
|
# ── 引擎 / 镜像(参考环境)──────────────────────────────────────────────────────────────────
|
|
267
280
|
PERF_ENGINE=()
|
|
268
281
|
PERF_IMAGE=""
|
|
@@ -326,10 +339,10 @@ perf_run_in_container() {
|
|
|
326
339
|
opts=(--pid=host --user "$(id -u):$(id -g)")
|
|
327
340
|
fi
|
|
328
341
|
eng_env=(-e HOME=/tmp -e TEAM_PERF_MODE=container -e "TEAM_PERF_REV=$(git -C "$tree" rev-parse --short HEAD 2>/dev/null || printf 'unknown')")
|
|
329
|
-
#
|
|
342
|
+
# 锁的身份**不**透传:容器那一层不取锁(宿主持有),只带一句「锁由调用方持有」。
|
|
343
|
+
TEAM_PERF_LOCK_HELD_BY_RUNNER=1
|
|
330
344
|
local k
|
|
331
|
-
for k in
|
|
332
|
-
TEAM_PERF_LOCK_WRAPPED TEAM_PERF_NO_LOCK TEAM_PANEL_CPU_SECS; do
|
|
345
|
+
for k in TEAM_PANEL_CPU_SECS TEAM_PERF_LOCK_HELD_BY_RUNNER; do
|
|
333
346
|
[ -n "${!k:-}" ] && eng_env+=(-e "$k=${!k}")
|
|
334
347
|
done
|
|
335
348
|
say "参考环境:镜像 $PERF_IMAGE(引擎 ${PERF_ENGINE[*]})"
|
|
@@ -363,45 +376,28 @@ perf_setup_fixture() { # 夹具仓库(装配判定测的是面板装配,不
|
|
|
363
376
|
# 夹具仓库里的 team 调用:清掉继承的团队身份与所有夹具旋钮(身份隔离,M7.2 纪律)。
|
|
364
377
|
perf_team_env_init() { env -u TEAM_ROOT -u TEAM_MAIN_ROOT -u TEAM_SKILL_DIR -u TEAM_PROJECT -u TEAM_SESSION \
|
|
365
378
|
-u TEAM_STATE_DIR -u TEAM_JS_BIN -u TEAM_REQUIRE_JS -u TEAM_MONITOR_ACTIVITY -u TEAM_MONITOR_UI \
|
|
366
|
-
-u TEAM_AGENT_LOG_GLOB -u TEAM_SMOKE_FIXTURE -u
|
|
367
|
-
-u
|
|
368
|
-
-u TEAM_PANEL_CPU_FRAME_DELAY_MS -u TEAM_PANEL_CPU_PREMISE_ONLY "$@"; }
|
|
379
|
+
-u TEAM_AGENT_LOG_GLOB -u TEAM_SMOKE_FIXTURE -u TEAM_PANEL_CPU_LOADAVG \
|
|
380
|
+
-u TEAM_PANEL_CPU_CORES "$@"; } # P316:前提/帧时注入旋钮已随红线一起退役,名字一并清掉
|
|
369
381
|
perf_team() { ( cd "$PERF_FIX" && perf_team_env_init bash "$team_bin" "$@" ); }
|
|
370
382
|
|
|
371
383
|
perf_measure_assembly() { # → PERF_OBS 数组 + PERF_ASM_MEDIAN
|
|
372
|
-
local
|
|
373
|
-
inject_ms="$(perf_inject_ms)"
|
|
374
|
-
case "$inject_ms" in ''|*[!0-9]*) inject_ms=0 ;; esac
|
|
375
|
-
inject_s="$(awk -v ms="$inject_ms" 'BEGIN { printf "%.3f", ms / 1000 }')"
|
|
384
|
+
local t0 i
|
|
376
385
|
PERF_OBS=()
|
|
377
386
|
for ((i = 1; i <= PERF_SAMPLES; i++)); do
|
|
378
387
|
t0="$(date +%s%3N)"
|
|
379
388
|
perf_team monitor --print --no-activity >/dev/null 2>&1
|
|
380
|
-
[ "$inject_ms" -gt 0 ] && sleep "$inject_s" # 注入落在测量窗口里
|
|
381
389
|
PERF_OBS+=("$(( $(date +%s%3N) - t0 ))")
|
|
382
390
|
done
|
|
383
391
|
PERF_ASM_MEDIAN="$(perf_median "${PERF_OBS[@]}")"
|
|
384
392
|
}
|
|
385
393
|
|
|
386
394
|
# ── 汇总状态 ────────────────────────────────────────────────────────────────────────────────
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
SELFTEST_FAIL=0
|
|
395
|
+
J_FIRST_MEDIAN="?"; J_FIRST_READ=""
|
|
396
|
+
J_ASM_MEDIAN="?"; J_ASM_READ=""
|
|
397
|
+
J_CPU_MEDIAN="?"; J_CPU_READ=""
|
|
391
398
|
UNAVAILABLE=0
|
|
392
399
|
|
|
393
|
-
|
|
394
|
-
local factor="$1" cores="$2" load="$3" thr
|
|
395
|
-
case "$cores" in ''|*[!0-9]*) cores=0 ;; esac
|
|
396
|
-
thr="$(awk -v c="$cores" -v f="$factor" 'BEGIN { printf "%.2f", f * c }')"
|
|
397
|
-
if perf_premise_rc "$load" "$cores" "$factor"; then
|
|
398
|
-
printf '%s × %s = %s 成立(loadavg %s)' "$factor" "$cores" "$thr" "$load"
|
|
399
|
-
else
|
|
400
|
-
printf '%s × %s = %s **不成立**(loadavg %s)' "$factor" "$cores" "$thr" "$load"
|
|
401
|
-
fi
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
# ── 环境自述(判定之前)────────────────────────────────────────────────────────────────────
|
|
400
|
+
# ── 环境自述────────────────────────────────────────────────────────────────────
|
|
405
401
|
perf_env_description() { # <mode-label> <reference yes|no>
|
|
406
402
|
local mode_label="$1" reference="$2" cores load quota js tmux rev
|
|
407
403
|
cores="$(perf_cores)"; load="$(perf_load_reading)"
|
|
@@ -422,258 +418,56 @@ perf_env_description() { # <mode-label> <reference yes|no>
|
|
|
422
418
|
say " JS 运行时 : ${js:-缺}"
|
|
423
419
|
say " tmux : ${tmux:-缺}"
|
|
424
420
|
say " 被测版本 : $rev($tree)"
|
|
425
|
-
say "
|
|
421
|
+
say " 读数用途 : · 参考(性能不参与绿红;没有阈值,也不因负载跳过)"
|
|
426
422
|
}
|
|
427
423
|
|
|
428
|
-
# ──
|
|
429
|
-
|
|
430
|
-
local load cores rc=0
|
|
424
|
+
# ── 读数 ②:帧装配线(只打印)─────────────────────────────────────────────────────────────
|
|
425
|
+
perf_report_assembly() {
|
|
431
426
|
perf_measure_assembly
|
|
432
|
-
load="$(perf_load_reading)"; cores="$(perf_cores)"
|
|
433
|
-
J_ASM_PREMISE="$(perf_premise_text "$PERF_ASSEMBLY_PREMISE_FACTOR" "$cores" "$load")"
|
|
434
427
|
J_ASM_READ="$(printf '%s, ' "${PERF_OBS[@]}")"; J_ASM_READ="${J_ASM_READ%, }"
|
|
435
428
|
J_ASM_MEDIAN="$PERF_ASM_MEDIAN"
|
|
436
|
-
perf_budget_rc "$PERF_ASM_MEDIAN" "$load" "$cores" "$PERF_ASSEMBLY_PREMISE_FACTOR" le || rc=$?
|
|
437
|
-
case "$rc" in
|
|
438
|
-
0) J_ASM_VERDICT=OK ;;
|
|
439
|
-
1) J_ASM_VERDICT=RED ;;
|
|
440
|
-
*) J_ASM_VERDICT=SKIP ;;
|
|
441
|
-
esac
|
|
442
429
|
if [ "$UNAVAILABLE" = "1" ]; then
|
|
443
|
-
|
|
444
|
-
say " ② 帧装配线:宿主中位 ${J_ASM_MEDIAN}ms(样本 $J_ASM_READ)—— 参考环境不可用,不计成结论"
|
|
430
|
+
say " · 参考 帧装配线:宿主 ${PERF_SAMPLES} 次采样 $J_ASM_READ → 中位 ${J_ASM_MEDIAN}ms(非参考环境)"
|
|
445
431
|
else
|
|
446
|
-
say "
|
|
432
|
+
say " · 参考 帧装配线:${PERF_SAMPLES} 次采样 $J_ASM_READ → 中位 ${J_ASM_MEDIAN}ms(不比阈值)"
|
|
447
433
|
fi
|
|
448
434
|
}
|
|
449
435
|
|
|
450
|
-
# ──
|
|
451
|
-
|
|
452
|
-
local out="$PERF_TMP/panel-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
line="$(grep -a '== 结果 ==' "$out" 2>/dev/null | tail -1 | sed 's/\x1b\[[0-9;]*m//g')"
|
|
456
|
-
PERF_PANEL_RESULT_LINE="$line"
|
|
457
|
-
ff_line="$(sed -n 's/^first_frame_line=//p' "$out" | tail -1)"
|
|
458
|
-
pc_line="$(sed -n 's/^pane_cpu_line=//p' "$out" | tail -1)"
|
|
459
|
-
J_FIRST_READ="$ff_line"; J_CPU_READ="$pc_line"
|
|
460
|
-
J_FIRST_MEDIAN="$(printf '%s' "$ff_line" | sed -n 's/.*-> median \([0-9]*\|never\).*/\1/p')"
|
|
461
|
-
J_CPU_MEDIAN="$(printf '%s' "$pc_line" | sed -n 's/.*-> median \([0-9.]*\)%.*/\1/p')"
|
|
462
|
-
[ -n "$J_FIRST_MEDIAN" ] || J_FIRST_MEDIAN="?"
|
|
463
|
-
[ -n "$J_CPU_MEDIAN" ] || J_CPU_MEDIAN="?"
|
|
464
|
-
case "$rc" in
|
|
465
|
-
0) J_FIRST_VERDICT=OK; J_CPU_VERDICT=OK ;;
|
|
466
|
-
4) J_FIRST_VERDICT=SKIP; J_CPU_VERDICT=SKIP ;;
|
|
467
|
-
*) J_FIRST_VERDICT=RED; J_CPU_VERDICT=RED ;;
|
|
468
|
-
esac
|
|
469
|
-
local pload pcores
|
|
470
|
-
pload="$(perf_load_reading)"; pcores="$(perf_cores)"
|
|
471
|
-
J_FIRST_PREMISE="$(perf_premise_text "$PERF_FIRST_FRAME_PREMISE_FACTOR" "$pcores" "$pload")"
|
|
472
|
-
J_CPU_PREMISE="$(perf_premise_text "$PERF_CPU_PREMISE_FACTOR" "$pcores" "$pload")"
|
|
473
|
-
if [ "$UNAVAILABLE" = "1" ]; then
|
|
474
|
-
J_FIRST_VERDICT=SKIP; J_CPU_VERDICT=SKIP
|
|
475
|
-
say " ① 交互首帧:宿主读数 ${J_FIRST_READ:-无} —— 参考环境不可用,不计成结论"
|
|
476
|
-
say " ③ 稳态窗格 CPU:宿主读数 ${J_CPU_READ:-无} —— 参考环境不可用,不计成结论"
|
|
436
|
+
# ── 读数 ①③:交互首帧 + 稳态窗格 CPU(由 tests/panel-cpu.sh 量;它只打印参考行)──────────
|
|
437
|
+
perf_report_panel() {
|
|
438
|
+
local out="$PERF_TMP/panel-cpu.log" rc=0
|
|
439
|
+
if [ ! -f "$panel_cpu" ]; then
|
|
440
|
+
say " · 参考 面板读数:没测到(缺 $panel_cpu)"
|
|
477
441
|
return 0
|
|
478
442
|
fi
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
perf_self_tests() {
|
|
492
|
-
local st_rc
|
|
493
|
-
hdr "自检(判定函数与夹具旋钮)"
|
|
494
|
-
st() { # <名字> <期望 rc> <实际 rc>
|
|
495
|
-
if [ "$2" = "$3" ]; then
|
|
496
|
-
printf ' \033[32m✓\033[0m 自检 · %s(实际 %s)\n' "$1" "$3"
|
|
497
|
-
else
|
|
498
|
-
printf ' \033[31m✗\033[0m 自检 · %s(期望 %s,实际 %s)\n' "$1" "$2" "$3"; SELFTEST_FAIL=$((SELFTEST_FAIL + 1))
|
|
499
|
-
fi
|
|
500
|
-
}
|
|
501
|
-
local C=32
|
|
502
|
-
# 前提边界:== 阈值算成立(≤);阈值 + 0.1 算不成立。两个系数都测(0.75 装配 / 0.25 首帧·CPU)。
|
|
503
|
-
st_rc=0; perf_budget_rc 1200 "$(awk -v c=$C 'BEGIN{printf "%.2f", 0.75*c}')" "$C" 0.75 le || st_rc=$?
|
|
504
|
-
st "前提边界 0.75:loadavg == 阈值算成立" 0 "$st_rc"
|
|
505
|
-
st_rc=0; perf_budget_rc 1200 "$(awk -v c=$C 'BEGIN{printf "%.2f", 0.75*c+0.1}')" "$C" 0.75 le || st_rc=$?
|
|
506
|
-
st "前提边界 0.75:阈值 +0.1 算不成立" 2 "$st_rc"
|
|
507
|
-
st_rc=0; perf_cpu_rc 0.5 "$(awk -v c=$C 'BEGIN{printf "%.2f", 0.25*c}')" "$C" 0.25 || st_rc=$?
|
|
508
|
-
st "前提边界 0.25:loadavg == 阈值算成立" 0 "$st_rc"
|
|
509
|
-
st_rc=0; perf_cpu_rc 0.5 "$(awk -v c=$C 'BEGIN{printf "%.2f", 0.25*c+0.1}')" "$C" 0.25 || st_rc=$?
|
|
510
|
-
st "前提边界 0.25:阈值 +0.1 算不成立" 2 "$st_rc"
|
|
511
|
-
# 注入的慢帧 → **红**(证明套件不是永远绿);超前提负载 + 同一个慢帧 → 可见 SKIP(前提不是逃逸门)。
|
|
512
|
-
st_rc=0; perf_budget_rc 2600 0.50 "$C" 0.75 le || st_rc=$?
|
|
513
|
-
st "注入慢帧(2600ms)+ 安静 → 红" 1 "$st_rc"
|
|
514
|
-
st_rc=0; perf_budget_rc 2600 "$(awk -v c=$C 'BEGIN{printf "%.2f", 0.75*c+0.1}')" "$C" 0.75 le || st_rc=$?
|
|
515
|
-
st "注入慢帧 + 超前提负载 → 可见 SKIP" 2 "$st_rc"
|
|
516
|
-
st_rc=0; perf_budget_rc 1200 0.50 "$C" 0.75 le || st_rc=$?
|
|
517
|
-
st "健康帧 + 安静 → 绿" 0 "$st_rc"
|
|
518
|
-
# 首帧的红线是 < 2000(1900 绿、2000 红);CPU 是 < 1(0.99 绿、1.00 红)。
|
|
519
|
-
st_rc=0; perf_budget_rc 1900 0.50 "$C" 0.25 lt || st_rc=$?
|
|
520
|
-
st "首帧 1900ms + 安静 → 绿" 0 "$st_rc"
|
|
521
|
-
st_rc=0; perf_budget_rc 2000 0.50 "$C" 0.25 lt || st_rc=$?
|
|
522
|
-
st "首帧 2000ms + 安静 → 红(< 2000 才算绿)" 1 "$st_rc"
|
|
523
|
-
st_rc=0; perf_cpu_rc 0.99 0.50 "$C" 0.25 || st_rc=$?
|
|
524
|
-
st "窗格 CPU 0.99% → 绿" 0 "$st_rc"
|
|
525
|
-
st_rc=0; perf_cpu_rc 1.00 0.50 "$C" 0.25 || st_rc=$?
|
|
526
|
-
st "窗格 CPU 1.00% → 红(< 1% 才算绿)" 1 "$st_rc"
|
|
527
|
-
# 中位本体(拆分前 smoke 的判定自检,原样搬来):单次越线仍绿、中位越线才红。
|
|
528
|
-
if [ "$(perf_median 1240 1417 2030 1400 1500)" -le 2000 ] && [ "$(perf_median 2100 2050 2200 1900 2300)" -gt 2000 ]; then
|
|
529
|
-
printf ' \033[32m✓\033[0m 自检 · 中位:单次越线(2030ms)仍绿、中位越线(2100ms)判红\n'
|
|
530
|
-
else
|
|
531
|
-
printf ' \033[31m✗\033[0m 自检 · 中位判定坏了(%s / %s)\n' "$(perf_median 1240 1417 2030 1400 1500)" "$(perf_median 2100 2050 2200 1900 2300)"
|
|
532
|
-
SELFTEST_FAIL=$((SELFTEST_FAIL + 1))
|
|
533
|
-
fi
|
|
534
|
-
# 身份证明(M66 · M64 F2 → M69):双重校验。① ENV 信号 =1 才通过,缺失/其它值一律拒绝;
|
|
535
|
-
# ② 标识文件存在且内容逐字节等于封闭 token —— --in-container 的谎报守卫用的就是同一组函数;
|
|
536
|
-
# 接线(入口先验证明再碰锁)用真 CLI 子进程钉,拒绝必须瞬时(timeout 10:若接线被改回
|
|
537
|
-
# 「信了口头声明」,子进程会走进锁/套件被杀 → rc≠3 → 红)。
|
|
538
|
-
st_rc=0; ( TEAM_PERF_PINNED_CONTAINER=1; perf_pinned_signal_rc ) || st_rc=$?
|
|
539
|
-
st "身份信号:=1 → 通过" 0 "$st_rc"
|
|
540
|
-
st_rc=0; ( unset TEAM_PERF_PINNED_CONTAINER; perf_pinned_signal_rc ) || st_rc=$?
|
|
541
|
-
st "身份信号:缺失 → 拒绝" 1 "$st_rc"
|
|
542
|
-
st_rc=0; ( TEAM_PERF_PINNED_CONTAINER=0; perf_pinned_signal_rc ) || st_rc=$?
|
|
543
|
-
st "身份信号:=0(被改)→ 拒绝" 1 "$st_rc"
|
|
544
|
-
# ② 标识文件本体(函数级,夹具文件):逐字节相等才算数 —— 缺尾换行/多加内容都是「不符」。
|
|
545
|
-
local idf="$PERF_TMP/identity-token"
|
|
546
|
-
printf '%s\n' "$PERF_IMAGE_IDENTITY_TOKEN" > "$idf"
|
|
547
|
-
st_rc=0; perf_image_identity_rc "$idf" || st_rc=$?
|
|
548
|
-
st "标识文件:内容逐字节等于 token → 通过" 0 "$st_rc"
|
|
549
|
-
st_rc=0; perf_image_identity_rc "$PERF_TMP/identity-absent" || st_rc=$?
|
|
550
|
-
st "标识文件:缺失 → 拒绝(缺失)" 1 "$st_rc"
|
|
551
|
-
printf 'teamsmith-gate:999\n' > "$idf"
|
|
552
|
-
st_rc=0; perf_image_identity_rc "$idf" || st_rc=$?
|
|
553
|
-
st "标识文件:token 被改 → 拒绝(不符)" 2 "$st_rc"
|
|
554
|
-
printf '%s' "$PERF_IMAGE_IDENTITY_TOKEN" > "$idf"
|
|
555
|
-
st_rc=0; perf_image_identity_rc "$idf" || st_rc=$?
|
|
556
|
-
st "标识文件:缺尾换行(非逐字节相等)→ 拒绝(不符)" 2 "$st_rc"
|
|
557
|
-
# ③ 挂载点判定(M73 · M64 F2 第三轮):挂载来的正确 token 也是伪造。夹具 mounts 表:
|
|
558
|
-
local mtf="$PERF_TMP/mounts-fixture"
|
|
559
|
-
: > "$mtf"
|
|
560
|
-
st_rc=0; perf_image_identity_mounted_rc "$mtf" || st_rc=$?
|
|
561
|
-
st "挂载判定:空 mounts 表 → 不算挂载" 1 "$st_rc"
|
|
562
|
-
{ printf '%s\n' 'proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0'
|
|
563
|
-
printf '%s\n' 'overlay / overlay rw,lowerdir=/l/1,upperdir=/l/2,workdir=/l/3 0 0'
|
|
564
|
-
printf '%s\n' '/dev/sda1 /work ext4 rw,relatime 0 0'
|
|
565
|
-
printf '%s\n' 'tmpfs /etc/resolv.conf tmpfs rw 0 0'; } > "$mtf"
|
|
566
|
-
st_rc=0; perf_image_identity_mounted_rc "$mtf" || st_rc=$?
|
|
567
|
-
st "挂载判定:真镜像形状(overlayfs / + /work + resolv.conf,无标识文件条目)→ 不算挂载" 1 "$st_rc"
|
|
568
|
-
printf '%s\n' '/dev/sda1 /etc/teamsmith-gate-image ext4 ro,relatime 0 0' >> "$mtf"
|
|
569
|
-
st_rc=0; perf_image_identity_mounted_rc "$mtf" || st_rc=$?
|
|
570
|
-
st "挂载判定:标识文件是挂载目标(伪造形状)→ 判挂载" 0 "$st_rc"
|
|
571
|
-
printf '%s\n' '/dev/sda1 /etc/teamsmith-gate-image\040bak ext4 ro 0 0' > "$mtf"
|
|
572
|
-
st_rc=0; perf_image_identity_mounted_rc "$mtf" || st_rc=$?
|
|
573
|
-
st "挂载判定:转义路径(\\040 解开后是别的文件)→ 不误判" 1 "$st_rc"
|
|
574
|
-
st_rc=0; perf_image_identity_mounted_rc "$PERF_TMP/mounts-absent" || st_rc=$?
|
|
575
|
-
st "挂载判定:mounts 表读不到 → 这一条判不了,不据此拒绝" 1 "$st_rc"
|
|
576
|
-
local wir_rc wir_log="$PERF_TMP/m66-wiring.log"
|
|
577
|
-
wir_rc=0
|
|
578
|
-
timeout 10 env -u TEAM_PERF_PINNED_CONTAINER -u TEAM_PERF_LOCK_WRAPPED -u TEAM_PERF_NO_LOCK \
|
|
579
|
-
bash "$self" --in-container >"$wir_log" 2>&1 || wir_rc=$?
|
|
580
|
-
st "入口接线:缺信号 → 真 CLI 可见拒绝 exit 3" 3 "$wir_rc"
|
|
581
|
-
if [ "$wir_rc" = "3" ] && grep -q 'TEAM_PERF_PINNED_CONTAINER' "$wir_log" && grep -q -- '--host' "$wir_log"; then
|
|
582
|
-
printf ' \033[32m✓\033[0m 自检 · 入口接线:拒绝点名身份信号与 --host 出路\n'
|
|
583
|
-
else
|
|
584
|
-
printf ' \033[31m✗\033[0m 自检 · 入口接线:拒绝信息没点名信号/--host(rc=%s)\n' "$wir_rc"
|
|
585
|
-
SELFTEST_FAIL=$((SELFTEST_FAIL + 1))
|
|
586
|
-
fi
|
|
587
|
-
wir_rc=0
|
|
588
|
-
timeout 10 env -u TEAM_PERF_LOCK_WRAPPED -u TEAM_PERF_NO_LOCK TEAM_PERF_PINNED_CONTAINER=0 \
|
|
589
|
-
bash "$self" --in-container >"$wir_log" 2>&1 || wir_rc=$?
|
|
590
|
-
st "入口接线:错信号(=0)→ 真 CLI 可见拒绝 exit 3" 3 "$wir_rc"
|
|
591
|
-
# M69 接线:ENV 信号齐全但标识文件缺失/不符(= M64 F2 的宿主伪造形状)也必须瞬时拒绝。
|
|
592
|
-
# 在真镜像里文件本就在 —— 换成钉「镜像里的文件逐字节等于 token」(镜像构建错了在这里红)。
|
|
593
|
-
if [ ! -e "$PERF_IMAGE_IDENTITY_FILE" ]; then
|
|
594
|
-
wir_rc=0
|
|
595
|
-
timeout 10 env -u TEAM_PERF_LOCK_WRAPPED -u TEAM_PERF_NO_LOCK TEAM_PERF_PINNED_CONTAINER=1 \
|
|
596
|
-
bash "$self" --in-container >"$wir_log" 2>&1 || wir_rc=$?
|
|
597
|
-
st "入口接线:有 ENV 信号但缺标识文件(宿主伪造形状)→ 真 CLI 可见拒绝 exit 3" 3 "$wir_rc"
|
|
598
|
-
if [ "$wir_rc" = "3" ] && grep -q 'teamsmith-gate-image' "$wir_log"; then
|
|
599
|
-
printf ' \033[32m✓\033[0m 自检 · 入口接线:拒绝点名缺镜像标识文件\n'
|
|
600
|
-
else
|
|
601
|
-
printf ' \033[31m✗\033[0m 自检 · 入口接线:拒绝没点名标识文件(rc=%s)\n' "$wir_rc"
|
|
602
|
-
SELFTEST_FAIL=$((SELFTEST_FAIL + 1))
|
|
603
|
-
fi
|
|
604
|
-
else
|
|
605
|
-
st_rc=0; perf_image_identity_rc || st_rc=$?
|
|
606
|
-
st "入口接线:本机即钉死镜像 —— 标识文件逐字节等于 token" 0 "$st_rc"
|
|
607
|
-
fi
|
|
608
|
-
# M73 接线:perf_require_pinned_container 真的会查挂载点 —— ①② 都齐但标识文件是挂载的也必须
|
|
609
|
-
# 瞬时拒绝。测试里造不了真挂载(要特权),用函数覆盖造同一判定面(真挂载的端到端翻转 = podman
|
|
610
|
-
# 实跑,见 M73 报告);再放行形一条:①②③ 全齐 → rc=0(覆盖全在子壳里,不影响外层)。
|
|
611
|
-
local m73_out
|
|
612
|
-
m73_out="$( { perf_pinned_signal_rc() { return 0; }; perf_image_identity_rc() { return 0; };
|
|
613
|
-
perf_image_identity_mounted_rc() { return 0; }; perf_require_pinned_container; } 2>&1 )"; wir_rc=$?
|
|
614
|
-
st "入口接线:信号+内容齐但标识文件是挂载的(伪造形状)→ 可见拒绝 exit 3" 3 "$wir_rc"
|
|
615
|
-
if [ "$wir_rc" = "3" ] && printf '%s' "$m73_out" | grep -q '挂载' && printf '%s' "$m73_out" | grep -q 'teamsmith-gate-image'; then
|
|
616
|
-
printf ' \033[32m✓\033[0m 自检 · 入口接线:拒绝点名「标识文件是挂载的,不是镜像烘焙的」\n'
|
|
617
|
-
else
|
|
618
|
-
printf ' \033[31m✗\033[0m 自检 · 入口接线:挂载拒绝没点名挂载/标识文件(rc=%s)\n' "$wir_rc"
|
|
619
|
-
SELFTEST_FAIL=$((SELFTEST_FAIL + 1))
|
|
620
|
-
fi
|
|
621
|
-
m73_out="$( { perf_pinned_signal_rc() { return 0; }; perf_image_identity_rc() { return 0; };
|
|
622
|
-
perf_image_identity_mounted_rc() { return 1; }; perf_require_pinned_container; } 2>&1 )"; wir_rc=$?
|
|
623
|
-
st "入口接线:信号+内容齐且不是挂载(真镜像形状)→ 放行 rc=0" 0 "$wir_rc"
|
|
624
|
-
# 真路径:夹具开关关着时,三个注入旋钮都被忽略且打印,读数不变。
|
|
625
|
-
if perf_fixture_on; then
|
|
626
|
-
note "自检 · 真路径旋钮忽略:跳过(TEAM_PERF_FIXTURE=1 夹具模式开着,注入按设计生效)"
|
|
443
|
+
TEAM_PANEL_CPU_SECS="${TEAM_PANEL_CPU_SECS:-6}" bash "$panel_cpu" >"$out" 2>&1 || rc=$?
|
|
444
|
+
# P316 · V61 D1:此前单引号里又双写了反斜杠(模式永远匹配不到 → 汇总表打 `?ms`/`无读数`),
|
|
445
|
+
# 且中位值里已经带着单位、表格又补了一次(`4065msms`)。这里只取数字,单位由表格那一列给。
|
|
446
|
+
J_FIRST_MEDIAN="$(sed -n 's/^.*· 参考 首帧:\([0-9][0-9.]*\)ms(3 次独立 spawn.*$/\1/p' "$out" | tail -1)"
|
|
447
|
+
J_CPU_MEDIAN="$(sed -n 's/^.*窗格 CPU:\([0-9][0-9.]*\)%(三等分中位).*$/\1/p' "$out" | tail -1)"
|
|
448
|
+
# 说明列不再从上面那一行里二次解析:cut -d 只收单字节分隔符(多字节「|」直接报错),而 C locale
|
|
449
|
+
# 下 sed 的 `.*`/`[^x]` 跨多字节回溯会静默失败(V61 D1 的同一类坑,本地实测三种写法都空)。
|
|
450
|
+
# 逐次读数与三等分已经原样打印在表上方,这里只写它们是什么。
|
|
451
|
+
J_FIRST_READ="3 次独立 spawn 的中位(上面逐次读数)"
|
|
452
|
+
J_CPU_READ="三等分中位(上面三等分读数)"
|
|
453
|
+
if [ "$rc" != "0" ]; then
|
|
454
|
+
say " · 参考 面板读数:没测到(panel-cpu rc=$rc);尾部:$(tail -1 "$out" | sed 's/^ *//')"
|
|
627
455
|
return 0
|
|
628
456
|
fi
|
|
629
|
-
|
|
630
|
-
real_load="$(cut -d' ' -f1 /proc/loadavg 2>/dev/null || printf '?')"
|
|
631
|
-
real_cores="$(nproc 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null || printf '0')"
|
|
632
|
-
export TEAM_PERF_LOADAVG=9999 TEAM_PERF_CORES=1 TEAM_PERF_FRAME_DELAY_MS=99999
|
|
633
|
-
fake_load="$(perf_load_reading 2>/dev/null)"; fake_cores="$(perf_cores 2>/dev/null)"; fake_inj="$(perf_inject_ms 2>/dev/null)"
|
|
634
|
-
notices="$( { perf_load_reading >/dev/null; perf_cores >/dev/null; perf_inject_ms >/dev/null; } 2>&1 )"
|
|
635
|
-
unset TEAM_PERF_LOADAVG TEAM_PERF_CORES TEAM_PERF_FRAME_DELAY_MS
|
|
636
|
-
st "真路径:注入的 loadavg 被忽略(读到真值 ${real_load})" "$real_load" "$fake_load"
|
|
637
|
-
st "真路径:注入的核数被忽略(读到真值 ${real_cores})" "$real_cores" "$fake_cores"
|
|
638
|
-
st "真路径:注入的慢帧拆成 0" "0" "$fake_inj"
|
|
639
|
-
if printf '%s' "$notices" | grep -q '忽略 TEAM_PERF_LOADAVG=9999' \
|
|
640
|
-
&& printf '%s' "$notices" | grep -q '忽略 TEAM_PERF_CORES=1' \
|
|
641
|
-
&& printf '%s' "$notices" | grep -q '忽略 TEAM_PERF_FRAME_DELAY_MS=99999'; then
|
|
642
|
-
printf ' \033[32m✓\033[0m 自检 · 真路径:三个注入旋钮都被忽略并打印\n'
|
|
643
|
-
else
|
|
644
|
-
printf ' \033[31m✗\033[0m 自检 · 真路径:旋钮忽略没有打印出来\n'; SELFTEST_FAIL=$((SELFTEST_FAIL + 1))
|
|
645
|
-
fi
|
|
457
|
+
sed 's/\\x1b\\[[0-9;]*m//g' "$out" | grep -a '· 参考' | sed 's/^ *//; s/^/ /'
|
|
646
458
|
}
|
|
647
459
|
|
|
648
|
-
# ──
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
printf '
|
|
653
|
-
printf ' %s\n' "
|
|
654
|
-
printf '
|
|
655
|
-
printf '
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
[ "$v" = "RED" ] && reds=$((reds + 1))
|
|
660
|
-
[ "$v" = "SKIP" ] && skips=$((skips + 1))
|
|
661
|
-
done
|
|
662
|
-
printf '\n== 结果 == ✓ %d 绿 ✗ %d 红 SKIP %d 没结论(自检失败 %d);参考环境:%s;面板夹具:%s\n' \
|
|
663
|
-
"$((3 - reds - skips))" "$reds" "$skips" "$SELFTEST_FAIL" "$([ "$PERF_REFERENCE" = yes ] && printf '是' || printf '否')" "${PERF_PANEL_RESULT_LINE:-无}"
|
|
664
|
-
if [ "$SELFTEST_FAIL" -gt 0 ]; then
|
|
665
|
-
printf '\033[31mperf: 自检失败 %d 条 → exit 2(套件自己的判定坏了,不能给结论)\033[0m\n' "$SELFTEST_FAIL"
|
|
666
|
-
return 2
|
|
667
|
-
fi
|
|
668
|
-
if [ "$reds" -gt 0 ]; then
|
|
669
|
-
printf '\033[31mperf: %d 条红 → exit 2\033[0m\n' "$reds"
|
|
670
|
-
return 2
|
|
671
|
-
fi
|
|
672
|
-
if [ "$skips" -gt 0 ]; then
|
|
673
|
-
printf '\033[33mperf: 没有红,但有 %d 条可见 SKIP → exit 4(没结论;不是通过)\033[0m\n' "$skips"
|
|
674
|
-
return 4
|
|
675
|
-
fi
|
|
676
|
-
printf '\033[32mperf: 三条判定全绿 → exit 0\033[0m\n'
|
|
460
|
+
# ── 参考读数汇总(没有判定,没有退出码)─────────────────────────────────────────────────────
|
|
461
|
+
perf_report() {
|
|
462
|
+
hdr "参考读数汇总(perf suite)"
|
|
463
|
+
printf ' 读数 | 中位 | 样本 / 说明\n'
|
|
464
|
+
printf ' -------------------------+--------------+--------------------------------\n'
|
|
465
|
+
printf ' ① 交互首帧 | %-12s | %s\n' "${J_FIRST_MEDIAN:+${J_FIRST_MEDIAN}ms}" "${J_FIRST_READ:-没测到}"
|
|
466
|
+
printf ' ② 帧装配线 | %-12s | %s\n' "${J_ASM_MEDIAN:+${J_ASM_MEDIAN}ms}" "${J_ASM_READ:-没测到}"
|
|
467
|
+
printf ' ③ 稳态窗格 CPU | %-12s | %s\n' "${J_CPU_MEDIAN:+${J_CPU_MEDIAN}%}" "${J_CPU_READ:-没测到}"
|
|
468
|
+
local ref="否(非参考环境)"
|
|
469
|
+
[ "${PERF_REFERENCE:-no}" = yes ] && ref="是(钉死镜像)"
|
|
470
|
+
printf '\n== 结果 == · 参考(性能不参与绿红;参考环境:%s);没有红/绿/SKIP 结论\n' "$ref"
|
|
677
471
|
return 0
|
|
678
472
|
}
|
|
679
473
|
|
|
@@ -684,7 +478,7 @@ perf_run_suite() { # <mode-label> <reference yes|no> [unavailable]
|
|
|
684
478
|
UNAVAILABLE="${3:-0}"
|
|
685
479
|
local js=""
|
|
686
480
|
if ! command -v tmux >/dev/null 2>&1; then
|
|
687
|
-
printf 'perf: 搭建失败 ——
|
|
481
|
+
printf 'perf: 搭建失败 —— 面板读数要真 tmux 窗格,本机没有 tmux(exit 3)\n' >&2; return 3
|
|
688
482
|
fi
|
|
689
483
|
js="${TEAM_JS_BIN:-$(command -v node 2>/dev/null || command -v bun 2>/dev/null || true)}"
|
|
690
484
|
if [ -z "$js" ]; then
|
|
@@ -693,23 +487,24 @@ perf_run_suite() { # <mode-label> <reference yes|no> [unavailable]
|
|
|
693
487
|
if [ ! -f "$panel_bundle" ]; then
|
|
694
488
|
printf 'perf: 搭建失败 —— 树里没有面板 bundle(%s)(exit 3)\n' "$panel_bundle" >&2; return 3
|
|
695
489
|
fi
|
|
696
|
-
if [ ! -f "$
|
|
697
|
-
printf 'perf: 搭建失败 ——
|
|
490
|
+
if [ ! -f "$panel_cpu" ]; then
|
|
491
|
+
printf 'perf: 搭建失败 —— 缺面板读数夹具(%s)(exit 3)\n' "$panel_cpu" >&2; return 3
|
|
698
492
|
fi
|
|
699
493
|
perf_env_description "$mode_label" "$reference"
|
|
700
494
|
perf_smoke_lock_probe
|
|
701
495
|
if [ "$UNAVAILABLE" = "1" ]; then
|
|
702
|
-
printf '\n
|
|
496
|
+
printf '\n · 参考 注意:参考环境不可用,本次是宿主读数(只作参考,不是验收依据)\n'
|
|
703
497
|
fi
|
|
704
498
|
if ! perf_setup_fixture; then
|
|
705
499
|
printf 'perf: 搭建失败 —— 夹具仓库 init 没成功(见 %s)(exit 3)\n' "$PERF_TMP/init.log" >&2
|
|
706
500
|
tail -3 "$PERF_TMP/init.log" 2>/dev/null | sed 's/^/ /'
|
|
707
501
|
return 3
|
|
708
502
|
fi
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
503
|
+
perf_report_assembly
|
|
504
|
+
perf_report_panel
|
|
505
|
+
perf_lock_identity_check || true
|
|
506
|
+
perf_report
|
|
507
|
+
return 0
|
|
713
508
|
}
|
|
714
509
|
|
|
715
510
|
# ── 入口 ────────────────────────────────────────────────────────────────────────────────────
|
|
@@ -717,14 +512,10 @@ rc=0
|
|
|
717
512
|
if [ "$MODE" = "host" ]; then
|
|
718
513
|
perf_run_suite "host(--host:非参考环境)" no || rc=$?
|
|
719
514
|
elif [ "$IN_CONTAINER" = "1" ]; then
|
|
720
|
-
#
|
|
721
|
-
# exit 3 并点名)——走到这里才算真的在钉死镜像里。仍**不**用 /.dockerenv、/run/.containerenv
|
|
722
|
-
# 自动判断:distrobox 也是容器(/run/.containerenv 在开发宿主上就存在,PM 实测),那样会把开发
|
|
723
|
-
# 容器误当参考镜像(实测过:宿主路径与宿主 tmux 混进了「参考环境」的自述里)。
|
|
515
|
+
# 身份证明已验(入口在拿锁之前查过 ENV 信号与 rootfs 标识文件,缺失/不符早已 exit 3 并点名)。
|
|
724
516
|
perf_run_suite "container(参考环境:钉死镜像)" yes || rc=$?
|
|
725
517
|
else
|
|
726
|
-
# 默认(含 --container
|
|
727
|
-
# 结论全部记 SKIP、打印「参考环境不可用,本次为宿主判定,结论不作为验收依据」并 exit 4。
|
|
518
|
+
# 默认(含 --container):参考环境;引擎/镜像不可用时照打宿主读数,只标注「非参考环境」。
|
|
728
519
|
if perf_detect_engine && perf_detect_image; then
|
|
729
520
|
perf_run_in_container || rc=$?
|
|
730
521
|
else
|