1212#include " aliased_buffer.h"
1313#include " v8-profiler.h"
1414
15+ namespace node {
16+
1517// Set the node name of a MemoryRetainer to klass
1618#define SET_MEMORY_INFO_NAME (Klass ) \
1719 inline std::string MemoryInfoName () const override { return #Klass; }
2527#define SET_NO_MEMORY_INFO () \
2628 inline void MemoryInfo (node::MemoryTracker* tracker) const override {}
2729
28- namespace node {
29-
3030class MemoryTracker ;
3131class MemoryRetainerNode ;
3232
@@ -43,16 +43,16 @@ class NodeBIO;
4343 * void MemoryInfo(MemoryTracker* tracker) const override {
4444 * // Node name and size comes from the MemoryInfoName and SelfSize of
4545 * // AnotherRetainerClass
46- * tracker->TrackField("another_retainer", this-> another_retainer);
46+ * tracker->TrackField("another_retainer", another_retainer);
4747 * // Specify node name and size explicitly
4848 * tracker->TrackFieldWithSize("internal_member",
49- * this-> internal_member.size(),
49+ * internal_member.size(),
5050 * "InternalClass");
5151 * // Node name falls back to the edge name,
5252 * // elements in the container appear as grandchildren nodes
53- * tracker->TrackField("vector", this->vector_field );
53+ * tracker->TrackField("vector", vector );
5454 * // Node name and size come from the JS object
55- * tracker->TrackField("target", this-> target);
55+ * tracker->TrackField("target", target);
5656 * }
5757 *
5858 * // Or use SET_MEMORY_INFO_NAME(ExampleRetainer)
@@ -69,12 +69,12 @@ class NodeBIO;
6969 * // a BaseObject or an AsyncWrap class
7070 * bool IsRootNode() const override { return !wrapped.IsWeak(); }
7171 * v8::Local<v8::Object> WrappedObject() const override {
72- * return node::PersistentToLocal(this-> wrapped);
72+ * return node::PersistentToLocal(wrapped);
7373 * }
7474 * private:
7575 * AnotherRetainerClass another_retainer;
7676 * InternalClass internal_member;
77- * std::vector<int > vector;
77+ * std::vector<uv_async_t > vector;
7878 * node::Persistent<Object> target;
7979 *
8080 * node::Persistent<Object> wrapped;
@@ -84,7 +84,10 @@ class NodeBIO;
8484 * Node / ExampleRetainer
8585 * |> another_retainer :: Node / AnotherRetainerClass
8686 * |> internal_member :: Node / InternalClass
87- * |> vector :: Node / vector
87+ * |> vector :: Node / vector (elements will be grandchildren)
88+ * |> [1] :: Node / uv_async_t (uv_async_t has predefined names)
89+ * |> [2] :: Node / uv_async_t
90+ * |> ...
8891 * |> target :: TargetClass (JS class name of the target object)
8992 * |> wrapped :: WrappedClass (JS class name of the wrapped object)
9093 * |> wrapper :: Node / ExampleRetainer (back reference)
@@ -123,12 +126,16 @@ class MemoryTracker {
123126
124127 // For containers, the elements will be graphed as grandchildren nodes
125128 // if the container is not empty.
129+ // By default, we assume the parent count the stack size of the container
130+ // into its SelfSize so that will be subtracted from the parent size when we
131+ // spin off a new node for the container.
126132 // TODO(joyeecheung): use RTTI to retrieve the class name at runtime?
127133 template <typename T, typename Iterator = typename T::const_iterator>
128134 inline void TrackField (const char * edge_name,
129135 const T& value,
130136 const char * node_name = nullptr ,
131- const char * element_name = nullptr );
137+ const char * element_name = nullptr ,
138+ bool subtract_from_self = true );
132139 template <typename T>
133140 inline void TrackField (const char * edge_name,
134141 const std::queue<T>& value,
0 commit comments