Skip to content

CodexBar 是一个 macOS 菜单栏应用,用于查看本机 Codex 账号状态、额度、Token 用量、详细统计信息

feat: 为性能采样目录添加版本与构建标识

Bob32144881da3e
diff --git a/Scripts/performance/README.md b/Scripts/performance/README.md
index 2d89a4e..4ea9db2 100644
--- a/Scripts/performance/README.md
+++ b/Scripts/performance/README.md
@@ -47,10 +47,10 @@ python3 -m Scripts.performance \
## 输出位置
-默认输出到仓库根目录下的 `Performance/YYYYMMDD/HHMMSS-{preset}/`,日期和时间取测试启动时的本地时间。例如:
+默认输出到仓库根目录下的 `Performance/{version}({build})-{preset}-YYYYMMDDHHmmss/`,日期和时间取测试启动时的本地时间,精确到秒。版本和构建号分别读取 `Config/Version.xcconfig` 中的 `MARKETING_VERSION` 和 `CURRENT_PROJECT_VERSION`,保留版本号中的点号。
```text
-Performance/20260912/103000-quick/
+Performance/4.1.1(123)-extended-20261024140000/
├── performance.html
├── performance.json
├── schemas.json
@@ -62,6 +62,8 @@ Performance/20260912/103000-quick/
`performance.html` 用于查看报告,`performance.json` 用于基线比较和重新生成报告,`*.trace` 可用 Instruments 打开。目录内同时保存采样 XML、命令日志和工具源码快照。
+已有同名目录时,脚本会报错而不覆盖已有结果。可用 `--output` 指定其他新目录:
+
```sh
python3 -m Scripts.performance --preset quick --output Performance/idle-01
```
diff --git a/Scripts/performance/__main__.py b/Scripts/performance/__main__.py
index 659ff41..e39dbad 100644
--- a/Scripts/performance/__main__.py
+++ b/Scripts/performance/__main__.py
@@ -6,6 +6,7 @@ import hashlib
import json
import os
import platform
+import re
import signal
import sys
import tempfile
@@ -65,10 +66,23 @@ def main() -> int:
for value in (args.cpu_mean_budget, args.footprint_budget):
if value is not None and (not 0 < value < float("inf")):
parser.error("Budgets must be finite positive numbers")
- timestamp = dt.datetime.now().strftime("%Y%m%d/%H%M%S")
- output = (
- args.output or ROOT / "Performance" / f"{timestamp}-{args.preset}"
- ).resolve()
+ output = args.output
+ if output is None:
+ version_config = ROOT / "Config/Version.xcconfig"
+ try:
+ version_text = version_config.read_text()
+ except OSError as error:
+ parser.error(f"Cannot read {version_config}: {error}")
+ version_match = re.search(r"(?m)^\s*MARKETING_VERSION\s*=\s*(\d+(?:\.\d+)+)\s*$", version_text)
+ if version_match is None:
+ parser.error(f"Missing or invalid MARKETING_VERSION in {version_config}")
+ build_match = re.search(r"(?m)^\s*CURRENT_PROJECT_VERSION\s*=\s*(\d+(?:\.\d+)*)\s*$", version_text)
+ if build_match is None:
+ parser.error(f"Missing or invalid CURRENT_PROJECT_VERSION in {version_config}")
+ version = f"{version_match.group(1)}({build_match.group(1)})"
+ timestamp = dt.datetime.now().strftime("%Y%m%d%H%M%S")
+ output = ROOT / "Performance" / f"{version}-{args.preset}-{timestamp}"
+ output = output.resolve()
try:
output.mkdir(parents=True, exist_ok=False)
except OSError as error: