AgentSkillsCN

tracing-execution-counts

在函数或语句级别统计精确的执行频率(而非耗时)。通过对比解释执行与编译执行的比例,您可以验证函数的编译效率(编译占比超过 95%),深入理解控制流模式,并有效验证算法复杂度。相较于基于 CPU 采样器的性能剖析,该工具侧重于频率而非持续时间,因而更具针对性。

SKILL.md
--- frontmatter
name: tracing-execution-counts
description: Counts exact execution frequencies (not time) at function/statement level. Shows interpreted vs compiled execution split. Use to verify functions compile (>95% compiled), understand control flow patterns, and validate algorithmic complexity. Complements profiling-with-cpu-sampler by showing frequency rather than duration.

Tracing Execution Counts

Counts exact execution frequencies (NOT time) at function and statement level. Complements CPU Sampler by showing HOW OFTEN code runs rather than how much time it takes.

When to Use This Skill

  • Verify functions are compiling (aim for >95% compiled executions)
  • Understand control flow patterns
  • Validate algorithmic complexity (O(n) vs O(n²))
  • Quantify how often code paths execute

Quick Start

bash
# Basic execution count tracing
<launcher> --cputracer <program>

# With tier breakdown (RECOMMENDED)
<launcher> --cputracer --cputracer.TraceTiers=true <program>

# Per-statement granularity
<launcher> --cputracer --cputracer.TraceStatements=true <program>

⚠️ REQUIRED: Fermi Verification (Every Tool Invocation)

Before running:

  • Pre-calculate: Expected call counts (based on algorithm complexity, e.g., O(n²) for nested loops)
  • Smoke test: <launcher> --cputracer -c 'var x = 0; for (var i = 0; i < 10; i = i + 1) { x = x + 1; }' → Verify counts

After running:

  • Validate: Counts within 1 OOM of estimate? YES / NO
  • If NO: STOP - Either algorithm issue or wrong estimate (recalculate)
  • Save output: tool-outputs/cpu-tracer-[benchmark].txt

Gate: All boxes checked? → Proceed to analysis

Key Options

OptionDescriptionRecommended
--cputracer.TraceTiers=trueShow interpreted vs compiledAlways use
--cputracer.TraceStatements=trueStatement-level detailWhen needed
--cputracer.FilterRootName=<name>Filter by functionFocus analysis
--cputracer.Output=jsonJSON outputFor parsing
--cputracer.OutputFile=<file>Save to fileFor analysis

Understanding Output

Sample Output with Tiers

code
Tracing Histogram. Counted 1234567 executions.

Name          || Count       || Interpreted | Compiled
queens        || 500000 40%  || 2.1%        | 97.9%      ✅
hasConflict   || 750000 60%  || 1.8%        | 98.2%      ✅

Interpretation

Compiled %StatusAction
>95%✅ GoodCode is well-optimized
80-95%⚠️ CheckMay have warmup or minor issues
<80%❌ ProblemCompilation failures or deoptimization

Key Insights

Frequency vs Time

  • CPU Sampler: Shows WHERE time is spent
  • CPU Tracer: Shows HOW OFTEN code runs

A function called 1M times at 1µs each = 1 second total. A function called 100 times at 10ms each = 1 second total.

Same time, very different optimization strategies!

Algorithmic Complexity

code
Expected for queens(N=8):
- hasConflict called ~92 times per queen placement
- Total calls = O(N!)

If counts much higher → algorithm issue
If counts much lower → early termination bug

Integration with Other Skills

FindingNext Skill
Low compiled %tracing-compilation-events
Unexpected countsReview algorithm
Hot functionsprofiling-with-cpu-sampler for time

Related Skills

  • profiling-with-cpu-sampler - Time-based profiling
  • tracing-compilation-events - Why compilation fails
  • detecting-performance-warnings - Optimization barriers

Reference

bash
<launcher> --help:cputracer