Node.js profiler - Everything in Shared Libraries?
Asked Answered
I

1

14

I am currently doing Advent Of Code (definately to recommend btw but off topic. However on Day 3 I was pretty unhappy with the performance of my algorithm.

So I started using the built in node profiler to test out where I am wasting time. Here's the link to the repo in case you want to reproduce my steps advent-of-code-2019-typescript. Also if you do run

npm install
npm run build

before running the profiler

Steps to reproduce

I was following the guide from node.js to analyze my code. So first i ran my Code for Day 3 with the profiler

node --prof ./dist/src/03.01/index.js
node --prof-process isolate-xxxxxx-v8.log > processed.txt

Now the Output is not really helping

processed.txt [Summary-Section]

 [Summary]:
   ticks  total  nonlib   name
     12    0.0%   70.6%  JavaScript
      0    0.0%    0.0%  C++
    344    0.6%  2023.5%  GC
  56103  100.0%          Shared libraries
      5    0.0%          Unaccounted

As you see practicaly all ticks show up under Shared libraries. My guess is that this happens because index.js imports all the functions it needs and executes them. Practically everything should turn up under JavaScript yet only 12 ticks do.

If I am correct and this is the reason my question would be

How can i resolve the Shared Libaries Section to actually show all the functions being called and their ticks?

Bonus-Question

I would be happy if my question above was answered but this would help me further. I use TypeScript, so the Profiler runs on the transpiled Code. As a result my functions show up as and i would have to check in the transpiled code with line refers to which function. Possible but not pretty.

Is there a way to map this to the typescript files?

Incalescent answered 4/12, 2019 at 10:4 Comment(1)
You can try "--inspect-brk"?Pilferage
R
0

If you follow the guidance of this article you would start the nodejs process with --inspect-brk then launch Chrome and visit the pseudo-URL chrome://inspect

This should detect the open port of your nodejs process which is halted waiting for a debugger to connect to it.

Once you have connected, you can choose the Performance and Profiler tabs to execute periods of data gathering followed by analysis which will give you profiling WITHIN your javascript code stack.

If your code has suitable source mapping, and you have added your local folders to the source paths of Chrome, then should be able to navigate to your Typescript source via the line references within the profiler UI.

Racecourse answered 11/5 at 19:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.