Implement MemoryTracker for Heap Snapshots #1584
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is adapted from Node.js' implementation.
This extends workerd's v8::HeapSnapshot collection process to allow including more detailed information about internal/native objects. Best illustrated with a screenshot...
This PR includes the core part of the implementation. It provides a straightforward implementation of
jsg::Object
s /jsg::Wrappable
snapshot tracing along with a handful of other types. It does *NOT add all of the instrumentation to all of the various objects.Those familiar with the GC tracing mechanism should find this familiar.
Look at the memory-test.c++ for an example of how it's used.
To keep things as simple as possible, to instrument your typical
jsg::Object
type (anything usingJSG_RESOURCE_TYPE
, you only need to provide an implementation of thevisitForMemoryInfo(...)
method:This should be familiar to anyone who has implemented support for GC tracing (using the
visitForGc(...)
method).Any fields you want to include in the heap snapshot are registered using
trackField(...)
ortrackFieldWithSize(...)
.If you want anything else to be trackable, then it will need to implement all three of the following methods:
To check to see if a type if trackable, you can test it using something like:
From the typical day-to-day use there wouldn't be much more than that. There a few more advanced cases to consider and we might want to expand the
trackField(...)
implementations inmemory.h
to add support for various types, but for the most part this was designed to be as minimally intrusive as possible.