{"slug":"profile-dart-code","title":"profile-dart-code","summary":"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.","platform":"Claude","tags":[],"authorName":"LLM Mart","authorSlug":"llm-mart","score":0,"source":"github","price":null,"verified":false,"createdAt":"2026-09-14T18:30:25.053539Z","repo":{"url":"https://github.com/kevmoo/dash_skills","stars":146,"forks":16,"license":"Apache-2.0","updatedAt":"2026-09-24T00:03:49Z"},"bodyHtml":"<hr>\n<p>name: profile-dart-code\ndescription: |-\nProfile Dart command-line applications using the VM Service protocol to\ncapture CPU samples and identify performance bottlenecks. Helps agents\nautomate CPU profiling, generate function call breakdown summaries, and\nexport JSON profiles without a browser or DevTools.\nkey_features:</p>\n<ul>\n<li>Automated VM Service WebSocket connection</li>\n<li>CPU sampling and top-function call summary</li>\n<li>JSON trace export for further analysis</li>\n</ul>\n<hr>\n<h1>Dart CPU Profiling</h1>\n<p>Guidelines and automated tools for capturing CPU profiles and identifying\nbottlenecks in Dart command-line applications.</p>\n<h2>When to use this skill</h2>\n<ul>\n<li>When asked to profile, optimize, or benchmark CPU execution of a Dart script\nor CLI tool.</li>\n<li>When investigating hot loops, heavy function calls, or unexpected execution\noverhead.</li>\n</ul>\n<h3>When NOT to use (Abstention Guardrails)</h3>\n<p>Do NOT profile using this skill when:</p>\n<ul>\n<li><strong>Pure I/O-Bound Bottlenecks</strong>: The performance bottleneck is network latency,\ndatabase queries, or disk I/O wait rather than CPU execution.</li>\n<li><strong>Flutter UI Applications</strong>: The target is a Flutter application requiring\nframe profiling, raster thread inspection, or widget rebuild tracking (use\nFlutter DevTools or <code>widget_inspector</code>).</li>\n<li><strong>Short-Lived Micro-Benchmarks</strong>: Micro-benchmarks running for only a few\nmilliseconds where VM warmup and sampling overhead skew results (use\n<code>package:benchmark_harness</code> or <code>package:bench_press</code> instead).</li>\n<li><strong>Target Does Not Run Cleanly</strong>: If the target script fails to compile or\ncrashes on startup, fix functional bugs before attempting CPU profiling.</li>\n</ul>\n<h2>Workflow</h2>\n<ol>\n<li><strong>Ensure clean compilation</strong>: Make sure the target Dart script runs cleanly\n(<code>dart run &lt;script.dart&gt;</code>).</li>\n<li><strong>Run Profiler Script</strong>: Use the automated profiling helper script inside\nthis skill directory to launch the target app with VM Service observability\nenabled, capture CPU samples, and output top-consuming functions.</li>\n<li><strong>Analyze &amp; Optimize</strong>: Review the self and total sample percentages reported\nby the tool to pinpoint bottlenecks (e.g., excessive object allocation,\ncostly hashing, virtual dispatch overhead).</li>\n</ol>\n<h2>Running the Profiler Helper Script</h2>\n<p>This repository includes a zero-dependency (using only official <code>vm_service</code>)\nprofiling script that launches any Dart file, connects to the VM Service, waits\nfor execution to complete (<code>--pause-isolates-on-exit</code>), retrieves CPU samples,\nand prints a clean summary while exporting the full JSON profile.</p>\n<p>Run it from any working directory:</p>\n<pre><code>dart run &lt;dash_skills_repo&gt;/skills/profile-dart-code/scripts/bin/profile.dart --out=cpu_profile.json -- &lt;path_to_target.dart&gt; [target_arguments...]\n</code></pre>\n<h3>Script Arguments</h3>\n<ul>\n<li><code>-o, --out=&lt;file&gt;</code>: Output file path to save the raw JSON CPU profile\n(default: <code>cpu_profile.json</code>).</li>\n<li><code>-p, --period=&lt;micros&gt;</code>: Sampling interval in microseconds (default: <code>1000</code>µs\n= 1ms). Minimum <code>50</code>µs.</li>\n<li><code>-- &lt;target.dart&gt; [args...]</code>: The Dart script to profile, followed by any\narguments passed to <code>main()</code>.</li>\n</ul>\n<blockquote>\n<p>[!WARNING] <strong>Potential Hangs</strong>: When profiling or debugging Dart targets using\nVM services, target exceptions or connection issues can cause the process to\nhang indefinitely. Ensure your target script handles timeouts, and monitor the\nprocess output.</p>\n</blockquote>\n<h3>Example Output</h3>\n<pre><code>Connecting to VM service at ws://127.0.0.1:8181/ws...\nTarget execution paused at exit. Retrieving CPU profile samples...\n\n=== Top CPU Functions (Self Samples) ===\n 1. _PuzzleSmart._shiftSlice (self: 34.2%, total: 41.0%)\n 2. _countInversions (self: 18.5%, total: 18.5%)\n 3. shortestPaths (self: 12.1%, total: 98.4%)\n\nSaved complete JSON profile to: cpu_profile.json\n</code></pre>\n<h2>Best Practices for Interpreting Profiles</h2>\n<ol>\n<li><strong>Focus on Self % vs. Total %</strong>: High <code>self %</code> indicates where CPU time is\nspent directly inside a function's own body (math, loop branching, array\nindexing). High <code>total %</code> with low <code>self %</code> indicates a dispatcher or outer\norchestration loop.</li>\n<li><strong>Look for Hidden Overhead</strong>: Watch out for implicit object allocations\n(<code>_copyData</code>, iterator wrappers, closure creation) inside tight loops.</li>\n<li><strong>Verify Optimizations Empirically</strong>: Always record baseline sample counts\nand execution duration (<code>time -v</code>) before and after applying optimizations.</li>\n</ol>\n","files":[{"path":"evals/evals.json","sizeBytes":1860,"isText":true},{"path":"scripts/bin/profile.dart","sizeBytes":7628,"isText":false},{"path":"scripts/pubspec.yaml","sizeBytes":370,"isText":true},{"path":"scripts/test/profile_test.dart","sizeBytes":3117,"isText":false},{"path":"SKILL.md","sizeBytes":4317,"isText":true}],"reviewScore":null,"reviewSummary":null,"trust":{"provenance":"trusted-source-unreviewed","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow.","bodySource":null},"bodyLocked":false,"purchaseUrl":null,"sourceUrl":null,"report":{"provenance":"trusted-source-unreviewed","screen":{"ran":true,"outcome":"clean","suspicious":0,"notes":0,"hiddenCharacters":false},"virusScan":{"engine":"clamav","status":"clean","scannedAt":"2026-09-14T18:30:43.438558Z","sha256":"2FC71F9091AF72C55DD7CAF77626BD35804FE4BE6D4F524BADD855A097242104","sizeBytes":6958},"review":null,"source":{"repositoryUrl":"https://github.com/kevmoo/dash_skills","path":"skills/profile-dart-code","license":"Apache-2.0","commit":"0b6371c26516df82443ee5491771befa70d60f0f","subtreeSha":"710DF5C1DDF2A795EBF5F44F2D8CBB36E3097898A59DAE8D08D85A64CAC93B63","lastSyncedAt":"2026-09-26T23:12:20.969684Z"},"reviewedAt":"2026-09-14T18:31:12.653952Z","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow."},"install":[{"target":"skills-cli","command":"npx skills add https://github.com/kevmoo/dash_skills/tree/main/skills/profile-dart-code"},{"target":"claude-code","command":"claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install kevmoo-dash-skills@llmmart"},{"target":"git","command":"git clone https://github.com/kevmoo/dash_skills.git"}]}