'How do I profile a node.js program from start to end?

Suppose I have a node.js cli program that can be run as node some-program.js and it exits in 10 seconds. How do I profile it? I want to get flame graphs and time spent in each functions.



Solution 1:[1]

node --prof some-program.js will produce an isolate-* for each worker thread.

node --prof-process isolate... will produce a user-friendly output.

You need some experience to be able to read it - but basically your program spends time in three ways: executing JS code, compiling JS code and running system libraries.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mmomtchev