diff options
author | Anna Henningsen <anna@addaleax.net> | 2018-07-11 01:59:53 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2018-07-15 21:35:35 +0300 |
commit | 266a7e62585b975f2ea2d25473b21395f5ca5a3f (patch) | |
tree | 0e5229e042517620784aea2f8114c2cf3d287bb7 /src/memory_tracker.h | |
parent | d2a1408f119181675d9d3f20982ccd863443baad (diff) |
src: use V8 graph heap snapshot API
Transition to a newer, more flexible API for
heap snapshot creation.
This addresses a currently pending deprecation in the V8 API.
PR-URL: https://github.com/nodejs/node/pull/21741
Fixes: https://github.com/nodejs/node/issues/21633
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Diffstat (limited to 'src/memory_tracker.h')
-rw-r--r-- | src/memory_tracker.h | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/src/memory_tracker.h b/src/memory_tracker.h index 18822651f67..d0f9e0dcad8 100644 --- a/src/memory_tracker.h +++ b/src/memory_tracker.h @@ -3,15 +3,19 @@ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS -#include <unordered_set> +#include <unordered_map> #include <queue> +#include <stack> +#include <string> #include <limits> #include <uv.h> -#include <aliased_buffer.h> +#include "aliased_buffer.h" +#include "v8-profiler.h" namespace node { class MemoryTracker; +class MemoryRetainerNode; namespace crypto { class NodeBIO; @@ -29,6 +33,8 @@ class MemoryRetainer { } virtual bool IsRootNode() const { return false; } + + virtual std::string MemoryInfoName() const { return std::string(); } }; class MemoryTracker { @@ -67,17 +73,32 @@ class MemoryTracker { inline void TrackField(const char* name, const AliasedBuffer<NativeT, V8T>& value); - inline void Track(const MemoryRetainer* value); - inline size_t accumulated_size() const { return accumulated_size_; } + inline void Track(const MemoryRetainer* value, const char* name = nullptr); inline void set_track_only_self(bool value) { track_only_self_ = value; } + inline v8::EmbedderGraph* graph() { return graph_; } + inline v8::Isolate* isolate() { return isolate_; } - inline MemoryTracker() {} + inline explicit MemoryTracker(v8::Isolate* isolate, + v8::EmbedderGraph* graph) + : isolate_(isolate), graph_(graph) {} private: + typedef std::unordered_map<const MemoryRetainer*, MemoryRetainerNode*> + NodeMap; + + inline MemoryRetainerNode* CurrentNode() const; + inline MemoryRetainerNode* AddNode(const char* name, + const MemoryRetainer* retainer = nullptr); + inline MemoryRetainerNode* PushNode(const char* name, + const MemoryRetainer* retainer = nullptr); + inline void PopNode(); + bool track_only_self_ = false; - size_t accumulated_size_ = 0; - std::unordered_set<const MemoryRetainer*> seen_; + v8::Isolate* isolate_; + v8::EmbedderGraph* graph_; + std::stack<MemoryRetainerNode*> node_stack_; + NodeMap seen_; }; } // namespace node |