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

ntop

v0.0.9

Published

Node CLI runtime profiler - easily debug unexpected high CPU usage

Downloads

35

Readme

"top" command for Node apps

The idea is to be able to quickly see the heaviest currently running Node functions using a single command in the terminal just like with "top" for regular processes. Another major point is only attaching the inspector for the time of the profiling so the tool can be always available in a production server without causing any overhead.

Once this is enabled there's no need to restart the app with "--profile" flag so any unexpected high CPU usage can be debugged more easily.

Usage - with no code changes required(Linux only)

npm i -g ntop
ntop inject 12345 // where 12345 is the process id
ntop 12345

Usage with includes in a project

npm i ntop

Add to the script to enable communication with CLI tool

const ntop = require('ntop')
ntop()

Then run the CLI. It will find all processes enabled for ntop communication

npx ntop

You'll see a list of ntop-enabled Node processes and their corresponding PIDs for convenience. Now you can see the list of functions for any process with

npx ntop 12345

Example output:

  • (garbage collector) | 11.703ms |
  • utils.bulkPreparePacket | 1.53ms | file:///home/app/src/Utils.js:91:26
  • (anonymous) | 1.181ms | evalmachine.:3:14
  • (anonymous) | 1.126ms | file:///home/app/node_modules/lodash/lodash.js:1223:19

Custom sampling time 5s

npx ntop 12345 5000

Verbose output showing breadcrumbs i.e. to see what called (anonymous)

npx ntop 12345 5000 -v

Example output with "breadcrumbs":

  • (garbage collector) | 4.191ms |

  • utils.bulkPreparePacket | 3.034ms | file:///home/app/src/Utils.js:91:26
    < prepareBulkData < (anonymous) < update < emit < update < processTick < (anonymous) < listOnTimeout < processTimers

  • (anonymous) | 2.574ms | evalmachine.:3:14
    < listOnTimeout < processTimers

  • prepareBulkData | 1.516ms | file:///home/app/src/controllers/Map.js:672:17
    < (anonymous) < update < emit < update < processTick < (anonymous) < listOnTimeout < processTimers

  • hasCallback | 1.141ms | file:///home/app/src/Scripting.js:271:13
    < update < emit < update < processTick < (anonymous) < listOnTimeout < processTimers

Experimental flame chart

npx ntop 12345 5000 -f

"Flame chart" (initial experiment):

  • (root) 3056.191ms
    -- processTimers 0.661ms
    --- listOnTimeout 0.661ms
    ---- (anonymous function) 0.661ms
    ----- processTick 0.661ms
    ------ queueNextAction 0.661ms
    ------- setImmediate 0.661ms
    -------- Immediate 0.661ms
    --------- initAsyncResource 0.661ms
    -- processTimers 1.305ms
    --- listOnTimeout 1.305ms
    ---- (anonymous function) 1.305ms
    ----- processTick 1.305ms
    ------ update 1.305ms
    ------- emit 1.305ms
    -------- update 1.305ms
    --------- (anonymous function) 1.305ms
    -- (garbage collector) 2.185ms
    -- processTimers 1.118ms
    --- listOnTimeout 1.118ms
    ---- (anonymous function) 1.118ms
    ----- processTick 1.118ms
    ------ update 1.118ms
    ------- emit 1.118ms
    -------- update 1.118ms
    --------- (anonymous function) 1.118ms
    ---------- prepareBulkData 1.118ms
    ----------- utils.bulkPreparePacket 1.118ms
    -- processTimers 1.471ms
    --- listOnTimeout 1.471ms
    ---- (anonymous function) 1.471ms
    ----- processTick 1.471ms
    ------ update 1.471ms
    ------- emit 1.471ms
    -------- update 1.471ms
    --------- (anonymous function) 1.471ms
    ---------- prepareBulkData 1.471ms
    ----------- utils.bulkPreparePacket 1.471ms
    ------------ preparePacket 1.471ms