Claude Skills Guide

Flamegraphs are an essential tool for understanding application performance, showing how CPU time or memory is distributed across function calls. When combined with Claude Code, you can automate flamegraph generation, analyze results more efficiently, and integrate profiling into your development workflow. This guide covers practical approaches to using Claude Code for flamegraph visualization, from setup to interpretation.

Understanding Flamegraphs and Their Role in Performance Analysis

A flamegraph represents a stack trace where each function call appears as a horizontal bar. The width of each bar indicates how much time or memory that function consumed. The vertical axis shows the call hierarchy, with the bottom representing the entry point and the top showing leaf functions. This visualization makes it easy to spot which code paths are hot—consuming the most resources.

Flamegraphs help you answer critical performance questions: Which functions dominate execution time? Where are the bottlenecks? Are there unexpected allocations in frequently called code? Unlike traditional profiling outputs, flamegraphs let you see the full context of your call stack at a glance.

Most flamegraph tools work with sampling profilers. You collect profile data over a period, then transform it into the flamegraph format. Popular tools include perf on Linux, ` Instruments on macOS, and py-spy` for Python applications.

Setting Up Flamegraph Generation with Claude Code

Claude Code can help you set up automated profiling pipelines. The key is integrating data collection with your existing development workflow. Here’s a practical setup for a Node.js application:

First, install the necessary profiling tools:

# Install py-spy for Python profiling
pip install py-spy

# Install flamegraph tool
pip install flamegraph

# For Node.js applications
npm install --save-dev 0x

Create a Claude Code skill to automate the profiling workflow. This skill should handle starting your application with profiling enabled, collecting the data, and generating the flamegraph:

// Save as .claude/flamegraph-profiler.md
# Flamegraph Profiler Skill

This skill automates flamegraph generation for Node.js and Python applications.

## Usage

Generate a flamegraph for your application:
- Language: node|python
- Duration: profiling duration in seconds
- Output: output file path

## Workflow

1. Start the application with profiling enabled
2. Run representative workload
3. Collect and transform profile data
4. Generate interactive flamegraph SVG

The skill then executes the appropriate profiler based on your language choice. For Node.js, use the 0x package which generates flamegraphs automatically:

# Generate flamegraph for Node.js application
0x --output-dir ./flamegraphs node server.js

For Python applications, use py-spy with flamegraph:

# Profile Python application and generate flamegraph
py-spy record -o flamegraph.svg -- python app.py

Automating Flamegraph Collection in CI/CD

Integrating flamegraph generation into your CI pipeline helps catch performance regressions before they reach production. Create a workflow that runs profiling on key code paths and compares results against baselines.

Here’s a practical GitHub Actions workflow:

name: Performance Flamegraph
on: [pull_request]

jobs:
  profile:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Setup profiling tools
        run: |
          pip install py-spy flamegraph
      - name: Run baseline profile
        run: |
          py-spy record -o baseline.svg -- python app.py
      - name: Run new code profile
        run: |
          py-spy record -o current.svg -- python app_new.py
      - name: Compare flamegraphs
        run: |
          # Automated comparison of key functions
          python compare_flamegraphs.py baseline.svg current.svg

This workflow runs on every pull request, comparing flamegraphs between the baseline and new code. You can configure thresholds to fail the build if certain functions exceed time allocations.

Interpreting Flamegraphs with Claude Code

Once you have a flamegraph, the challenge is interpretation. Claude Code can help analyze the SVG and explain what you’re seeing. Describe your flamegraph and ask for insights:

“Analyze this flamegraph and identify the top five most expensive functions. Explain what each does and suggest potential optimizations.”

Claude Code can help you understand complex flamegraphs by:

For JavaScript applications, pay attention to functions marked with idle or GC—these indicate time spent in garbage collection or waiting. Reducing allocations in hot paths often provides significant performance gains.

Practical Example: Optimizing a Node.js API Server

Consider a typical scenario: your API server is experiencing high latency. Here’s how to use Claude Code with flamegraphs to identify the problem:

First, generate a flamegraph during a load test:

# Run load test while profiling
0x --output-dir ./profile node server.js &
# Run load test
hey -c 50 -n 10000 http://localhost:3000/api

Open the generated flamegraph and describe it to Claude Code. A typical analysis reveals patterns like:

  1. JSON serialization bottlenecks — large objects being serialized repeatedly
  2. Database query overhead — N+1 query patterns in ORM code
  3. Unnecessary computation — redundant calculations in request handlers

For example, if your flamegraph shows a wide bar for JSON.stringify at the top of a hot path, you might optimize by:

Claude Code can suggest specific optimizations based on the patterns in your flamegraph, helping you prioritize changes that have the biggest impact.

Integrating Flamegraphs into Daily Development

Make flamegraph analysis part of your regular workflow rather than a reactive process. Here are actionable steps:

Conclusion

Flamegraph visualization combined with Claude Code creates a powerful workflow for performance optimization. By automating profile collection, integrating with CI/CD, and using Claude Code for analysis, you can systematically identify and fix performance bottlenecks. Start by setting up basic profiling for your application, then gradually integrate these practices into your development process. The insights you gain will directly translate to faster applications and better user experiences.

Built by theluckystrike — More at zovo.one