diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..7941c46 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,57 @@ +name: CI + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + ci: + runs-on: ${{ matrix.os }} + timeout-minutes: 10 + + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest] + node-version: ["20.x", "22.x", "24.x"] + include: + - os: ubuntu-latest + node-version: "20.x" + lint: true + build: true + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + + - name: Install dependencies + run: npm install + + - name: Run tests + run: npm test + + - name: Run linting + if: matrix.lint + run: npm run lint + + - name: Build and package + if: matrix.build + run: | + npm pack --dry-run + echo "Package size:" + npm pack --silent | xargs ls -lh + + - name: Test CLI installation + if: matrix.build + run: | + npm pack + npm install -g *.tgz + flame --help + diff --git a/.gitignore b/.gitignore index 9a5aced..478d6ff 100644 --- a/.gitignore +++ b/.gitignore @@ -137,3 +137,7 @@ dist # Vite logs files vite.config.js.timestamp-* vite.config.ts.timestamp-* + +# Generated profile files from flame profiling +cpu-profile-*.* +**/*.csv diff --git a/README.md b/README.md index 71018ef..f9f1a64 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,242 @@ -# 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 + +- **Auto-Start Profiling**: CPU profiling starts immediately when using `flame run` (default behavior) +- **Automatic Flamegraph Generation**: Interactive HTML flamegraphs are created automatically on exit +- **Clear File Path Display**: Shows exact paths and browser URLs for generated files +- **Manual Control**: Optional manual mode with signal-based control using `SIGUSR2` +- **Interactive Visualization**: WebGL-based HTML flamegraphs with zoom, search, and filtering +- **CLI Interface**: Simple 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 (Auto-Start Mode) + +```bash +# Start profiling your application (profiling begins immediately) +flame run server.js + +# The application runs with CPU profiling active +# When you stop the app (Ctrl-C or normal exit), you'll see: +# šŸ”„ CPU profile written to: cpu-profile-2025-08-27T12-00-00-000Z.pb +# šŸ”„ Generating flamegraph... +# šŸ”„ Flamegraph will be saved as: cpu-profile-2025-08-27T12-00-00-000Z.html +# šŸ”„ Open file:///path/to/cpu-profile-2025-08-27T12-00-00-000Z.html in your browser +``` + +### Manual Profiling Mode + +```bash +# Start profiling in manual mode (requires signals to start) +flame run --manual 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