Bug 682216 - add a memory reporter for libnestegg's memory; r=njn,kinetik
authorNathan Froyd <froydnj@mozilla.com>
Tue, 08 Apr 2014 10:36:30 -0400
changeset 179484 5c509bb6f5c4d0fba0c0f718538443e158043ec0
parent 179483 7c22d81c6b04ad37c3239c7aa936f2a1620e76d7
child 179485 5d5dae8097ef84b87e3f4214b70108bf5f81c94f
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersnjn, kinetik
bugs682216
milestone31.0a1
Bug 682216 - add a memory reporter for libnestegg's memory; r=njn,kinetik
layout/media/symbols.def.in
xpcom/build/nsXPComInit.cpp
--- a/layout/media/symbols.def.in
+++ b/layout/media/symbols.def.in
@@ -23,16 +23,17 @@ nestegg_track_codec_id
 nestegg_track_count
 nestegg_get_cue_point
 nestegg_track_seek
 nestegg_track_type
 nestegg_track_video_params
 nestegg_tstamp_scale
 nestegg_has_cues
 nestegg_sniff
+nestegg_set_halloc_func
 #endif
 #ifdef MOZ_WEBM_ENCODER
 writeSimpleBlock
 writeHeader
 writeSegmentInformation
 writeVideoTrack
 writeAudioTrack
 Ebml_Serialize
--- a/xpcom/build/nsXPComInit.cpp
+++ b/xpcom/build/nsXPComInit.cpp
@@ -132,16 +132,19 @@ extern nsresult nsStringInputStreamConst
 #ifdef MOZ_VISUAL_EVENT_TRACER
 #include "mozilla/VisualEventTracer.h"
 #endif
 
 #include "ogg/ogg.h"
 #ifdef MOZ_VPX
 #include "vpx_mem/vpx_mem.h"
 #endif
+#ifdef MOZ_WEBM
+#include "nestegg/nestegg.h"
+#endif
 
 #include "GeckoProfiler.h"
 
 #include "jsapi.h"
 
 using namespace mozilla;
 using base::AtExitManager;
 using mozilla::ipc::BrowserProcessSubThread;
@@ -413,16 +416,38 @@ private:
     }
 };
 
 NS_IMPL_ISUPPORTS1(VPXReporter, nsIMemoryReporter)
 
 /* static */ template<> Atomic<size_t> CountingAllocatorBase<VPXReporter>::sAmount(0);
 #endif /* MOZ_VPX */
 
+#ifdef MOZ_WEBM
+class NesteggReporter MOZ_FINAL : public nsIMemoryReporter
+                                , public CountingAllocatorBase<NesteggReporter>
+{
+public:
+    NS_DECL_ISUPPORTS
+
+private:
+    NS_IMETHODIMP
+    CollectReports(nsIHandleReportCallback* aHandleReport, nsISupports* aData)
+    {
+        return MOZ_COLLECT_REPORT(
+            "explicit/media/libnestegg", KIND_HEAP, UNITS_BYTES, MemoryAllocated(),
+            "Memory allocated through libnestegg for WebM media files.");
+    }
+};
+
+NS_IMPL_ISUPPORTS1(NesteggReporter, nsIMemoryReporter)
+
+/* static */ template<> Atomic<size_t> CountingAllocatorBase<NesteggReporter>::sAmount(0);
+#endif /* MOZ_WEBM */
+
 EXPORT_XPCOM_API(nsresult)
 NS_InitXPCOM2(nsIServiceManager* *result,
               nsIFile* binDirectory,
               nsIDirectoryServiceProvider* appFileLocationProvider)
 {
     mozPoisonValueInit();
 
     char aLocal;
@@ -583,16 +608,21 @@ NS_InitXPCOM2(nsIServiceManager* *result
                           VPXReporter::CountingCalloc,
                           VPXReporter::CountingRealloc,
                           VPXReporter::CountingFree,
                           memcpy,
                           memset,
                           memmove);
 #endif
 
+#ifdef MOZ_WEBM
+    // And for libnestegg.
+    nestegg_set_halloc_func(NesteggReporter::CountingRealloc);
+#endif
+
     // Initialize the JS engine.
     if (!JS_Init()) {
         NS_RUNTIMEABORT("JS_Init failed");
     }
 
     rv = nsComponentManagerImpl::gComponentManager->Init();
     if (NS_FAILED(rv))
     {
@@ -636,16 +666,19 @@ NS_InitXPCOM2(nsIServiceManager* *result
     }
 
     // The memory reporter manager is up and running -- register our reporters.
     RegisterStrongMemoryReporter(new ICUReporter());
     RegisterStrongMemoryReporter(new OggReporter());
 #ifdef MOZ_VPX
     RegisterStrongMemoryReporter(new VPXReporter());
 #endif
+#ifdef MOZ_WEBM
+    RegisterStrongMemoryReporter(new NesteggReporter());
+#endif
 
     mozilla::Telemetry::Init();
 
     mozilla::HangMonitor::Startup();
     mozilla::BackgroundHangMonitor::Startup();
 
     const MessageLoop* const loop = MessageLoop::current();
     sMainHangMonitor = new mozilla::BackgroundHangMonitor(