NS_IMETHODIMP MediaMemoryTracker::CollectReports(nsIHandleReportCallback* aHandleReport, nsISupports* aData, bool aAnonymize) { int64_t video = 0, audio = 0; // NB: When resourceSizes' ref count goes to 0 the promise will report the // resources memory and finish the asynchronous memory report. RefPtr<MediaDecoder::ResourceSizes> resourceSizes = new MediaDecoder::ResourceSizes(MediaMemoryTracker::MallocSizeOf); nsCOMPtr<nsIHandleReportCallback> handleReport = aHandleReport; nsCOMPtr<nsISupports> data = aData; resourceSizes->Promise()->Then( AbstractThread::MainThread(), __func__, [handleReport, data] (size_t size) { handleReport->Callback( EmptyCString(), NS_LITERAL_CSTRING("explicit/media/resources"), KIND_HEAP, UNITS_BYTES, size, NS_LITERAL_CSTRING("Memory used by media resources including " "streaming buffers, caches, etc."), data); nsCOMPtr<nsIMemoryReporterManager> imgr = do_GetService("@mozilla.org/memory-reporter-manager;1"); if (imgr) { imgr->EndReport(); } }, [] (size_t) { /* unused reject function */ }); DecodersArray& decoders = Decoders(); for (size_t i = 0; i < decoders.Length(); ++i) { MediaDecoder* decoder = decoders[i]; video += decoder->SizeOfVideoQueue(); audio += decoder->SizeOfAudioQueue(); decoder->AddSizeOfResources(resourceSizes); } #define REPORT(_path, _amount, _desc) \ do { \ nsresult rv; \ rv = aHandleReport->Callback(EmptyCString(), NS_LITERAL_CSTRING(_path), \ KIND_HEAP, UNITS_BYTES, _amount, \ NS_LITERAL_CSTRING(_desc), aData); \ NS_ENSURE_SUCCESS(rv, rv); \ } while (0) REPORT("explicit/media/decoded/video", video, "Memory used by decoded video frames."); REPORT("explicit/media/decoded/audio", audio, "Memory used by decoded audio chunks."); #undef REPORT return NS_OK; }
NS_IMETHODIMP MediaMemoryTracker::CollectReports(nsIHandleReportCallback* aHandleReport, nsISupports* aData, bool aAnonymize) { // NB: When resourceSizes' ref count goes to 0 the promise will report the // resources memory and finish the asynchronous memory report. RefPtr<MediaDecoder::ResourceSizes> resourceSizes = new MediaDecoder::ResourceSizes(MediaMemoryTracker::MallocSizeOf); nsCOMPtr<nsIHandleReportCallback> handleReport = aHandleReport; nsCOMPtr<nsISupports> data = aData; resourceSizes->Promise()->Then( // Don't use SystemGroup::AbstractMainThreadFor() for // handleReport->Callback() will run scripts. AbstractThread::MainThread(), __func__, [handleReport, data] (size_t size) { handleReport->Callback( EmptyCString(), NS_LITERAL_CSTRING("explicit/media/resources"), KIND_HEAP, UNITS_BYTES, size, NS_LITERAL_CSTRING("Memory used by media resources including " "streaming buffers, caches, etc."), data); nsCOMPtr<nsIMemoryReporterManager> imgr = do_GetService("@mozilla.org/memory-reporter-manager;1"); if (imgr) { imgr->EndReport(); } }, [] (size_t) { /* unused reject function */ }); int64_t video = 0; int64_t audio = 0; DecodersArray& decoders = Decoders(); for (size_t i = 0; i < decoders.Length(); ++i) { MediaDecoder* decoder = decoders[i]; video += decoder->SizeOfVideoQueue(); audio += decoder->SizeOfAudioQueue(); decoder->AddSizeOfResources(resourceSizes); } MOZ_COLLECT_REPORT( "explicit/media/decoded/video", KIND_HEAP, UNITS_BYTES, video, "Memory used by decoded video frames."); MOZ_COLLECT_REPORT( "explicit/media/decoded/audio", KIND_HEAP, UNITS_BYTES, audio, "Memory used by decoded audio chunks."); return NS_OK; }