Skip to content

feat: Introducing allocation profiler#343

Merged
IlyasShabi merged 7 commits into
mainfrom
ishabi/allocations-profiler-v2
Jun 8, 2026
Merged

feat: Introducing allocation profiler#343
IlyasShabi merged 7 commits into
mainfrom
ishabi/allocations-profiler-v2

Conversation

@IlyasShabi

@IlyasShabi IlyasShabi commented Jun 2, 2026

Copy link
Copy Markdown

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

github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown

Overall package size

Self size: 2.19 MB
Deduped: 2.56 MB
No deduping: 2.56 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
Comment thread bindings/profilers/heap.cc Outdated
Comment thread bindings/profilers/heap.cc Outdated
Comment thread bindings/profilers/heap.cc Outdated
Comment thread bindings/test/binding.cc
Comment thread bindings/allocation-profile.cc Outdated
Comment thread ts/src/heap-profiler.ts Outdated
Comment thread bindings/allocation-profile.cc Outdated
Comment thread bindings/allocation-profile.cc Outdated
Comment thread bindings/profilers/heap.cc
Comment thread bindings/allocation-profile.cc

@szegedi szegedi left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great now, just a last JSDoc nit and we're good :-)

Comment thread ts/src/heap-profiler.ts Outdated
* references to them. The memory is freed when the callback returns.
*
* @param callback - function to convert the heap profiler to a converted profile
* @param callback - function to convert the heap profiler to a converted

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param callback - function to convert the heap profiler to a converted
* @param callback - function to convert the heap profile to a converted

Also (I'll write it here as prose 'cause GitHub is giving me trouble making a diff suggestion for some reason) above we have the two sentences:

 * Collects a heap profile when heapProfiler is enabled. Otherwise throws
 * an error.
 * Map the heap profiler to a converted profile using callback function.

That should be edited into a single sentence:

Map the heap profile to a converted profile using callback function when heapProfiler is enabled. Otherwise throws an error.

@IlyasShabi IlyasShabi requested a review from szegedi June 8, 2026 09:44
@IlyasShabi IlyasShabi merged commit e626eb2 into main Jun 8, 2026
126 of 128 checks passed
@IlyasShabi IlyasShabi deleted the ishabi/allocations-profiler-v2 branch June 8, 2026 10:34
@IlyasShabi IlyasShabi mentioned this pull request Jun 8, 2026
szegedi pushed a commit that referenced this pull request Jun 8, 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.

2 participants