From 3aa5cc1eb5f5f532b70b63f86bf1ce8c50a9ad20 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Wed, 21 Jan 2026 18:19:47 +0100 Subject: [PATCH] Add pprof-to-md integration for LLM-friendly markdown analysis Integrates pprof-to-md to generate markdown analysis files alongside existing HTML flamegraphs and pb files, making profile data more accessible to LLMs and automated analysis tools. Changes: - Added pprof-to-md dependency and bumped Node.js requirement to >=22.6.0 - Implemented generateMarkdown() function in lib/index.js - Extended preload.js to generate markdown files automatically - Added --md-format CLI flag supporting summary/detailed/adaptive modes - Added comprehensive test coverage (8 new tests across unit/integration) - Updated documentation with markdown generation examples and usage The markdown format provides structured, readable profile analysis that can be easily consumed by LLMs, while maintaining full backward compatibility with existing HTML and pb output formats. --- README.md | 50 +++++++++++++++------ bin/flame.js | 36 +++++++++++++-- lib/index.js | 24 +++++++++- package.json | 3 +- preload.js | 42 +++++++++++++++++ test/cli.test.js | 82 ++++++++++++++++++++++++++++++++- test/integration.test.js | 31 +++++++++++++ test/lib.test.js | 97 +++++++++++++++++++++++++++++++++++++++- 8 files changed, 344 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 035d95d..6776240 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ - **Dual Profiling**: Captures both CPU and heap profiles concurrently for comprehensive performance insights - **Auto-Start Profiling**: Profiling starts immediately when using `flame run` (default behavior) - **Automatic Flamegraph Generation**: Interactive HTML flamegraphs are created automatically for both CPU and heap profiles on exit +- **LLM-Friendly Markdown Analysis**: Generates markdown reports with hotspot analysis, ideal for AI-assisted performance debugging - **Sourcemap Support**: Automatically translates transpiled code locations back to original source files (TypeScript, bundled JavaScript, etc.) - **Clear File Path Display**: Shows exact paths and browser URLs for generated files - **Manual Control**: Optional manual mode with signal-based control using `SIGUSR2` @@ -34,10 +35,11 @@ flame run server.js # 🔥 Heap profile written to: heap-profile-2025-08-27T12-00-00-000Z.pb # 🔥 Generating CPU flamegraph... # 🔥 CPU flamegraph generated: cpu-profile-2025-08-27T12-00-00-000Z.html +# 🔥 CPU markdown generated: cpu-profile-2025-08-27T12-00-00-000Z.md # 🔥 Generating heap flamegraph... # 🔥 Heap flamegraph generated: heap-profile-2025-08-27T12-00-00-000Z.html +# 🔥 Heap markdown generated: heap-profile-2025-08-27T12-00-00-000Z.md # 🔥 Open file:///path/to/cpu-profile-2025-08-27T12-00-00-000Z.html in your browser to view the CPU flamegraph -# 🔥 Open file:///path/to/heap-profile-2025-08-27T12-00-00-000Z.html in your browser to view the heap flamegraph ``` ### Manual Profiling Mode @@ -53,14 +55,17 @@ kill -USR2 flame toggle ``` -### Generate Flamegraph +### Generate Flamegraph and Markdown ```bash -# Generate HTML flamegraph from pprof file +# Generate HTML flamegraph and markdown from pprof file flame generate cpu-profile-2024-01-01T12-00-00-000Z.pb # Specify custom output file flame generate -o my-flamegraph.html profile.pb.gz + +# Use detailed markdown format for comprehensive analysis +flame generate --md-format=detailed profile.pb ``` ## CLI Usage @@ -70,7 +75,7 @@ flame [options] Commands: run