Skip to content

Commit b3d7b7c

Browse files
authored
perf: add build stage analysis dimension and simplify project name inference (#2559)
1 parent df72947 commit b3d7b7c

3 files changed

Lines changed: 10 additions & 17 deletions

File tree

.github/workflows/pack-perf.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jobs:
7171

7272
- name: Analyze Traces
7373
run: |
74-
python3 agents/tools/analyze_trace.py .trace/trace_antd.json .trace/report_antd.md
74+
TRACE_PROJECT=examples/with-antd python3 agents/tools/analyze_trace.py .trace/trace_antd.json .trace/report_antd.md
7575
# Prepare PR comment content
7676
echo "## 📊 Performance Benchmark Report (with-antd)" > .trace/pr_comment.md
7777
cat .trace/report_antd.md >> .trace/pr_comment.md

agents/tools/analyze_trace.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from collections import defaultdict
1313
from datetime import datetime
1414

15-
def analyze_trace(trace_path, output_path):
15+
def analyze_trace(trace_path, output_path, override_project_name=None):
1616
"""Analyze Chrome Trace and generate performance report following the protocol"""
1717

1818
print(f"📊 Loading trace: {trace_path}")
@@ -21,6 +21,9 @@ def analyze_trace(trace_path, output_path):
2121

2222
events = data if isinstance(data, list) else data.get("traceEvents", [])
2323
print(f"✅ Analyzing {len(events):,} events...")
24+
25+
# Try to infer project name
26+
project_name = override_project_name or os.environ.get("TRACE_PROJECT") or "Unknown Project"
2427

2528
# Initialize metrics
2629
min_ts, max_ts = float('inf'), float('-inf')
@@ -130,18 +133,6 @@ def analyze_trace(trace_path, output_path):
130133
trace_file = os.path.basename(trace_path)
131134
trace_size_gb = os.path.getsize(trace_path) / (1024**3)
132135

133-
# Try to infer project name
134-
project_name = "Unknown Project"
135-
abs_path = os.path.abspath(trace_path)
136-
path_parts = abs_path.split(os.sep)
137-
if "examples" in path_parts:
138-
try:
139-
idx = path_parts.index("examples")
140-
if idx + 1 < len(path_parts):
141-
project_name = f"examples/{path_parts[idx+1]}"
142-
except ValueError:
143-
pass
144-
145136
# Pre-calculate derived metrics
146137
max_thread_work = max(thread_work, 1) # Avoid division by zero
147138
total_tasks_safe = max(total_tasks, 1)
@@ -336,14 +327,15 @@ def analyze_trace(trace_path, output_path):
336327

337328
if __name__ == "__main__":
338329
if len(sys.argv) < 3:
339-
print("Usage: python3 analyze_trace.py <trace_file> <output_report>")
330+
print("Usage: python3 analyze_trace.py <trace_file> <output_report> [project_name]")
340331
sys.exit(1)
341332

342333
trace_file = sys.argv[1]
343334
report_file = sys.argv[2]
335+
override_project_name = sys.argv[3] if len(sys.argv) > 3 else None
344336

345337
if not os.path.exists(trace_file):
346338
print(f"Error: Trace file not found: {trace_file}")
347339
sys.exit(1)
348340

349-
analyze_trace(trace_file, report_file)
341+
analyze_trace(trace_file, report_file, override_project_name)

agents/utoopack-performance-agent.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ Follow this tiered hierarchy. Solve P0 before descending to P1, as high-level sc
9797
---
9898

9999
## 🚀 Step 3: Actionable Diagnostic Workflow
100-
1. **Quantitative Baseline**: Run the summary script `python3 agents/tools/analyze_trace.py <trace_file> <output_report>` to list Top 20 tasks by `count` and `sum(duration)`.
100+
1. **Quantitative Baseline**: Run the summary script with the **`TRACE_PROJECT`** environment variable to identify the build target.
101+
- *Command*: `TRACE_PROJECT=examples/with-antd python3 agents/tools/analyze_trace.py <trace_file> <output_report>`
101102
2. **Qualitative Timeline Scan**: Open the trace in `chrome://tracing` or `edge://tracing`. Look for "Wall-like" structures (Parallelism) vs "Staircase" structures (Serialism).
102103
3. **Causal Attribution**: Identify the `Parent Span` of the top bottlenecks to understand *why* they were invoked.
103104
4. **Final Reporting**: Summarize findings and save the report to `./agents/reports/utoopack_performance_report_YYYYMMDD_HHMMSS.md`. Include specific Tiered signals and recommended actions.

0 commit comments

Comments
 (0)