Skip to content

Commit 96293e1

Browse files
committed
Add token and cost charts to launch readiness
1 parent e255166 commit 96293e1

6 files changed

Lines changed: 623 additions & 1 deletion

File tree

experiment/locality-mcp-comparison/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,22 @@ Important artifacts:
320320
- `scenarios/<scenario>/locality.folded` and `scenarios/<scenario>/notion-mcp.folded` - FlameGraph-compatible folded stacks generated from the same timing spans.
321321
- `scenarios/<scenario>/locality.snakeviz.prof` and `scenarios/<scenario>/notion-mcp.snakeviz.prof` - SnakeViz-compatible synthetic pstats profiles.
322322
- `scenarios/<scenario>/locality.snakeviz.stats.md` and `scenarios/<scenario>/notion-mcp.snakeviz.stats.md` - text summary of the SnakeViz profile frames.
323+
- `token-usage/by-trial-scenario/*.svg` - stacked token-usage charts with one
324+
Locality bar and one MCP bar for each trial/scenario pair.
325+
- `token-usage/average.svg` - stacked token-usage chart averaged over paired
326+
scenarios and trials.
327+
- `token-usage/cost/by-trial-scenario/*.svg` - stacked cost charts using the
328+
same token buckets and one Locality/MCP bar pair per trial/scenario.
329+
- `token-usage/cost/average.svg` - stacked cost chart averaged over paired
330+
scenarios and trials.
331+
- `token-usage/token-usage.tsv`, `token-usage/cost-usage.tsv`, and
332+
`token-usage/token-usage.json` - chart data, cost data, pricing, and manifest.
333+
334+
Cost charts default to the `gpt-5.6-luna` Standard short-context rates used by
335+
the benchmark harness. Override them for Azure/internal billing with
336+
`CODEX_COST_INPUT_USD_PER_1M`, `CODEX_COST_CACHED_INPUT_USD_PER_1M`,
337+
`CODEX_COST_CACHE_WRITE_INPUT_USD_PER_1M`, `CODEX_COST_OUTPUT_USD_PER_1M`, and
338+
`CODEX_COST_REASONING_OUTPUT_USD_PER_1M`.
323339
- `locality-traces/*.jsonl` - raw Locality command and pull/hydration spans.
324340
- `locality-traces/*-summary.json` - top Locality spans by duration.
325341
- `locality-traces/*-spans.tsv` - tabular Locality span data.

experiment/locality-mcp-comparison/run-agent-comparison.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,9 @@ run_launch_strategy "$LOCALITY_SANDBOX" "locality" "$LOCALITY_REMOTE_OUT_DIR" "$
384384
run_launch_strategy "$MCP_SANDBOX" "notion-mcp" "$MCP_REMOTE_OUT_DIR" "$@"
385385
sync_artifacts "$LOCALITY_SANDBOX" "locality" "$LOCALITY_REMOTE_OUT_DIR"
386386
sync_artifacts "$MCP_SANDBOX" "notion-mcp" "$MCP_REMOTE_OUT_DIR"
387+
if [ "$SYNC_ARTIFACTS" = "1" ]; then
388+
python3 "$SCRIPT_DIR/scripts/token-usage-charts.py" "$LOCAL_OUT_DIR/artifacts" "$LOCAL_OUT_DIR/token-usage" >/dev/null
389+
fi
387390

388391
cat > "$LOCAL_OUT_DIR/artifacts.tsv" <<EOF
389392
strategy sandbox remote_out_dir local_stdout local_stderr local_artifact_dir
@@ -396,4 +399,5 @@ echo "Locality artifacts: $LOCALITY_SANDBOX:$LOCALITY_REMOTE_OUT_DIR"
396399
echo "MCP artifacts: $MCP_SANDBOX:$MCP_REMOTE_OUT_DIR"
397400
if [ "$SYNC_ARTIFACTS" = "1" ]; then
398401
echo "Local copies: $LOCAL_OUT_DIR/artifacts/locality and $LOCAL_OUT_DIR/artifacts/notion-mcp"
402+
echo "Token usage charts: $LOCAL_OUT_DIR/token-usage"
399403
fi

experiment/locality-mcp-comparison/run-launch-readiness-benchmark.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,3 +1675,6 @@ summary = {
16751675
Path(summary_path).write_text(json.dumps(summary, indent=2) + "\n")
16761676
print(json.dumps(summary, indent=2))
16771677
PY
1678+
1679+
python3 "$SCRIPT_DIR/scripts/token-usage-charts.py" "$OUT_DIR" "$OUT_DIR/token-usage" >/dev/null
1680+
echo "Token usage charts: $OUT_DIR/token-usage"

experiment/locality-mcp-comparison/scripts/summarize-runs.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,40 @@
11
#!/usr/bin/env python3
22
import json
3+
import subprocess
34
import statistics
45
import sys
56
from pathlib import Path
67

78
root = Path(sys.argv[1]) if len(sys.argv) > 1 else Path("experiment/runs")
89
summaries = sorted(root.glob("**/summary.json"))
10+
STRATEGY_DIRS = {"locality", "notion-mcp"}
11+
12+
13+
def run_id_for_summary(path):
14+
parent = path.parent
15+
try:
16+
rel_parts = parent.relative_to(root).parts
17+
except ValueError:
18+
rel_parts = parent.parts
19+
20+
if not rel_parts:
21+
return root.name
22+
if len(rel_parts) >= 2 and rel_parts[-2] == "artifacts" and rel_parts[-1] in STRATEGY_DIRS:
23+
trial_parts = rel_parts[:-2]
24+
return "/".join(trial_parts) if trial_parts else root.parent.name
25+
if len(rel_parts) >= 1 and rel_parts[-1] in STRATEGY_DIRS:
26+
trial_parts = rel_parts[:-1]
27+
return "/".join(trial_parts) if trial_parts else root.name
28+
return "/".join(rel_parts)
29+
30+
931
rows = []
1032
for path in summaries:
1133
data = json.loads(path.read_text())
1234
metrics = data.get("metrics", [])
1335
if not metrics:
1436
continue
15-
run_id = str(path.parent.relative_to(root))
37+
run_id = run_id_for_summary(path)
1638
for metric in metrics:
1739
rows.append(
1840
{
@@ -48,3 +70,12 @@
4870
out = root / "repeated-summary.md"
4971
out.write_text("\n".join(lines) + "\n")
5072
print(out)
73+
74+
chart_script = Path(__file__).with_name("token-usage-charts.py")
75+
if rows and chart_script.exists():
76+
subprocess.run(
77+
[sys.executable, str(chart_script), str(root), str(root / "token-usage")],
78+
check=True,
79+
stdout=subprocess.DEVNULL,
80+
)
81+
print(root / "token-usage")

0 commit comments

Comments
 (0)