From 434a3b45556363eab94435638c24bdb89a65e33a Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Mon, 25 Aug 2025 16:49:25 +0200 Subject: [PATCH 01/41] feat: implement @platformatic/flame package with CPU profiling and flamegraph visualization - Add CLI interface with run, generate, and toggle commands for CPU profiling - Implement preload script for instrumenting Node.js applications - Integrate with @platformatic/react-pprof for flamegraph generation - Include comprehensive test suite covering CLI, library, and preload functionality - Add load testing examples with autocannon for performance validation - Configure ESLint with neostandard for code quality - Support Node.js >=18.0.0 with @datadog/pprof integration This package provides a complete solution for CPU profiling Node.js applications with easy-to-use CLI tools and programmatic API for flamegraph visualization. --- README.md | 176 +++++++++++++++++++++++++++++++++- bin/flame.js | 180 +++++++++++++++++++++++++++++++++++ eslint.config.js | 3 + examples/load-test-server.js | 40 ++++++++ examples/run-load-test.js | 99 +++++++++++++++++++ lib/index.js | 102 ++++++++++++++++++++ package.json | 40 ++++++++ preload.js | 36 +++++++ test/cli.test.js | 135 ++++++++++++++++++++++++++ test/fixtures/test-script.js | 17 ++++ test/integration.test.js | 154 ++++++++++++++++++++++++++++++ test/lib.test.js | 80 ++++++++++++++++ test/preload.test.js | 167 ++++++++++++++++++++++++++++++++ 13 files changed, 1227 insertions(+), 2 deletions(-) create mode 100644 bin/flame.js create mode 100644 eslint.config.js create mode 100644 examples/load-test-server.js create mode 100644 examples/run-load-test.js create mode 100644 lib/index.js create mode 100644 package.json create mode 100644 preload.js create mode 100644 test/cli.test.js create mode 100644 test/fixtures/test-script.js create mode 100644 test/integration.test.js create mode 100644 test/lib.test.js create mode 100644 test/preload.test.js diff --git a/README.md b/README.md index 71018ef..e7660d5 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,174 @@ -# flame -Utility to generate flamegraphs +# @platformatic/flame + +๐Ÿ”ฅ CPU profiling and flamegraph visualization tool built on top of [@platformatic/react-pprof](https://github.com/platformatic/react-pprof). + +## Features + +- **Easy Profiling**: Instrument any Node.js application with a simple preload script +- **Signal-based Control**: Start/stop profiling using `SIGUSR2` signals +- **Flamegraph Generation**: Generate interactive HTML flamegraphs from pprof files +- **CLI Interface**: Command-line tool for profiling and visualization +- **Zero Config**: Works out of the box with sensible defaults + +## Installation + +```bash +npm install -g @platformatic/flame +``` + +## Quick Start + +### Profile a Node.js Script + +```bash +# Start profiling your application +flame run server.js + +# In another terminal, toggle profiling on/off +kill -USR2 + +# Or use the built-in toggle command +flame toggle +``` + +### Generate Flamegraph + +```bash +# Generate HTML flamegraph 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 +``` + +## CLI Usage + +```bash +flame [options] + +Commands: + run