GitHub - TomerAberbach/profiler-md: ๐Ÿ”ฅ Converts performance profiles to human and LLM friendly Markdown.

GitHub

13 min read Original article โ†—

Markdown flame logo

version CI Sponsor

Converts performance profiles to human and LLM friendly Markdown.

Demo โ€ข Features โ€ข Install โ€ข Usage โ€ข Skill โ€ข Languages and formats

Note

This package is in beta and I'm excited for you to try it! Share suggestions, bug reports, and feature requests by filing an issue.

Demo

Converting and diffing CPU profiles in the terminal

# CPU profile

Took 2.52s over 1,984 samples (1.3ms per sample).

| Category           |     % |    Time | Samples |
| ------------------ | ----: | ------: | ------: |
| Third-party        | 86.0% |   2.17s |   1,707 |
| Garbage collector  |  7.7% | 194.2ms |     153 |
| Standard library   |  4.4% | 111.7ms |      88 |
| Native             |  1.6% |  40.6ms |      32 |
| Regular expression |  0.2% |   3.8ms |       3 |
| Ours               |  0.1% |   1.3ms |       1 |

Paths starting with `./` or `../` are relative to `/private/tmp/nix-shell.K1HXIc/profiler-md-input-generation.EdvtIc/zod/`.

`โ€ฆ` stands for omitted frames.

## Call tree

Call paths to the hottest functions.

```
โ”œโ”€โ”€ 2.28s (90.7%) (anonymous) at ./cpuprofile-run.mjs
โ”‚   โ””โ”€โ”€ 2.28s (90.7%) typeCheckProject at ./tsc-workload.mjs:3:33
โ”‚       โ”œโ”€โ”€ โ€ฆ 1.77s (70.2%) (anonymous) at ./node_modules/typescript/lib/typescript.js:123385:37
โ”‚       โ”‚   โ”œโ”€โ”€ โ€ฆ 1.61s (63.8%) checkSourceFileWorker at ./node_modules/typescript/lib/typescript.js:87270:33
โ”‚       โ”‚   โ”‚   โ””โ”€โ”€ 1.61s (63.8%) 3 more callees, led by (32.8%) checkDeferredNodes at 87179:30
โ”‚       โ”‚   โ””โ”€โ”€ โ€ฆ 146.0ms (5.8%, self 1.1%) bind at ./node_modules/typescript/lib/typescript.js:46600:16
โ”‚       โ”‚       โ””โ”€โ”€ 119.3ms (4.7%) 6 more callees, led by (2.8%) bindWorker at ./node_modules/typescript/lib/typescript.js:46663:22
โ”‚       โ”œโ”€โ”€ 392.2ms (15.6%) createProgram at ./node_modules/typescript/lib/typescript.js:122262:23
โ”‚       โ”‚   โ””โ”€โ”€ 392.2ms (15.6%) 7 more callees, led by (13.0%) forEach at 2365:17
โ”‚       โ””โ”€โ”€ โ€ฆ 100.3ms (4.0%) (anonymous) at node:internal/modules/cjs/loader:1731:37
โ”‚           โ”œโ”€โ”€ 87.6ms (3.5%) wrapSafe at 1671:18
โ”‚           โ””โ”€โ”€ 12.7ms (0.5%) (anonymous) at ./node_modules/typescript/lib/typescript.js:1:1 โ€ฆ
โ”œโ”€โ”€ 194.2ms (7.7%) (garbage collector)
โ””โ”€โ”€ 40.6ms (1.6%) 20 more root frames, led by (0.2%) recursiveTypeRelatedTo at ./node_modules/typescript/lib/typescript.js:67063:36
```

## Hottest functions

### Self time

Functions with the most time spent within the function body, excluding callees.

|    % |    Time | Samples | Function                     | Location                                               |
| ---: | ------: | ------: | ---------------------------- | ------------------------------------------------------ |
| 7.7% | 194.2ms |     153 | `(garbage collector)`        | `<unknown>`                                            |
| 3.5% |  87.6ms |      69 | `wrapSafe`                   | `node:internal/modules/cjs/loader:1671:18`             |
| 2.8% |  69.8ms |      55 | `recursiveTypeRelatedTo`     | `./node_modules/typescript/lib/typescript.js:67063:36` |
| 2.1% |  53.3ms |      42 | `instantiateTypeWorker`      | `./node_modules/typescript/lib/typescript.js:65023:33` |
| 1.5% |  38.1ms |      30 | `checkTypeRelatedTo`         | `./node_modules/typescript/lib/typescript.js:66185:30` |
| 1.3% |  33.0ms |      26 | `isRelatedTo`                | `./node_modules/typescript/lib/typescript.js:66493:25` |
| 1.2% |  29.2ms |      23 | `getObjectTypeInstantiation` | `./node_modules/typescript/lib/typescript.js:64785:38` |
โ€ฆ

The output continues with the hottest functions by total time, the hottest call stacks, and per-line, caller, and callee detail. See the full output, or examples/output/ for heap snapshots and diffs.

Features

  • Polyglot: call stack profile, call graph, heap snapshot, and trace formats across many languages
  • Profile analysis: rates, category breakdowns, and the hottest functions, call stacks, lines, callers, and callees
  • Heap analysis: self and dominator-based retained sizes, retainer paths, and the largest constructors and strings
  • Trace analysis: category and thread breakdowns, the longest spans with their attributes, nesting, and longest instances, the most frequent instants, and gauges such as heap size over time
  • Multi-profile inputs: one all JFR recording becomes CPU, allocation, and lock contention profiles
  • Diffing: ranked regressions and improvements between two profiles, two heap snapshots, or two traces, across formats and profilers
  • Source maps: resolves minified and transpiled locations back to original sources
  • Zero config: auto-detects the format and profiler
  • Configurable: top N, base URLs, categorization, filtering, and diff matching
  • CLI and API: a command line and a fully-typed API with sync and async variants (API docs)
  • Self-documenting: --help <language> and --help <format> explain how to generate and read each format
  • Agent-ready: ships a skill that guides an agent through profiling and optimizing your code

Install

# npm
$ npm i -g profiler-md

# Homebrew
$ brew install tomeraberbach/tap/profiler-md
Shell completions (optional)
# Bash (Linux)
$ profiler-md --completion bash > ~/.local/share/bash-completion/completions/profiler-md

# Bash (macOS/Homebrew)
$ profiler-md --completion bash > $(brew --prefix)/etc/bash_completion.d/profiler-md

# Fish
$ profiler-md --completion fish > ~/.config/fish/completions/profiler-md.fish

# Zsh
$ profiler-md --completion zsh > ~/.zfunc/_profiler-md

# PowerShell
$ profiler-md --completion pwsh >> $PROFILE.CurrentUserCurrentHost

Usage

CLI

# Convert a profile, paged and syntax highlighted
$ profiler-md profile.cpuprofile

# Diff two profiles or two heap snapshots
$ profiler-md base.cpuprofile current.cpuprofile

# Write the Markdown to a file
$ profiler-md profile.pb.gz -o profile.md

# Read a profile from stdin
$ node --cpu-prof app.js && cat *.cpuprofile | profiler-md

# Show how to profile a language
$ profiler-md --help python
All flags
$ profiler-md --help
Converts performance profiles to human and LLM friendly Markdown.

Usage: profiler-md [OPTIONS] [FILE]
       profiler-md [OPTIONS] BASE CURRENT
       profiler-md --help [TOPIC]

Examples:
  # Convert a profile, paged and syntax highlighted
  $ profiler-md profile.cpuprofile

  # Diff two profiles or two heap snapshots
  $ profiler-md base.cpuprofile current.cpuprofile

  # Write the Markdown to a file
  $ profiler-md profile.pb.gz -o profile.md

  # Read a profile from stdin
  $ node --cpu-prof app.js && cat *.cpuprofile | profiler-md

  # Show how to profile a language
  $ profiler-md --help python

  FILE                                Profile to convert (default: stdin)
  BASE                                Base profile to diff
  CURRENT                             Current profile to diff against the base

Output:
  -o, --output FILE                   Output file (default: - for stdout)
  --log-level LEVEL                   Verbosity of diagnostics printed to 
                                      stderr, overriding $PROFILER_MD_LOG 
                                      (default: warn)
  --no-pager                          Disable stdout paging (default: auto)
  --color, --no-color                 Enable or disable ANSI syntax 
                                      highlighting (default: auto)

Input:
  -f, --format FORMAT                 Input profile format (default: auto)
  -r, --origin ORIGIN                 Input profile origin (default: auto)
  --source-maps GLOB                  Source maps (JSON or inline) to apply to 
                                      locations (repeatable)
  --base-url STRING                   Base URL or path to show paths relative 
                                      to, or auto to infer one from the 
                                      program's own code (default: cwd)

Ranking:
  --top-n N                           Entries to show per ranking, including 
                                      category subsections (default: 20)
  --min-category-share FRACTION       Share of the shown entries' self values a 
                                      category needs for its own subsection, 
                                      from 0 to 1 (default: 0.01)

Filtering:
  --category REGEX=CATEGORY           Categorize functions whose name or 
                                      location matches REGEX as CATEGORY, first 
                                      rule winning (repeatable)
  --hide REGEX                        Hide entries whose name or location 
                                      matches REGEX, still counting hidden 
                                      entries in totals (repeatable)
  --show REGEX                        Show only entries whose name or location 
                                      matches REGEX, still counting hidden 
                                      entries in totals (repeatable)
  --hide-category CATEGORY            Hide entries of CATEGORY, still counting 
                                      hidden entries in totals (repeatable)
  --show-category CATEGORY            Show only entries of CATEGORY, still 
                                      counting hidden entries in totals 
                                      (repeatable)

Diffing:
  --match-name REGEX=REPLACEMENT      Rewrite names matching REGEX to 
                                      REPLACEMENT when pairing diffed entries 
                                      (repeatable)
  --match-location REGEX=REPLACEMENT  Rewrite locations (URL, path, or logical 
                                      name) matching REGEX to REPLACEMENT when 
                                      pairing diffed entries (repeatable)

Help:
  -h, --help [TOPIC]                  Show this help message or topic docs
  --version                           Show the version
  --completion SHELL                  Print a completion script for SHELL 
                                      (bash, fish, nu, pwsh, or zsh)

Formats:
  callgrind, collapsed, ghc-eventlog, ghc-json-profile, hprof, jfr,
  jsc-heap-snapshot, memray, perf, pprof, speedscope, systing, trace-event,
  v8-cpu-profile, v8-heap-profile, v8-heap-snapshot, webkit-timeline-recording

Origins:
  async-profiler, bun, chrome, clang, deno, dotnet-trace, eflambe, excimer, ghc,
  go, gperftools, jdk, memray, nix, node, node-pprof, perf, pprof-jl, pprof-rs,
  profile-jl, py-spy, pyinstrument, rbspy, safari, simpleperf, systing, tachyon,
  tsc, unknown, valgrind

Function categories:
  ours, third-party, stdlib, native, unknown, garbage-collector, compiler, jit,
  regexp, kernel, idle

Heap snapshot categories:
  object, array, string, concatenated-string, sliced-string, function, code,
  regexp, number, big-number, symbol, native, object-shape, internal, synthetic,
  unknown

Trace event categories:
  script, parsing, compilation, garbage-collection-pause, garbage-collection,
  style, layout, paint, io, other

Languages:
  c/cpp, csharp/fsharp, elixir/erlang, fortran, go, haskell, java/kotlin/groovy,
  javascript/typescript, julia, nix, php, python, ruby, rust, swift, zig

Docs: https://github.com/TomerAberbach/profiler-md
Bugs: https://github.com/TomerAberbach/profiler-md/issues

API

import { openAsBlob } from 'node:fs'
import { diffProfilesAsync, profileToMdAsync } from 'profiler-md'

// Convert a profile or heap snapshot. The format and origin are auto-detected
console.log(await profileToMdAsync(await openAsBlob(`example.cpuprofile`)))

// Diff two profiles or two heap snapshots
console.log(
  await diffProfilesAsync(
    await openAsBlob(`base.cpuprofile`),
    await openAsBlob(`current.cpuprofile`),
  ),
)

See the API docs for sync variants, explicit formats and origins, and configuration callbacks.

Skill

Use the profile-optimize skill to have an agent profile and optimize your code. The skill runs the profiler-md CLI, so install it first.

Install the skill for any agent with skills:

$ npx skills add TomerAberbach/profiler-md --skill profile-optimize

Or install it natively:

Claude Code
$ claude plugin marketplace add TomerAberbach/profiler-md --sparse .claude-plugin
$ claude plugin install profiler-md@profiler-md

Pass --sparse .claude-plugin so Claude Code checks out only the marketplace file instead of this repository's large example inputs. The plugin installs the skill from the npm package. Invoke it as /profiler-md:profile-optimize.

Codex
$ codex plugin marketplace add TomerAberbach/profiler-md --sparse .claude-plugin

Then open /plugins, select the profiler-md marketplace, and install the profiler-md plugin. Pass --sparse .claude-plugin so Codex checks out only the marketplace file instead of this repository's large example inputs.

Pi
$ pi install npm:profiler-md

Fun fact: the skill has profiled and optimized profiler-md itself!

Languages and formats

Each language lists only the formats its own tools generate. Third-party tools convert others. Click a language for how to profile it, and a format for how to generate and read it.


C C++
Cโ /โ C++

Callgrind ยท perf.data ยท pprof ยท systing ยท Trace Event Format

C# F#
C#โ /โ F#

Speedscope

Elixir Erlang
Elixirโ /โ Erlang

Collapsed stacks

Fortran
Fortran

pprof

Go
Go

pprof

Haskell
Haskell

GHC eventlog ยท GHC JSON profile

Java Kotlin Groovy
Javaโ /โ Kotlinโ /โ Groovy

Collapsed stacks ยท HPROF ยท JFR

JavaScript TypeScript
JavaScriptโ /โ TypeScript

JSC heap snapshot ยท pprof ยท Trace Event Format ยท V8 CPU profile ยท V8 heap profile ยท V8 heap snapshot ยท WebKit timeline recording

Julia
Julia

pprof ยท V8 heap snapshot

Nix
Nix

Collapsed stacks

PHP
PHP

Collapsed stacks ยท Speedscope

Python
Python

Collapsed stacks ยท memray ยท Speedscope ยท systing

Ruby
Ruby

Callgrind ยท Collapsed stacks ยท pprof ยท Speedscope

Rust
Rust

pprof ยท systing

Swift
Swift

pprof

Zig
Zig

perf.data ยท pprof

Examples

Each example links to the Markdown for a base profile, a current profile, and the diff between them.

Browse 138 examples
LanguageProfileFormatMarkdown
C C++
Cโ /โ C++
C ValgrindCallgrindbase ยท current ยท diff
C perf CPUperf.database ยท current ยท diff
C simpleperf CPUperf.database ยท current ยท diff
C++ perf CPUperf.database ยท current ยท diff
C gperftools CPUpprofbase ยท current ยท diff
C gperftools heappprofbase ยท current ยท diff
C++ gperftools CPUpprofbase ยท current ยท diff
C++ gperftools heappprofbase ยท current ยท diff
C systing CPUsystingbase ยท current ยท diff
C ClangTrace Event Formatbase ยท current ยท diff
C++ ClangTrace Event Formatbase ยท current ยท diff
C# F#
C#โ /โ F#
C# dotnet-traceSpeedscopebase ยท current ยท diff
F# dotnet-traceSpeedscopebase ยท current ยท diff
Elixir Erlang
Elixirโ /โ Erlang
Elixir eflambe wallCollapsed stacksbase ยท current ยท diff
Erlang eflambe wallCollapsed stacksbase ยท current ยท diff
Fortran
Fortran
gperftools CPUpprofbase ยท current ยท diff
gperftools heappprofbase ยท current ยท diff
Go
Go
pprof blockpprofbase ยท current ยท diff
pprof CPUpprofbase ยท current ยท diff
pprof CPU (-trimpath)pprofbase ยท current ยท diff
pprof goroutinepprofbase ยท current ยท diff
pprof goroutine leakpprofbase ยท current ยท diff
pprof heappprofbase ยท current ยท diff
pprof heap-allocpprofbase ยท current ยท diff
pprof mutexpprofbase ยท current ยท diff
pprof threadcreatepprofbase ยท current ยท diff
Haskell
Haskell
GHCGHC eventlogbase ยท current ยท diff
GHCGHC JSON profilebase ยท current ยท diff
Java Kotlin Groovy
Javaโ /โ Kotlinโ /โ Groovy
Groovy async-profiler allocCollapsed stacksbase ยท current ยท diff
Groovy async-profiler alloc (dot)Collapsed stacksbase ยท current ยท diff
Groovy async-profiler CPUCollapsed stacksbase ยท current ยท diff
Groovy async-profiler CPU (dot)Collapsed stacksbase ยท current ยท diff
Groovy async-profiler CPU (threads, ann, sig)Collapsed stacksbase ยท current ยท diff
Java async-profiler allocCollapsed stacksbase ยท current ยท diff
Java async-profiler alloc (dot)Collapsed stacksbase ยท current ยท diff
Java async-profiler CPUCollapsed stacksbase ยท current ยท diff
Java async-profiler CPU (dot)Collapsed stacksbase ยท current ยท diff
Java async-profiler CPU (threads, ann, sig)Collapsed stacksbase ยท current ยท diff
Kotlin async-profiler allocCollapsed stacksbase ยท current ยท diff
Kotlin async-profiler alloc (dot)Collapsed stacksbase ยท current ยท diff
Kotlin async-profiler CPUCollapsed stacksbase ยท current ยท diff
Kotlin async-profiler CPU (dot)Collapsed stacksbase ยท current ยท diff
Kotlin async-profiler CPU (threads, ann, sig)Collapsed stacksbase ยท current ยท diff
Java JDKHPROFbase ยท current ยท diff
Groovy async-profiler allJFRbase ยท current ยท diff
Groovy async-profiler allocJFRbase ยท current ยท diff
Groovy async-profiler CPUJFRbase ยท current ยท diff
Groovy async-profiler liveJFRbase ยท current ยท diff
Groovy async-profiler lockJFRbase ยท current ยท diff
Groovy async-profiler nativememJFRbase ยท current ยท diff
Groovy async-profiler wallJFRbase ยท current ยท diff
Groovy JDK allJFRbase ยท current ยท diff
Groovy JDK allocJFRbase ยท current ยท diff
Groovy JDK CPUJFRbase ยท current ยท diff
Groovy JDK liveJFRbase ยท current ยท diff
Groovy JDK lockJFRbase ยท current ยท diff
Java async-profiler allJFRbase ยท current ยท diff
Java async-profiler allocJFRbase ยท current ยท diff
Java async-profiler CPUJFRbase ยท current ยท diff
Java async-profiler liveJFRbase ยท current ยท diff
Java async-profiler lockJFRbase ยท current ยท diff
Java async-profiler nativememJFRbase ยท current ยท diff
Java async-profiler wallJFRbase ยท current ยท diff
Java JDK allJFRbase ยท current ยท diff
Java JDK allocJFRbase ยท current ยท diff
Java JDK CPUJFRbase ยท current ยท diff
Java JDK CPU (stackdepth=64)JFRbase ยท current ยท diff
Java JDK liveJFRbase ยท current ยท diff
Java JDK lockJFRbase ยท current ยท diff
Kotlin async-profiler allJFRbase ยท current ยท diff
Kotlin async-profiler allocJFRbase ยท current ยท diff
Kotlin async-profiler CPUJFRbase ยท current ยท diff
Kotlin async-profiler liveJFRbase ยท current ยท diff
Kotlin async-profiler lockJFRbase ยท current ยท diff
Kotlin async-profiler nativememJFRbase ยท current ยท diff
Kotlin async-profiler wallJFRbase ยท current ยท diff
Kotlin JDK allJFRbase ยท current ยท diff
Kotlin JDK allocJFRbase ยท current ยท diff
Kotlin JDK CPUJFRbase ยท current ยท diff
Kotlin JDK liveJFRbase ยท current ยท diff
Kotlin JDK lockJFRbase ยท current ยท diff
JavaScript TypeScript
JavaScriptโ /โ TypeScript
JavaScript BunJSC heap snapshotbase ยท current ยท diff
JavaScript SafariJSC heap snapshotbase ยท current ยท diff
JavaScript node-pprof CPUpprofbase ยท current ยท diff
JavaScript node-pprof CPU (line numbers)pprofbase ยท current ยท diff
JavaScript node-pprof heappprofbase ยท current ยท diff
JavaScript Node.jsTrace Event Formatbase ยท current ยท diff
TypeScript TypeScript compilerTrace Event Formatbase ยท current ยท diff
JavaScript BunV8 CPU profilebase ยท current ยท diff
JavaScript ChromeV8 CPU profilebase ยท current ยท diff
JavaScript DenoV8 CPU profilebase ยท current ยท diff
JavaScript Node.jsV8 CPU profilebase ยท current ยท diff
JavaScript ChromeV8 heap profilebase ยท current ยท diff
JavaScript Node.jsV8 heap profilebase ยท current ยท diff
JavaScript Node.js all allocationsV8 heap profilebase ยท current ยท diff
JavaScript BunV8 heap snapshotbase ยท current ยท diff
JavaScript ChromeV8 heap snapshotbase ยท current ยท diff
JavaScript Node.jsV8 heap snapshotbase ยท current ยท diff
JavaScript Safari 17WebKit timeline recordingbase ยท current ยท diff
JavaScript Safari 26WebKit timeline recordingbase ยท current ยท diff
Julia
Julia
pprof-jl allocpprofbase ยท current ยท diff
pprof-jl CPUpprofbase ยท current ยท diff
pprof-jl wallpprofbase ยท current ยท diff
ProfileV8 heap snapshotbase ยท current ยท diff
Nix
Nix
NixCollapsed stacksbase ยท current ยท diff
PHP
PHP
Excimer wallCollapsed stacksbase ยท current ยท diff
Excimer wall (max depth 16)Collapsed stacksbase ยท current ยท diff
Excimer wallSpeedscopebase ยท current ยท diff
Excimer wall (max depth 16)Speedscopebase ยท current ยท diff
Python
Python
py-spy CPUCollapsed stacksbase ยท current ยท diff
py-spy functionCollapsed stacksbase ยท current ยท diff
py-spy nativeCollapsed stacksbase ยท current ยท diff
py-spy wallCollapsed stacksbase ยท current ยท diff
tachyon all threadsCollapsed stacksbase ยท current ยท diff
tachyon CPUCollapsed stacksbase ยท current ยท diff
tachyon exceptionCollapsed stacksbase ยท current ยท diff
tachyon GILCollapsed stacksbase ยท current ยท diff
tachyon nativeCollapsed stacksbase ยท current ยท diff
tachyon wallCollapsed stacksbase ยท current ยท diff
memraymemraybase ยท current ยท diff
memray aggregatedmemraybase ยท current ยท diff
memray nativememraybase ยท current ยท diff
memray Python 3.10memraybase ยท current ยท diff
memray v13memraybase ยท current ยท diff
py-spy CPUSpeedscopebase ยท current ยท diff
py-spy functionSpeedscopebase ยท current ยท diff
py-spy nativeSpeedscopebase ยท current ยท diff
pyinstrumentSpeedscopebase ยท current ยท diff
Ruby
Ruby
rbspy CPUCallgrindbase ยท current ยท diff
rbspy CPUCollapsed stacksbase ยท current ยท diff
rbspy CPUpprofbase ยท current ยท diff
rbspy CPUSpeedscopebase ยท current ยท diff
Rust
Rust
pprof-rs CPUpprofbase ยท current ยท diff
Swift
Swift
gperftools CPUpprofbase ยท current ยท diff
gperftools heappprofbase ยท current ยท diff
Zig
Zig
perf CPUperf.database ยท current ยท diff
gperftools CPUpprofbase ยท current ยท diff
gperftools heappprofbase ยท current ยท diff

Contributing

Stars are always welcome!

For bugs and feature requests, create an issue.

License

MIT ยฉ Tomer Aberbach