Reputation: 26085
I have a script that is mostly callbacks for network events. The callbacks finish very quickly. In contrast, the script takes a relatively long time to initialize. I don't really care how long it takes to initialize, I just want to optimize the event callbacks. If I run node --prof
, most of the results are from the initialization.
How can I make Node not record anything until it's done initializing? In other words, how can I programmatically enable and disable profiling?
Upvotes: 5
Views: 349
Reputation: 5538
You could always pipe the output into flamebearer to get a flame graph.
node --prof app.js
node --prof-process --preprocess -j isolate*.log | npx flamebearer
It won't stop node from profiling your entire application, but it will likely give you enough information to drill down in the flame graph and ignore the pieces around the edges that you don't want to see, like the app bootstrap.
You could always try executing the code that you want to profile in a loop as well, to give them a larger representation. Or use node --prof
in tandem with benchmark
.
Upvotes: 2
Reputation: 1
node --prof
is meant to profile the entire application from the beginning. You could try using another profiler like vTune or the one built into webstorm. Another thing I would try is debug. Debug can be used to log the time it takes between events, which I think is what you are trying to go for.
Upvotes: 0