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 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-flame

v0.0.2

Published

Tools for flaming Node with ptrace on Linux

Downloads

1

Readme

Synopsis

Tools for profiling Node.js programs. Uses ptrace to collect and symbolicate JavaScript backtraces, extracting human-readable names by walking the V8 stack and heap.

node-flame is an iteration on node-stap, using ptrace instead of system-tap to collect backtraces.

Uses wrapper scripts and node-stackvis to generate textual or HTML flamegraphs. Can also output text suitable for input to FlameGraph.

Inspired and informed by Dave Pacheco's excellent V8 DTrace ustack helper.

Safety

Your process is paused briefly when ptrace is attached to the process.

Understand that tools that use ptrace, such as strace or node-flame can have a negative impact on your processes. For example, if you abruptly kill node-flame or strace, the process you are profiling can get stuck in a stopped state.

Ptrace interrupts syscalls. Node/libuv handles this correctly, but it can interfere more intricately with the performance of your process.

The nature of pausing the process and resuming it means that it will slow down and this slowdown can be significant.

Recommended to try in safe environments before running in production!

Caveats

  • Only works on 64-bit node processes.
  • Line numbers are best effort (not always available) and refer to the start of a function.
  • Only tested on node0.10 so far. [TODO: fix for node4+]
  • Stacks may omit inlined functions.
  • Also may elide frames on very deep stacks to avoid doing too much work
  • Requires sudo due to ptrace kernel protection

Basic Usage

[~/] sudo npm i node-flame -g
[~/node-flame]$ sudo node-flame 
Usage: sudo node-flame <pid> <text|flame|raw|fullraw> <duration (s)>
  text: textual flame graph.
  flame: html flame graph.
  raw: format suitable for input to FlameGraph tools.

HTML Example

[~/]$ sudo node-flame 24701 flame 10 > /tmp/flame.html
Sampling 24701 for 10s, outputting flame.

[~/]$ # done

Raw Example

[~/]$ sudo node-flame 2291 raw 10 > /tmp/flame.raw.txt
Sampling 2291 for 10s, outputting raw.

[~/]$ cd ./FlameGraph/
[~/FlameGraph]$ ./stackcollapse.pl /tmp/flame.raw | tr -d "\0" > /tmp/flame.folded
[~/FlameGraph]$ ./flamegraph.pl /tmp/flame.folded > /tmp/flame.svg

Text Example

[~/]$ cat ./test.js
var dummy = new Error().stack; // Persuade v8 to compute line numbers

while(true) {
    console.log("Hello!");
}
[~/]$ node ./test.js  > /dev/null & 
[1] 2291
[~/]$ sudo node-flame 2291 text 10
Sampling 2291 for 10s, outputting text.

Total samples: 747
747 node::Start(int, char**):[native]
  747 node::Load(v8::Handle<v8::Object>):[native]
    747 v8::Function::Call(v8::Handle<v8::Object>, int, v8::Handle<v8::Value>*):[native]
      747 v8::internal::Execution::Call(v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, int, v8::internal::Handle<v8::internal::Object>*, bool*, bool):[native]
        747 [0x72a82a in /usr/bin/nodejs]:[native]
          747 [entry frame]
            747 [internal frame]
              747 [empty]:[unknown]:26
                747 startup:[unknown]:29
                  747 Module.runMain:module.js:494
                    747 Module._load:module.js:274
                        ... [more]

Installation

sudo npm i node-flame -g

Tests

All things in the fullness of time.

Contributors

  • dh
  • jcorbin
  • Matt-Esch
  • Raynos

Future Work

  • Reflect on the symbol table to target different versions of v8
  • Mac support
  • Post-process to resolve line numbers (compute line endings from files)

License

MIT