Skip to content

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

refactor: 区分性能采集标签与报告输出路径

Bobfc13a20751d3
diff --git a/Scripts/performance/README.md b/Scripts/performance/README.md
index 05299d3..679bb1c 100644
--- a/Scripts/performance/README.md
+++ b/Scripts/performance/README.md
@@ -37,8 +37,9 @@ python3 -m Scripts.performance \
| `--app PATH` | App 路径,默认 `/Applications/CodexBar.app` |
| `--pid PID` | 指定待测试进程,存在多个 App 实例时使用 |
| `--preset NAME` | 选择 `quick`、`standard` 或 `extended` |
-| `--output VALUE` | 采集时追加目录名后缀,重新生成报告时指定 HTML 文件路径 |
-| `--workload TEXT` | 记录测试场景说明 |
+| `--label TEXT` | 本次测试的标签,会追加到采集目录名末尾 |
+| `--output PATH` | 配合 `--render` 指定 HTML 文件路径 |
+| `--workload TEXT` | 记录测试场景说明,默认 default |
| `--baseline PATH` | 指定基线 `performance.json` |
| `--cpu-mean-budget NUMBER` | 各阶段平均 CPU 上限,单位为 `%` |
| `--footprint-budget NUMBER` | 各阶段 Footprint 峰值上限,单位为 `MiB` |
@@ -62,10 +63,10 @@ Performance/4.1.1(111)-extended-20261024140000/
`performance.html` 用于查看报告,`performance.json` 用于基线比较和重新生成报告,`*.trace` 可用 Instruments 打开。目录内同时保存采样 XML、命令日志和工具源码快照。
-已有同名目录时,脚本会报错而不覆盖已有结果。采集时可用 `--output` 在默认目录名后追加 `-{后缀}`,后缀不能为空或包含 `/`:
+已有同名目录时,脚本会报错而不覆盖已有结果。采集时可用 `--label` 为本次测试添加标签,在默认目录名后追加 `-{标签}`,标签不能为空或包含 `/`:
```sh
-python3 -m Scripts.performance --preset quick --output idle
+python3 -m Scripts.performance --preset quick --label idle
```
例如,输出目录为 `Performance/4.1.1(111)-quick-20261024140000-idle/`
@@ -77,7 +78,7 @@ python3 -m Scripts.performance --preset quick --output idle
```sh
python3 -m Scripts.performance \
--preset quick \
- --output idle
+ --label idle
```
再次测试时指定实际生成目录中的基线文件,例如:
diff --git a/Scripts/performance/__main__.py b/Scripts/performance/__main__.py
index ab8e7a0..422d7cf 100644
--- a/Scripts/performance/__main__.py
+++ b/Scripts/performance/__main__.py
@@ -35,7 +35,8 @@ class Arguments(argparse.Namespace):
app: Path
pid: int | None
preset: str
- output: str | None
+ label: str | None
+ output: Path | None
workload: str
baseline: Path | None
cpu_mean_budget: float | None
@@ -50,24 +51,29 @@ def main() -> int:
parser.add_argument("--app", type=Path, default=Path("/Applications/CodexBar.app"))
parser.add_argument("--pid", type=int)
parser.add_argument("--preset", choices=PRESETS, default="standard")
- parser.add_argument("--output", help="Append a suffix to the recording directory name, or set the HTML path with --render")
- parser.add_argument("--workload", default="Natural workload; UI and active tasks uncontrolled")
+ parser.add_argument("--label", help="Label this recording in its directory name")
+ parser.add_argument("--output", type=Path, help="Set the HTML output path with --render")
+ parser.add_argument("--workload", default="default")
parser.add_argument("--baseline", type=Path)
parser.add_argument("--cpu-mean-budget", type=float)
parser.add_argument("--footprint-budget", type=float, help="Physical footprint budget in MiB")
parser.add_argument("--render", type=Path, help="Regenerate HTML from an existing performance.json without profiling")
args = parser.parse_args(namespace=Arguments())
if args.render:
+ if args.label is not None:
+ parser.error("--label is only available when recording")
render_data = cast(Report, json.loads(args.render.read_text()))
- destination = Path(args.output) if args.output is not None else args.render.parent / "performance.html"
+ destination = args.output if args.output is not None else args.render.parent / "performance.html"
write_report(render_data, destination)
print(destination)
return 0
+ if args.output is not None:
+ parser.error("--output requires --render")
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")
- if args.output is not None and (not args.output or "/" in args.output):
- parser.error("--output must be a non-empty directory name suffix without '/' when recording")
+ if args.label is not None and (not args.label or "/" in args.label):
+ parser.error("--label must be non-empty and must not contain '/'")
version_config = ROOT / "Config/Version.xcconfig"
try:
version_text = version_config.read_text()
@@ -82,8 +88,8 @@ def main() -> int:
version = f"{version_match.group(1)}({build_match.group(1)})"
timestamp = dt.datetime.now().strftime("%Y%m%d%H%M%S")
output_name = f"{version}-{args.preset}-{timestamp}"
- if args.output is not None:
- output_name += f"-{args.output}"
+ if args.label is not None:
+ output_name += f"-{args.label}"
output = (ROOT / "Performance" / output_name).resolve()
try:
output.mkdir(parents=True, exist_ok=False)