diff options
author | Anna Henningsen <anna@addaleax.net> | 2018-06-10 17:40:13 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2018-07-13 20:53:15 +0300 |
commit | 57e301539bff2599974b7269a56377330c9b730e (patch) | |
tree | 6f5c866728f22bbacb8dadb89a2c8a12e5b66508 /src/async_wrap.cc | |
parent | 36cc5f5caf52af895079d153a9131fe2b0c6b8f9 (diff) |
src: enable more detailed memory tracking
This will enable more detailed heap snapshots based on
a newer V8 API.
This commit itself is not tied to that API and could
be backported.
PR-URL: https://github.com/nodejs/node/pull/21742
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/async_wrap.cc')
-rw-r--r-- | src/async_wrap.cc | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/src/async_wrap.cc b/src/async_wrap.cc index 89e82b9ce36..e98dca3c566 100644 --- a/src/async_wrap.cc +++ b/src/async_wrap.cc @@ -76,14 +76,22 @@ class RetainedAsyncInfo: public RetainedObjectInfo { private: const char* label_; const AsyncWrap* wrap_; - const int length_; + const size_t length_; }; +static int OwnMemory(AsyncWrap* async_wrap) { + MemoryTracker tracker; + tracker.set_track_only_self(true); + tracker.Track(async_wrap); + return tracker.accumulated_size(); +} + + RetainedAsyncInfo::RetainedAsyncInfo(uint16_t class_id, AsyncWrap* wrap) : label_(provider_names[class_id - NODE_ASYNC_ID_OFFSET]), wrap_(wrap), - length_(wrap->self_size()) { + length_(OwnMemory(wrap)) { } @@ -147,7 +155,9 @@ struct AsyncWrapObject : public AsyncWrap { inline AsyncWrapObject(Environment* env, Local<Object> object, ProviderType type) : AsyncWrap(env, object, type) {} - inline size_t self_size() const override { return sizeof(*this); } + void MemoryInfo(MemoryTracker* tracker) const override { + tracker->TrackThis(this); + } }; @@ -252,7 +262,10 @@ class PromiseWrap : public AsyncWrap { : AsyncWrap(env, object, PROVIDER_PROMISE, -1, silent) { MakeWeak(); } - size_t self_size() const override { return sizeof(*this); } + + void MemoryInfo(MemoryTracker* tracker) const override { + tracker->TrackThis(this); + } static constexpr int kPromiseField = 1; static constexpr int kIsChainedPromiseField = 2; |