Skip to content

feat: Introducing allocation profiler#343

Open
IlyasShabi wants to merge 1 commit into
mainfrom
ishabi/allocations-profiler-v2
Open

feat: Introducing allocation profiler#343
IlyasShabi wants to merge 1 commit into
mainfrom
ishabi/allocations-profiler-v2

Conversation

@IlyasShabi
Copy link
Copy Markdown

@IlyasShabi IlyasShabi commented Jun 2, 2026

What does this PR do?:
This PR adds optional allocation profiling support to the heap profiler. Allocation profiling is enabled only when passing the allocation flag to

pprof.heap.start(intervalBytes, stackDepth, true);

When enabled, the native profiler starts V8 heap sampling with allocation tracking flags so collected objects are retained in the sampling profile. The resulting pprof profile produces sample types:

  • inuse_objects/count
  • alloc_objects/count
  • inuse_space/bytes
  • alloc_space/bytes

This requires Node.js 26+, because the V8 sample API needs sample.is_live to distinguish live objects from collected ones. Older Node versions keep existing heap profiler behavior and reject allocation mode.

Motivation:
Node.js Allocation Profiler

Additional Notes:

  • This feature works only with stop v1 since we will get rid of lazy load node in stopV2 soon.
  • In ts/src/heap-profiler.ts I removed heapStackDepth variable because it was not used correctly.

How to test the change?:

  • Add C++ unit test for BuildAllocationStatsByNodeId
  • Allocation profiler unit tests in TS side were added

@IlyasShabi IlyasShabi added the semver-minor Usually minor non-breaking improvements label Jun 2, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 2, 2026

Overall package size

Self size: 2.19 MB
Deduped: 2.55 MB
No deduping: 2.55 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | source-map | 0.7.6 | 185.63 kB | 185.63 kB | | pprof-format | 2.2.1 | 163.06 kB | 163.06 kB | | node-gyp-build | 4.8.4 | 13.86 kB | 13.86 kB |

🤖 This report was automatically generated by heaviest-objects-in-the-universe

@datadog-datadog-prod-us1-2

This comment has been minimized.

@IlyasShabi IlyasShabi force-pushed the ishabi/allocations-profiler-v2 branch from 320e350 to 53faf4a Compare June 2, 2026 14:37
@IlyasShabi IlyasShabi marked this pull request as ready for review June 2, 2026 14:52
@IlyasShabi IlyasShabi changed the title feat: Allocation profiler feat: Introducing allocation profiler Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

semver-minor Usually minor non-breaking improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant