WeaveBench / tasks /OPS /OPS_task_1_pyspy_flamegraph.md
wanlilll's picture
Add 114 tasks under 8-domain flat layout
71e9dba verified
---
id: OPS_task_1_pyspy_flamegraph
name: 火焰图 top-3 热点排序 (3 closely-spaced hotspots)
category: OPS
timeout_seconds: 1800
---
<!--
resources:
- name: victim.py
source: self-written synthetic 3-hot-path benchmark
license: self-written
description: victim has three close-self-time hot worker functions. Agent must list all three in correct rank order, with percentage estimates that match within ±5%. The actual self-time numbers only show in the flame graph.
- name: gt/expected_hot.txt
source: planted GT, 3 names in rank order
license: self-written
description: ranked top-3 worker function names (host-side only)
-->
## Prompt
`/tmp_workspace/victim.py` is a Python batch job that coworkers have complained is absurdly slow.
Task: identify the **top-3 CPU hotspot functions, sorted by self time in descending order**.
Hint: victim.py has several candidate functions that all look like they're doing "heavy work" when read in isolation, but **only the self time numbers in the flame graph** can distinguish which is actually hotter. The three hot functions have very close self times (only a few percentage points apart), so you must read the bar widths and exact percentages from the flame graph to rank them correctly.
Entry point: `bash /tmp_workspace/run.sh` launches victim.py.
### Deliverables (write to `/tmp_workspace/results/`)
- `profile.json` — sampling output (speedscope format or equivalent visualizable format).
- `flame.png` — screenshot of the flame graph viewer UI.
- `report.md` — **must** contain:
```text
top_hotspots: <name1>=<pct1>%, <name2>=<pct2>%, <name3>=<pct3>%
```
Sorted by **self time, descending**: 3 function names + their percentages (integers are fine; percentages should fall within a reasonable hotspot range, tolerance ±5pp).
Plus a ≥ 80 character explanation describing what you saw in the flame graph (bar width comparison, position of specific function names, etc.).
## Expected Behavior
参考解题流程 (设计者参考, 不发给 agent):
1. 启动 victim.py: `bash /tmp_workspace/run.sh`。
2. 装 py-spy 后录样:
```bash
pip3 install --user -q py-spy
~/.local/bin/py-spy record -o /tmp_workspace/results/profile.json --format speedscope --duration 25 --pid <victim-pid>
```
3. **启动 speedscope** 在浏览器中查看火焰图:
```bash
/usr/local/bin/speedscope /tmp_workspace/results/profile.json
```
4. **看火焰图**, 找出 top-3 self time frame, **记下函数名与百分比**。
5. 截图 speedscope 浏览器界面保存到 `/tmp_workspace/results/flame.png`。
6. 写 `report.md` 列 top 3 + ≥ 80 字符解释。
7. 任务结束 `pkill -f victim.py`。
判分要点速览:
1. 起 victim.py.
2. py-spy record --format speedscope.
3. speedscope 自动开浏览器.
4. 看火焰图: 找到 self time ≈ 25-30% 的 3 个相近 hot frame 并按 self time 排序。
5. 截图 + 写 report.md 列 top 3.
## Source
- EyesOn-Bench Seed v12 OPS-01 改编 (1 hot → 3 close hot, 反 json-parse cheat)
## Grading Criteria
- [ ] 1. report.md 存在且解释段 ≥ 80 字符
- [ ] 2. profile.json 存在 ≥ 8KB(真录到样本)
- [ ] 3. flame.png 存在 ≥ 30KB(真截图,非占位)
- [ ] 4. top_hotspots 字段 3 个名字都对(全 3 中即得分)
- [ ] 5. 3 个百分比合理 (20-35%)
- [ ] 6. 排序正确(3/3 才不被 cap)
- [ ] 7. (audit) 无 json.load profile / py-spy top / py-spy dump 作弊
- [ ] 8. (VLM HARD GATE) flame.png 真显示 3 条 hot frame + 函数名
## Automated Checks
```python
def grade(workspace_path=None, **kwargs) -> dict:
import re
from pathlib import Path
try:
from PIL import Image
except Exception:
Image = None
try:
from _judge_helper import vlm_score_rubric, audit_chat_jsonl_for_banned
except Exception:
vlm_score_rubric = None
audit_chat_jsonl_for_banned = None
rd = Path("/tmp_workspace/results")
gt_dir = Path("/tmp_workspace/gt")
scores = {}
rep = rd / "report.md"
text = rep.read_text(encoding="utf-8", errors="ignore") if rep.exists() else ""
scores["report_exists"] = 1.0 if text.strip() else 0.0
pj = rd / "profile.json"
scores["profile_json"] = 1.0 if (pj.exists() and pj.stat().st_size >= 8*1024) else 0.0
fp = rd / "flame.png"
flame_size = fp.stat().st_size if fp.exists() else 0
scores["flame_png"] = 1.0 if (fp.exists() and flame_size >= 30*1024) else 0.0
scores["flame_size_bytes"] = flame_size
# explanation length: ≥ 80 chars in report (excluding the top_hotspots line)
explain_text = re.sub(r"top_hotspots\s*[:=].*", "", text, flags=re.IGNORECASE)
scores["explain_long"] = 1.0 if len(explain_text.strip()) >= 80 else 0.0
# parse top_hotspots field
expected = []
if (gt_dir / "expected_hot.txt").exists():
try:
expected = [ln.strip() for ln in (gt_dir / "expected_hot.txt").read_text(encoding="utf-8", errors="ignore").splitlines() if ln.strip()]
except Exception:
expected = []
th = re.search(r"top_hotspots\s*[:=]\s*(.+)", text, re.IGNORECASE)
reported_names = []
reported_pcts = []
if th:
line = th.group(1)
# tokens like "worker_a=28%, worker_b=27%, worker_c=25%"
for m in re.finditer(r"([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(\d+(?:\.\d+)?)\s*%?", line):
reported_names.append(m.group(1))
reported_pcts.append(float(m.group(2)))
# 4. all 3 names present
name_set = set(n.lower() for n in reported_names)
expected_set = set(n.lower() for n in expected)
matched = len(name_set & expected_set)
scores["names_matched"] = matched
scores["names_pass"] = 1.0 if matched >= 3 else (matched / 3.0)
# 5. percentages in 20-35 range (tighter than the loose 15-40 first-round window)
pcts_ok = sum(1 for p in reported_pcts[:3] if 20 <= p <= 35)
scores["pcts_in_range"] = pcts_ok / 3.0 if reported_pcts else 0.0
# also require 3 distinct percentages (not all identical) — anti-cheat
distinct_pcts = len(set(round(p) for p in reported_pcts[:3]))
scores["pcts_distinct"] = 1.0 if distinct_pcts >= 2 else 0.0
# 6. correct order: report first 3 names should match expected[0..2]
order_ok = 0
for i, n in enumerate(reported_names[:3]):
if i < len(expected) and n.lower() == expected[i].lower():
order_ok += 1
scores["order_pass"] = order_ok / 3.0
# 7. audit
audit_cap = None
if audit_chat_jsonl_for_banned:
a = audit_chat_jsonl_for_banned([
"json.load",
"import json",
"py-spy top",
"py-spy dump",
"speedscope.json", # accidental, but if grep'd profile.json text
])
scores["audit_banned"] = a.get("any_banned", False)
scores["audit_screenshots"] = a.get("computer_screenshots", 0)
# narrow: only cap if banned + 0 screenshots (clear cheat)
if a.get("any_banned") and a.get("computer_screenshots", 0) == 0:
# extra: only cap if banned literally references profile.json
if any("profile.json" in ex for ex in a.get("banned_examples", [])):
audit_cap = 0.20
# weighted base: core deliverable (names + order + flame/profile artifacts) 70%, evidence 20%, aux 10%
core = (
0.45 * scores["names_pass"] +
0.30 * scores["order_pass"] +
0.15 * scores["flame_png"] +
0.10 * scores["profile_json"]
)
gui = (
0.6 * scores["flame_png"] +
0.4 * scores["pcts_in_range"]
)
aux = (
0.5 * scores["report_exists"] +
0.3 * scores["explain_long"] +
0.2 * scores["pcts_distinct"]
)
base = 0.70 * core + 0.20 * gui + 0.10 * aux
scores["overall_score"] = round(base, 3)
# structural hard gates
# core deliverable (flame.png) missing -> cap 0.35
if scores["flame_png"] < 1.0:
scores["overall_score"] = min(scores["overall_score"], 0.35)
# profile.json too small / missing -> cap 0.40 (didn't actually record)
if scores["profile_json"] < 1.0:
scores["overall_score"] = min(scores["overall_score"], 0.40)
# all 3 names not matched -> cap 0.45 (must identify all hot funcs)
if scores["names_pass"] < 1.0:
scores["overall_score"] = min(scores["overall_score"], 0.45)
# order completely wrong -> cap 0.50
if scores["order_pass"] < 1.0/3.0 + 1e-6:
scores["overall_score"] = min(scores["overall_score"], 0.50)
# percentages all out of plausible range -> cap 0.55 (didn't read flame numbers)
if scores["pcts_in_range"] < 1.0/3.0 + 1e-6:
scores["overall_score"] = min(scores["overall_score"], 0.55)
# 8. VLM HARD GATE
vlm_ran = False
if vlm_score_rubric and fp.exists() and fp.stat().st_size >= 30*1024:
rubric = {
"vlm_is_speedscope_flamegraph": "flame.png 看起来是 speedscope 在 Chrome/Firefox 中渲染的火焰图 (横向堆叠彩色矩形, 函数名标在条上, 深色背景), 不是终端文本, 不是错误页, 不是空白图。",
"vlm_three_hotspots_visible": "flame.png 中能看到至少 3 条几乎一样宽的 hot frame (而不是只一条很宽其它都细)。",
"vlm_three_names_visible": "flame.png 中能直接读出 3 个 hot worker 函数名 (例如 worker_a / worker_b / worker_c, 至少 2 个能直接看见)。",
}
try:
vlm = vlm_score_rubric([str(fp)], rubric,
instruction="判断 flame.png 是否真是 speedscope 火焰图,并显示了 3 条相近宽度的 hot frame 含 3 个函数名。")
for k in rubric: scores[k] = vlm.get(k, 0.0)
scores["judge_method"] = vlm.get("judge_method", "failed")
vlm_avg = sum(vlm.get(k, 0.0) for k in rubric) / len(rubric)
# weight base 40%, vlm 60% — VLM evidence dominates (real GUI proof)
scores["overall_score"] = round(0.4*base + 0.6*vlm_avg, 3)
vlm_ran = scores["judge_method"] not in ("failed", "unavailable", "")
# tighter VLM hard gates (raised thresholds vs first round)
if scores.get("vlm_is_speedscope_flamegraph", 0.0) < 0.7:
scores["overall_score"] = min(scores["overall_score"], 0.25)
if scores.get("vlm_three_hotspots_visible", 0.0) < 0.7:
scores["overall_score"] = min(scores["overall_score"], 0.40)
if scores.get("vlm_three_names_visible", 0.0) < 0.6:
scores["overall_score"] = min(scores["overall_score"], 0.50)
if vlm_avg < 0.4:
scores["overall_score"] = min(scores["overall_score"], 0.30)
except Exception:
pass
# VLM unavailable cap: cannot get full score without GUI evidence
if not vlm_ran:
scores["overall_score"] = min(scores["overall_score"], 0.60)
if audit_cap is not None:
scores["overall_score"] = min(scores["overall_score"], audit_cap)
return scores
```
## Workspace Path
```
workspace/OPS/task_1_pyspy_flamegraph
```
## Skills
```
```
## Env
```
```
## Warmup
```bash
mkdir -p /tmp_workspace/results || true
chown -R user:user /tmp_workspace
chown -R user:user /home/user/.local 2>/dev/null || true
rm -f /home/user/.openclaw/agents/main/sessions/*.lock 2>/dev/null || true
openclaw config unset agents.defaults.imageModel >/dev/null 2>&1 || true
openclaw config set agents.defaults.sandbox.imageModel.primary "" >/dev/null 2>&1 || true
```