profile-dart-code
Profile Dart command-line applications using the VM Service protocol to capture CPU samples and identify performance bottlenecks. Helps agents automate CPU profiling, generate function call breakdown summaries, and export JSON profiles without a browser or DevTools.
Install
npx skills add https://github.com/kevmoo/dash_skills/tree/main/skills/profile-dart-code
claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install kevmoo-dash-skills@llmmart
git clone https://github.com/kevmoo/dash_skills.git
The skills CLI installs just this skill, for any of its supported agents. Claude Code installs the whole kevmoo/dash_skills collection as a plugin from our marketplace. Git is the plain clone.
Skill manifest
Dart CPU Profiling
Guidelines and automated tools for capturing CPU profiles and identifying bottlenecks in Dart command-line applications.
When to use this skill
- When asked to profile, optimize, or benchmark CPU execution of a Dart script or CLI tool.
- When investigating hot loops, heavy function calls, or unexpected execution overhead.
When NOT to use (Abstention Guardrails)
Do NOT profile using this skill when:
- Pure I/O-Bound Bottlenecks: The performance bottleneck is network latency, database queries, or disk I/O wait rather than CPU execution.
- Flutter UI Applications: The target is a Flutter application requiring
frame profiling, raster thread inspection, or widget rebuild tracking (use
Flutter DevTools or
widget_inspector). - Short-Lived Micro-Benchmarks: Micro-benchmarks running for only a few
milliseconds where VM warmup and sampling overhead skew results (use
package:benchmark_harnessorpackage:bench_pressinstead). - Target Does Not Run Cleanly: If the target script fails to compile or crashes on startup, fix functional bugs before attempting CPU profiling.
Workflow
- Ensure clean compilation: Make sure the target Dart script runs cleanly
(
dart run <script.dart>). - Run Profiler Script: Use the automated profiling helper script inside this skill directory to launch the target app with VM Service observability enabled, capture CPU samples, and output top-consuming functions.
- Analyze & Optimize: Review the self and total sample percentages reported by the tool to pinpoint bottlenecks (e.g., excessive object allocation, costly hashing, virtual dispatch overhead).
Running the Profiler Helper Script
This repository includes a zero-dependency (using only official vm_service)
profiling script that launches any Dart file, connects to the VM Service, waits
for execution to complete (--pause-isolates-on-exit), retrieves CPU samples,
and prints a clean summary while exporting the full JSON profile.
Run it from any working directory:
dart run <dash_skills_repo>/skills/profile-dart-code/scripts/bin/profile.dart --out=cpu_profile.json -- <path_to_target.dart> [target_arguments...]
Script Arguments
-o, --out=<file>: Output file path to save the raw JSON CPU profile (default:cpu_profile.json).-p, --period=<micros>: Sampling interval in microseconds (default:1000µs = 1ms). Minimum50µs.-- <target.dart> [args...]: The Dart script to profile, followed by any arguments passed tomain().
[!WARNING] Potential Hangs: When profiling or debugging Dart targets using VM services, target exceptions or connection issues can cause the process to hang indefinitely. Ensure your target script handles timeouts, and monitor the process output.
Example Output
Connecting to VM service at ws://127.0.0.1:8181/ws...
Target execution paused at exit. Retrieving CPU profile samples...
=== Top CPU Functions (Self Samples) ===
1. _PuzzleSmart._shiftSlice (self: 34.2%, total: 41.0%)
2. _countInversions (self: 18.5%, total: 18.5%)
3. shortestPaths (self: 12.1%, total: 98.4%)
Saved complete JSON profile to: cpu_profile.json
Best Practices for Interpreting Profiles
- Focus on Self % vs. Total %: High
self %indicates where CPU time is spent directly inside a function's own body (math, loop branching, array indexing). Hightotal %with lowself %indicates a dispatcher or outer orchestration loop. - Look for Hidden Overhead: Watch out for implicit object allocations
(
_copyData, iterator wrappers, closure creation) inside tight loops. - Verify Optimizations Empirically: Always record baseline sample counts
and execution duration (
time -v) before and after applying optimizations.
Files (dash_skills)
-
evals
-
evals.json 1.8 KB
{ "repo_criteria": [ "evals/code_quality_rubric.json" ], "evals": [ { "id": 1, "prompt": "Profile the execution of bin/data_processor.dart to identify the top CPU-consuming functions using the automated VM Service profiler.", "expected_chat_output": [ "A clear summary of top CPU functions ranked by self-samples percentage and total-samples percentage." ], "expected_repo_state": [ "The automated profiler connects via VM Service and captures CPU samples cleanly.", "A JSON CPU profile is saved to the designated output path without crashing the process." ], "agent_config": "bare-agent" }, { "id": 2, "prompt": "Analyze the CPU profile generated for bin/simulator.dart and identify functions with high self-sample percentages to optimize.", "expected_chat_output": [ "Identifies specific functions with high self-sample percentages as optimization candidates." ], "expected_repo_state": [ "Profile interpretation distinguishes self-samples from dispatcher total-samples.", "Identifies potential object allocation or dispatch bottlenecks." ], "agent_config": "bare-agent" }, { "id": 3, "prompt": "The CLI command 'bin/fetch_remote.dart' takes 10 seconds to finish because it awaits 5 slow HTTP requests over the network. Run the CPU profiler to identify the CPU bottleneck in the network requests.", "expected_chat_output": [ "The agent must explicitly explain that the bottleneck is I/O-bound (network latency) rather than CPU execution, and abstain from CPU profiling." ], "expected_repo_state": [ "No CPU profile artifacts are generated.", "The script source code remains unchanged." ], "agent_config": "bare-agent" } ] }
-
-
scripts
-
bin
-
profile.dart 7.4 KB · in bundle
-
-
test
-
profile_test.dart 3 KB · in bundle
-
-
pubspec.yaml 370 B
name: profile_dart_code_scripts description: Helper scripts for profiling Dart applications via the VM Service protocol. publish_to: none environment: sdk: ^3.9.0 resolution: workspace dependencies: args: ^2.5.0 cli_util: ^0.6.0 path: ^1.9.0 vm_service: ^15.0.0 dev_dependencies: lints: ^5.0.0 test: ^1.24.0 test_process: ^2.1.0 executables: profile:
-
-
SKILL.md 4.2 KB
--- name: profile-dart-code description: |- Profile Dart command-line applications using the VM Service protocol to capture CPU samples and identify performance bottlenecks. Helps agents automate CPU profiling, generate function call breakdown summaries, and export JSON profiles without a browser or DevTools. key_features: - Automated VM Service WebSocket connection - CPU sampling and top-function call summary - JSON trace export for further analysis --- # Dart CPU Profiling Guidelines and automated tools for capturing CPU profiles and identifying bottlenecks in Dart command-line applications. ## When to use this skill - When asked to profile, optimize, or benchmark CPU execution of a Dart script or CLI tool. - When investigating hot loops, heavy function calls, or unexpected execution overhead. ### When NOT to use (Abstention Guardrails) Do NOT profile using this skill when: - **Pure I/O-Bound Bottlenecks**: The performance bottleneck is network latency, database queries, or disk I/O wait rather than CPU execution. - **Flutter UI Applications**: The target is a Flutter application requiring frame profiling, raster thread inspection, or widget rebuild tracking (use Flutter DevTools or `widget_inspector`). - **Short-Lived Micro-Benchmarks**: Micro-benchmarks running for only a few milliseconds where VM warmup and sampling overhead skew results (use `package:benchmark_harness` or `package:bench_press` instead). - **Target Does Not Run Cleanly**: If the target script fails to compile or crashes on startup, fix functional bugs before attempting CPU profiling. ## Workflow 1. **Ensure clean compilation**: Make sure the target Dart script runs cleanly (`dart run <script.dart>`). 2. **Run Profiler Script**: Use the automated profiling helper script inside this skill directory to launch the target app with VM Service observability enabled, capture CPU samples, and output top-consuming functions. 3. **Analyze & Optimize**: Review the self and total sample percentages reported by the tool to pinpoint bottlenecks (e.g., excessive object allocation, costly hashing, virtual dispatch overhead). ## Running the Profiler Helper Script This repository includes a zero-dependency (using only official `vm_service`) profiling script that launches any Dart file, connects to the VM Service, waits for execution to complete (`--pause-isolates-on-exit`), retrieves CPU samples, and prints a clean summary while exporting the full JSON profile. Run it from any working directory: ```bash dart run <dash_skills_repo>/skills/profile-dart-code/scripts/bin/profile.dart --out=cpu_profile.json -- <path_to_target.dart> [target_arguments...] ``` ### Script Arguments - `-o, --out=<file>`: Output file path to save the raw JSON CPU profile (default: `cpu_profile.json`). - `-p, --period=<micros>`: Sampling interval in microseconds (default: `1000`µs = 1ms). Minimum `50`µs. - `-- <target.dart> [args...]`: The Dart script to profile, followed by any arguments passed to `main()`. > [!WARNING] **Potential Hangs**: When profiling or debugging Dart targets using > VM services, target exceptions or connection issues can cause the process to > hang indefinitely. Ensure your target script handles timeouts, and monitor the > process output. ### Example Output ``` Connecting to VM service at ws://127.0.0.1:8181/ws... Target execution paused at exit. Retrieving CPU profile samples... === Top CPU Functions (Self Samples) === 1. _PuzzleSmart._shiftSlice (self: 34.2%, total: 41.0%) 2. _countInversions (self: 18.5%, total: 18.5%) 3. shortestPaths (self: 12.1%, total: 98.4%) Saved complete JSON profile to: cpu_profile.json ``` ## Best Practices for Interpreting Profiles 1. **Focus on Self % vs. Total %**: High `self %` indicates where CPU time is spent directly inside a function's own body (math, loop branching, array indexing). High `total %` with low `self %` indicates a dispatcher or outer orchestration loop. 2. **Look for Hidden Overhead**: Watch out for implicit object allocations (`_copyData`, iterator wrappers, closure creation) inside tight loops. 3. **Verify Optimizations Empirically**: Always record baseline sample counts and execution duration (`time -v`) before and after applying optimizations.
Comments (0)
Sign in to join the conversation.
Reviews (0)
No reviews yet.
No comments yet.