google / pprof-nodejs

pprof support for Node.js
Apache License 2.0
251 stars 26 forks source link

feat: use inspector for heap profiles #236

Open psx95 opened 1 year ago

psx95 commented 1 year ago

For heap profiling, replaces the native C++ addon with calls to Node's inspector module. This uses the same V8::CpuProfiler under the hood but communicates over the chrome devtools protocol.

A similar PR has been raised to determine viability of using Node's inspector module for time profiling.

Testing

Caveats

Flame graph generated using the in-built inspector

in-built-inspector

Flame graph generated using the C++ addon

original-implementation

The graphs look similar, but there are differences, mostly due to the serializeHeapProfile task. When using the in-built inspector, this process takes about 1.55MB, while in the implementation that used C++ addon, this process took 0.81MB.

This accounts for most difference b/w the memory usage reported by the different profilers.

conventional-commit-lint-gcf[bot] commented 1 year ago

🤖 I detect that the PR title and the commit message differ and there's only one commit. To use the PR title for the commit history, you can use Github's automerge feature with squashing, or use automerge label. Good luck human!

-- conventional-commit-lint bot https://conventionalcommits.org/

nolanmar511 commented 1 year ago

Kokoro system tests have failed with the following (suggesting that maybe the heap profile isn't being written out successfully any more):

+ pprof -filefunctions -top -nodecount=2 heap.pb.gz
+ grep 'busyLoop.*src/busybench.js'
+ tee
heap.pb.gz: parsing profile: empty input file
pprof: failed to fetch any source profiles