How to get a thread dump of a running Node.js process?

Stack Overflow Asked by Philipp Claßen on December 23, 2020

In the Java JVM, kill -3 forces the process to print the current stack traces of all running threads. I found it very effective to quickly locate bottlenecks.

Is there an equivalent in V8? Can I make V8 print the current stack trace?

I assume, due to the asynchronous nature of node, it will be less useful than for a typical non-asynchronous program. Still, if there is an easy way to get access to a few stack traces, it does not take much time to look at it.

From my experience, some obvious bottlenecks can be quickly located that way before you need to switch to more advanced tools.

3 Answers

You can accomplish the same using heapdump tool. I found the below article of the same which is below (It also works for me):

Answered by Viral Patel on December 23, 2020

On this thread you have an idea using:

# node --debug-brk buggy.js Debugger listening on port 5858

In another terminal:

connecting to ... ok
break in buggy.js:16
 14 }
>16 z();
 18 });
debug> cont```

(wait for the node process to start using 100% CPU)

```debug> step
break in buggy.js:3
  1 function x() {
  2     var i = 0;
> 3     while(1) {
  4             i++;
  5     }
debug> bt
#0 buggy.js:3:8
#1 buggy.js:9:2
#2 buggy.js:13:2
#3 buggy.js:16:1```


Answered by zvi on December 23, 2020

Node has fully loaded diagnostics that tricks like above (if I understood correctly) would be redundant but feel free to correct me.

Must Read: Awesome blogs by NodeSource 1 2 3

I'll try to list down all the tools that I found useful:

Others (Just googled them.)

Answered by Aditya Guru on December 23, 2020

Add your own answers!

Related Questions

Add AWS Cognito to angular application

1  Asked on November 16, 2021 by captainmorgan


How to analize which object owns the max memory

0  Asked on November 16, 2021 by loverszhaokai


enable_if, SFINAE and template parameters?

2  Asked on November 16, 2021


Dynamic ‘wait’ arg in Scrapy-splash

0  Asked on November 16, 2021 by winters


Grab a decimal between 2 strings regex

1  Asked on November 15, 2021 by lenny-gonzalez


Django , models object not displayed in views

2  Asked on November 15, 2021 by mxzero-mxzero


Re-render a sibling component using hooks

3  Asked on November 15, 2021 by programmer1


filter method returns empty array

3  Asked on November 15, 2021


Fit container inside image

1  Asked on November 15, 2021


Ask a Question

Get help from others!

© 2022 All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP