Skip to content

Instantly share code, notes, and snippets.

@EricRahm
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EricRahm/0068cd58c33f9c0694cc to your computer and use it in GitHub Desktop.
Save EricRahm/0068cd58c33f9c0694cc to your computer and use it in GitHub Desktop.
Reporting MediaRawData

Reporting for MediaRawData:

Option 1: Report it in nsDocument::DocAddSizeOfExcludingThis (nsINode) HTMLMediaElement -> MediaSource -> SourceBuffer -> TrackBufferManager -> MediaRawData Pro: this should work Con: It would be rather generic under mDOMElementNodesSize

njn suggested expanding the struct to specify HTMLMediaElement specific stuff

Option 2: Unknown, MediaSource might be owned somewhere else https://dxr.mozilla.org/mozilla-central/source/dom/media/MediaDecoder.cpp#445

Async all the things:

  1. nsWindowMemoryReporter::CollectReports - This does the reporting of total sizes, passes a sizeof struct into other methods
  2. WindowPaths needs to be newed / refcounted
  3. Reporting of total sizes needs to be deferred
  4. CollectWindowReports returns a promise, ->then decrements pending count
  5. CollectWindowReports - This does the reporting of individual windows sizes, calls aWindow->AddSizeOfIncludingThis(&windowSizes);
  6. AddSizeOf returns promise ->then does the reporting, increments totals
  7. nsGlobalWindow::AddSizeOfIncludingThis - calls mDoc->DocAddSizeOfIncludingThis(aWindowSizes);
  8. mDoc->DocAddSizeOfIncludingThis(aWindowSizes) returns promise otherwise create already resolved happy promise
  9. nsIDocument::DocAddSizeOfIncludingThis - we care about the subclass implementation nsDocument::DocAddSizeOfExcludingThis(nsWindowSizes* aWindowSizes)
  10. Stub out other implementors to return a resolved promise
  11. nsDocument::DocAddSizeOfExcludingThis(nsWindowSizes* aWindowSizes) - calls nsINode::SizeOfExcludingThis. These need to take some sort of struct so that they can indicate if they're async
  12. Loop through nodes, each returns a promise, ->then will add to the tally
  13. Update all INodes to return resolved promise except HTMLMediaElement
  14. Return a Promise::All([array of promises])
  15. (...7...8...) HTMLMediaElement::SizeOfExcludingThis -> MediaSource::SizeOfIncludingThis -> ad nauseum

Pass in accumulator

struct AsyncSizeAccumulator
{
  MallocSizeOf mSizeOf;
  size_t mSize;
  size_t mPendingRequests;
};

With promises this probably actually isn't necessary.

But we also need some sort of callback mechanism. Promises might be nice:

   Promise MediaSource::DeferredSizeOfIncludingThis(...) {
     Promise deferred = mSourceBuffers->DefferedSizeOfIncludingThis(...);
     return deferred;
  }
  
  Promise TrackBuffersManager::DeferredSizeOfIncludingThis(...) {
    Promise deferred = Dispatch(taskqueue, this, SizeOfExlcudingThisInternal);
    return deferred;
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment