bug 1224022 collect memory reports of AudioNode dom objects on the main thread r?padenot draft
authorKarl Tomlinson <karlt+@karlt.net>
Fri, 01 Jul 2016 18:46:34 +1200
changeset 383469 c5a4b5a0f24fcb42794b18f520044fd9fca68c2c
parent 383468 0e8a7d058a0e97c8990c2c5244ebc8f83b694031
child 383470 af4c15d949a73eb03eee125f0076b1a55121f474
push id22037
push userktomlinson@mozilla.com
push dateMon, 04 Jul 2016 08:58:23 +0000
reviewerspadenot
bugs1224022
milestone50.0a1
bug 1224022 collect memory reports of AudioNode dom objects on the main thread r?padenot This will permit allowing the main thread to run while collecting reports from graph thread objects. MozReview-Commit-ID: BhW4Mp13bOK
dom/media/MediaStreamGraph.cpp
dom/media/MediaStreamGraph.h
dom/media/webaudio/AudioContext.cpp
dom/media/webaudio/AudioNodeEngine.h
--- a/dom/media/MediaStreamGraph.cpp
+++ b/dom/media/MediaStreamGraph.cpp
@@ -3487,21 +3487,16 @@ MediaStreamGraphImpl::CollectReports(nsI
     NS_ENSURE_SUCCESS(rv, rv);                                              \
   } while (0)
 
   for (size_t i = 0; i < mAudioStreamSizes.Length(); i++) {
     const AudioNodeSizes& usage = mAudioStreamSizes[i];
     const char* const nodeType =
       usage.mNodeType ? usage.mNodeType : "<unknown>";
 
-    nsPrintfCString domNodePath("explicit/webaudio/audio-node/%s/dom-nodes",
-                                nodeType);
-    REPORT(domNodePath, usage.mDomNode,
-           "Memory used by AudioNode DOM objects (Web Audio).");
-
     nsPrintfCString enginePath("explicit/webaudio/audio-node/%s/engine-objects",
                                nodeType);
     REPORT(enginePath, usage.mEngine,
            "Memory used by AudioNode engine objects (Web Audio).");
 
     nsPrintfCString streamPath("explicit/webaudio/audio-node/%s/stream-objects",
                                nodeType);
     REPORT(streamPath, usage.mStream,
--- a/dom/media/MediaStreamGraph.h
+++ b/dom/media/MediaStreamGraph.h
@@ -427,18 +427,17 @@ public:
   virtual void NotifyMainThreadStreamFinished() = 0;
 };
 
 /**
  * Helper struct used to keep track of memory usage by AudioNodes.
  */
 struct AudioNodeSizes
 {
-  AudioNodeSizes() : mDomNode(0), mStream(0), mEngine(0), mNodeType() {}
-  size_t mDomNode;
+  AudioNodeSizes() : mStream(0), mEngine(0), mNodeType() {}
   size_t mStream;
   size_t mEngine;
   const char* mNodeType;
 };
 
 class MediaStreamGraphImpl;
 class SourceMediaStream;
 class ProcessedMediaStream;
--- a/dom/media/webaudio/AudioContext.cpp
+++ b/dom/media/webaudio/AudioContext.cpp
@@ -34,16 +34,17 @@
 #include "MediaElementAudioSourceNode.h"
 #include "MediaStreamAudioDestinationNode.h"
 #include "MediaStreamAudioSourceNode.h"
 #include "MediaStreamGraph.h"
 #include "nsContentUtils.h"
 #include "nsNetCID.h"
 #include "nsNetUtil.h"
 #include "nsPIDOMWindow.h"
+#include "nsPrintfCString.h"
 #include "OscillatorNode.h"
 #include "PannerNode.h"
 #include "PeriodicWave.h"
 #include "ScriptProcessorNode.h"
 #include "StereoPannerNode.h"
 #include "WaveShaperNode.h"
 
 namespace mozilla {
@@ -1124,19 +1125,34 @@ AudioContext::SizeOfIncludingThis(mozill
   amount += mPannerNodes.ShallowSizeOfExcludingThis(aMallocSizeOf);
   return amount;
 }
 
 NS_IMETHODIMP
 AudioContext::CollectReports(nsIHandleReportCallback* aHandleReport,
                              nsISupports* aData, bool aAnonymize)
 {
+  const nsLiteralCString
+    nodeDescription("Memory used by AudioNode DOM objects (Web Audio).");
+  for (auto iter = mAllNodes.ConstIter(); !iter.Done(); iter.Next()) {
+    AudioNode* node = iter.Get()->GetKey();
+    int64_t amount = node->SizeOfIncludingThis(MallocSizeOf);
+    nsPrintfCString domNodePath("explicit/webaudio/audio-node/%s/dom-nodes",
+                                node->NodeType());
+    nsresult rv =
+      aHandleReport->Callback(EmptyCString(), domNodePath, KIND_HEAP,
+                              UNITS_BYTES, amount, nodeDescription, aData);
+    if (NS_WARN_IF(NS_FAILED(rv)))
+      return rv;
+  }
+
   int64_t amount = SizeOfIncludingThis(MallocSizeOf);
-  return MOZ_COLLECT_REPORT("explicit/webaudio/audiocontext", KIND_HEAP, UNITS_BYTES,
-                            amount, "Memory used by AudioContext objects (Web Audio).");
+  return MOZ_COLLECT_REPORT("explicit/webaudio/audiocontext",
+                            KIND_HEAP, UNITS_BYTES, amount,
+                            "Memory used by AudioContext objects (Web Audio).");
 }
 
 BasicWaveFormCache*
 AudioContext::GetBasicWaveFormCache()
 {
   MOZ_ASSERT(NS_IsMainThread());
   if (!mBasicWaveFormCache) {
     mBasicWaveFormCache = new BasicWaveFormCache(SampleRate());
--- a/dom/media/webaudio/AudioNodeEngine.h
+++ b/dom/media/webaudio/AudioNodeEngine.h
@@ -391,23 +391,20 @@ public:
     return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
   }
 
   void SizeOfIncludingThis(MallocSizeOf aMallocSizeOf,
                            AudioNodeSizes& aUsage) const
   {
     aUsage.mEngine = SizeOfIncludingThis(aMallocSizeOf);
     aUsage.mNodeType = mNodeType;
-    if (mNode) {
-      aUsage.mDomNode = mNode->SizeOfIncludingThis(aMallocSizeOf);
-    }
   }
 
 private:
-  dom::AudioNode* mNode;
+  dom::AudioNode* mNode; // main thread only
   const char* const mNodeType;
   const uint16_t mInputCount;
   const uint16_t mOutputCount;
 };
 
 } // namespace mozilla
 
 #endif /* MOZILLA_AUDIONODEENGINE_H_ */