Bug 893857 (part 1) - Add LinkedList::SizeOf{In,Ex}cludingThis(). r=Waldo.
authorNicholas Nethercote <nnethercote@mozilla.com>
Sun, 24 Nov 2013 15:20:12 -0800
changeset 172043 f91e339a1b368361118f649efc759e9a9fae6fea
parent 172042 aea2b472991a995b9c72bc653c0df390d646be8d
child 172044 6cfc4f26a183fa3f71933b891951f62cfb7119de
push id3224
push userlsblakk@mozilla.com
push dateTue, 04 Feb 2014 01:06:49 +0000
treeherdermozilla-beta@60c04d0987f1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersWaldo
bugs893857
milestone28.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 893857 (part 1) - Add LinkedList::SizeOf{In,Ex}cludingThis(). r=Waldo.
mfbt/LinkedList.h
--- a/mfbt/LinkedList.h
+++ b/mfbt/LinkedList.h
@@ -53,16 +53,17 @@
  *
  */
 
 #ifndef mozilla_LinkedList_h
 #define mozilla_LinkedList_h
 
 #include "mozilla/Assertions.h"
 #include "mozilla/Attributes.h"
+#include "mozilla/MemoryReporting.h"
 #include "mozilla/Move.h"
 #include "mozilla/NullPtr.h"
 
 #ifdef __cplusplus
 
 namespace mozilla {
 
 template<typename T>
@@ -375,16 +376,36 @@ class LinkedList
      * each element as not in the list.
      */
     void clear() {
       while (popFirst())
         continue;
     }
 
     /*
+     * Measures the memory consumption of the list excluding |this|.  Note that
+     * it only measures the list elements themselves.  If the list elements
+     * contain pointers to other memory blocks, those blocks must be measured
+     * separately during a subsequent iteration over the list.
+     */
+    size_t sizeOfExcludingThis(MallocSizeOf mallocSizeOf) const {
+      size_t n = 0;
+      for (const T* t = getFirst(); t; t = t->getNext())
+        n += mallocSizeOf(t);
+      return n;
+    }
+
+    /*
+     * Like sizeOfExcludingThis(), but measures |this| as well.
+     */
+    size_t sizeOfIncludingThis(MallocSizeOf mallocSizeOf) const {
+      return mallocSizeOf(this) + sizeOfExcludingThis(mallocSizeOf);
+    }
+
+    /*
      * In a debug build, make sure that the list is sane (no cycles, consistent
      * next/prev pointers, only one sentinel).  Has no effect in release builds.
      */
     void debugAssertIsSane() const {
 #ifdef DEBUG
       const LinkedListElement<T>* slow;
       const LinkedListElement<T>* fast1;
       const LinkedListElement<T>* fast2;