Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cpuprofile-to-flamegraph

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cpuprofile-to-flamegraph

Convert a nodejs .cpuprofile to a flame graph node

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

cpuprofile-to-flamegraph

Convert a .cpuprofile into a flameGraph tree to be renderable with D3-FlameGraph.

Flame Graph Example

/**
 * Compatible to the D3-FlameGraph input format
 * https://github.com/spiermar/d3-flame-graph#input-format
 */
type FlameGraphNode FlameGraphNode = {
	/**
	 * JavaScript function name.
	 */
	name: string;
	/**
	 * Self execution time
	 */
	value: number;
	/**
	 * Execution time including child nodes
	 */
	executionTime: number;
	/**
	 * Child nodes
	 */
	children: Array<FlameGraphNode>;
	/**
	 * Original cpu profiler node
	 */
	profileNode: {
        /**
        * Unique id of the node.
        */
        id: number;
        /**
        * Runtime.CallFrame
        * Function location
        */
        callFrame: {
            /**
            * JavaScript function name.
            */
            functionName?: string;
            /**
            * JavaScript script id.
            */
            scriptId: string;
            /**
            * JavaScript script name or url.
            */
            url: string;
            /**
            * JavaScript script line number (0-based).
            */
            lineNumber: number;
            /**
            * JavaScript script column number (0-based).
            */
            columnNumber: number;
        };
        /**
        * Number of samples where this node was on top of the call stack.
        */
        hitCount?: number;
        /**
        * Child node ids.
        */
        children?: number[];
    };
	/**
	 * nodeModule name if known
	 */
	nodeModule?: string;
	/**
	 * Parent node
	 */
	parent?: FlameGraphNode;
};

Usage:

cpuprofile-to-flamegraph is only able to transform a profile into a renderable structure.
To render it you have to combine it with D3-FlameGraph.

It will also calculate the execution timings and sort all nodes chronologically.

import { convertToMergedFlameGraph } from "cpuprofile-to-flamegraph";

const profile = JSON.parse(fs.readFileSync('demo.cpuprofile', "utf-8"));
const flameGraph = convertToMergedFlameGraph(profile);

FAQs

Package last updated on 03 Jan 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc