npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

js-self-profiling-utils

v0.1.0

Published

APIs to parse and summarize JS Self-Profiling traces.

Readme

js-self-profiling-utils

CI npm version

APIs to parse and summarize JS Self-Profiling traces.

Installation

npm / yarn / pnpm

npm install js-self-profiling-utils

CDN (Browser)

<script src="https://unpkg.com/js-self-profiling-utils"></script>
<!-- or -->
<script src="https://cdn.jsdelivr.net/npm/js-self-profiling-utils"></script>

Usage

ES Modules (TypeScript / Modern JS)

import { summarizeTrace, printCallTree } from 'js-self-profiling-utils';
import type { ProfilerTrace } from 'js-self-profiling-utils';

// After collecting a trace with the JS Self-Profiling API
const trace: ProfilerTrace = await profiler.stop();

const summary = summarizeTrace(trace);

console.log('Total samples:', summary.totalSamples);
console.log('Top functions:', summary.topFunctions);

// Print call tree to console
printCallTree(summary.callTree);

// Export folded stacks for flamegraph tools
const folded = summary.toFoldedStacks();

CommonJS (Node.js)

const { summarizeTrace, printCallTree } = require('js-self-profiling-utils');

const summary = summarizeTrace(trace);

Browser (Script Tag)

<script src="https://unpkg.com/js-self-profiling-utils"></script>
<script>
  const { summarizeTrace, printCallTree } = JSSelfProfilingUtils;
  
  // Use the APIs
  const summary = summarizeTrace(trace);
</script>

API

summarizeTrace(trace, options?)

Analyzes a ProfilerTrace and returns aggregated data.

Options: | Option | Type | Default | Description | |--------|------|---------|-------------| | topN | number | 30 | Number of top functions to return | | minPercent | number | 0 | Minimum inclusive percentage threshold | | formatFrame | function | (built-in) | Custom frame formatting function |

Returns: | Property | Type | Description | |----------|------|-------------| | totalSamples | number | Total number of samples in the trace | | topFunctions | TraceRow[] | Array of top functions with inclusive/exclusive counts | | callTree | CallTreeNode | Hierarchical call tree structure | | toFoldedStacks() | () => string | Method to export folded stacks format (for flamegraphs) |

printCallTree(node, options?)

Prints a call tree to console with indentation.

Options: | Option | Type | Default | Description | |--------|------|---------|-------------| | maxDepth | number | 8 | Maximum depth to print | | minCount | number | 1 | Minimum sample count to display |

Development

Prerequisites

  • Node.js 18+
  • Chrome or Chromium (for E2E tests)

⚠️ Important: The JS Self-Profiling API is only available in Chromium-based browsers (Chrome, Edge). Make sure to open the dev server URL in Chrome.

Setup

# Install dependencies
npm install

# Install Playwright browsers (for E2E tests)
npx playwright install chromium

Running the Dev Server

npm run dev

This starts a Vite dev server at http://localhost:3000 with the required Document-Policy: js-profiling header. Open in Chrome to test the profiler interactively.

Running Tests

# Unit tests
npm test

# Unit tests in watch mode
npm run test:watch

# Unit tests with coverage
npm run test:coverage

# E2E tests (requires Chromium)
npm run test:e2e

# E2E tests with UI
npm run test:e2e:ui

# All tests
npm run test:all

Building

npm run build

Outputs to dist/:

  • index.js — ES Module
  • index.cjs — CommonJS
  • index.umd.js — UMD (for browsers)
  • index.d.ts — TypeScript declarations

License

ISC