Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable source map support for node.js --prof-process

I try to profile my (typescript) app, which runs in node.js using the instructions from the nodejs.org simple profiling guide. However, the positions are those in the compiled js source file as run by node.

(How) is it possible to enable source map support for the step, to see the locations in the ts source files?

node --prof-process isolate-0xnnnnnnnnnnnn-v8.log > processed.txt

As of August 2017 I did not yet find a solution...

like image 709
Michael K Avatar asked Mar 24 '17 11:03

Michael K


1 Answers

After some initial playing around with --prof I found it easier to use Chrome's DevTools. At least for the JavaScript side. DevTools has the advantage of being interactive, and allows you to drill into the underlying .ts code.

  1. Start your app with node's --inspect flag:

    node -r ts-node/register -r tsconfig-paths/register --inspect ./src/index.ts

    (Here I'm using ts-node + tsconfig-paths for the typescript handling)

  2. Open chrome://inspect in Chrome

  3. Under "Remote Target" click "inspect" for your new target

    (This should open up a Chrome inspector window connected to your app)

  4. Go to the "Profiler" tab and begin recording a new profile

like image 75
Adaptation Avatar answered Sep 24 '22 11:09

Adaptation