10

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...

2
  • have you ever found a solution to this? Commented Jan 5, 2021 at 5:33
  • 1
    Unfortunately not, but I did not actively search. In case you got further than me, you can suggest an edit with the new information and I'll accept it. Commented Jan 6, 2021 at 13:12

2 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for that suggestion. I rather give you an up vote but won't accept this answer, as it suggests something which helps in the situation but does not solve the command line profiler question.
But AFAIK --inspect start a debugger session not the profiler
0

Node.js doesn't yet support applying source-maps on --prof traces on its own.

There are a few workarounds to get source-map:

  • A script has been posted on the Node.js issue tracker, which leverages the source-map npm package to perform the remapping.
  • The Chromium DevTools trace does correctly apply source-maps, and you can easily connect to a Node.js process using the --inspect or --inspect-brk flag. Using --inspect-brk will immediately halt the Node.js process and wait for a debugger to connect, only resuming resuming execution once you explicitly resume script execution via the debugger. This is helpful for getting measurements of an application's startup sequence.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.