Bug 1027921 - Part 4: Add SizeOf functions. r=njn, r=froydnj
authorEric Rahm <erahm@mozilla.com>
Mon, 04 Aug 2014 16:16:09 -0700
changeset 197760 efee0712ee71a19954acc6a7c7c6884a58f31fa0
parent 197759 9c16b710b1c79e6eb8389a948ba704f33fdb8cd1
child 197761 4501110ca9a71049b2f43c39073003d6f7a089bf
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersnjn, froydnj
bugs1027921
milestone34.0a1
Bug 1027921 - Part 4: Add SizeOf functions. r=njn, r=froydnj
xpcom/glue/BlockingResourceBase.h
xpcom/glue/DeadlockDetector.h
--- a/xpcom/glue/BlockingResourceBase.h
+++ b/xpcom/glue/BlockingResourceBase.h
@@ -47,16 +47,23 @@ public:
    * kResourceTypeName
    * Human-readable version of BlockingResourceType enum.
    */
   static const char* const kResourceTypeName[];
 
 
 #ifdef DEBUG
 
+  static size_t
+  SizeOfDeadlockDetector(MallocSizeOf aMallocSizeOf)
+  {
+    return sDeadlockDetector ?
+        sDeadlockDetector->SizeOfIncludingThis(aMallocSizeOf) : 0;
+  }
+
 private:
   // forward declaration for the following typedef
   struct DeadlockDetectorEntry;
 
   // ``DDT'' = ``Deadlock Detector Type''
   typedef DeadlockDetector<DeadlockDetectorEntry> DDT;
 
   /**
@@ -74,16 +81,26 @@ private:
                           BlockingResourceType aType)
       : mName(aName)
       , mType(aType)
       , mAcquisitionContext(CallStack::kNone)
     {
       NS_ABORT_IF_FALSE(mName, "Name must be nonnull");
     }
 
+    size_t
+    SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
+    {
+      // NB: |mName| is not reported as it's expected to be a static string.
+      //     If we switch to a nsString it should be added to the tally.
+      //     |mAcquisitionContext| has no measurable heap allocations in it.
+      size_t n = aMallocSizeOf(this);
+      return n;
+    }
+
     /**
      * Print
      * Write a description of this blocking resource to |aOut|.  If
      * the resource appears to be currently acquired, the current
      * acquisition context is printed and true is returned.
      * Otherwise, we print the context from |aFirstSeen|, the
      * first acquisition from which the code calling |Print()|
      * became interested in us, and return false.  |Print()| can
--- a/xpcom/glue/DeadlockDetector.h
+++ b/xpcom/glue/DeadlockDetector.h
@@ -197,16 +197,25 @@ private:
       , mOrderedLT()        // FIXME bug 456272: set to empirical dep size?
       , mResource(aResource)
     {
     }
     ~OrderingEntry()
     {
     }
 
+    size_t
+    SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
+    {
+      size_t n = aMallocSizeOf(this);
+      n += mOrderedLT.SizeOfExcludingThis(aMallocSizeOf);
+      n += mResource->SizeOfIncludingThis(aMallocSizeOf);
+      return n;
+    }
+
     CallStack mFirstSeen; // first site from which the resource appeared
     HashEntryArray mOrderedLT; // this <_o Other
     const T* mResource;
   };
 
   // Throwaway RAII lock to make the following code safer.
   struct PRAutoLock
   {
@@ -239,16 +248,33 @@ public:
    *
    * *NOT* thread safe.
    */
   ~DeadlockDetector()
   {
     PR_DestroyLock(mLock);
   }
 
+  static size_t
+  SizeOfEntryExcludingThis(const T* aKey, const nsAutoPtr<OrderingEntry>& aEntry,
+                           MallocSizeOf aMallocSizeOf, void* aUserArg)
+  {
+    // NB: Key is accounted for in the entry.
+    size_t n = aEntry->SizeOfIncludingThis(aMallocSizeOf);
+    return n;
+  }
+
+  size_t
+  SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
+  {
+    size_t n = aMallocSizeOf(this);
+    n += mOrdering.SizeOfExcludingThis(SizeOfEntryExcludingThis, aMallocSizeOf);
+    return n;
+  }
+
   /**
    * Add
    * Make the deadlock detector aware of |aResource|.
    *
    * WARNING: The deadlock detector owns |aResource|.
    *
    * Thread safe.
    *