NS_IMETHODIMP
nsWindowMemoryReporter::CollectReports(nsIMemoryMultiReporterCallback* aCb,
                                       nsISupports* aClosure)
{
  nsGlobalWindow::WindowByIdTable* windowsById =
    nsGlobalWindow::GetWindowsTable();
  NS_ENSURE_TRUE(windowsById, NS_OK);

  // Hold on to every window in memory so that window objects can't be
  // destroyed while we're calling the memory reporter callback.
  WindowArray windows;
  windowsById->Enumerate(GetWindows, &windows);

  // Collect window memory usage.
  nsRefPtr<nsGlobalWindow> *w = windows.Elements();
  nsRefPtr<nsGlobalWindow> *end = w + windows.Length();
  nsWindowSizes windowTotalSizes(NULL);
  for (; w != end; ++w) {
    CollectWindowReports(*w, &windowTotalSizes, aCb, aClosure);
  }

#define REPORT(_path, _amount, _desc)                                         \
  do {                                                                        \
    aCb->Callback(EmptyCString(), NS_LITERAL_CSTRING(_path),                  \
                  nsIMemoryReporter::KIND_OTHER,                              \
                  nsIMemoryReporter::UNITS_BYTES, _amount,                    \
                  NS_LITERAL_CSTRING(_desc), aClosure);                       \
  } while (0)

  REPORT("window-objects-dom", windowTotalSizes.mDOM, 
         "Memory used for the DOM within windows. "
         "This is the sum of all windows' 'dom' numbers.");
    
  REPORT("window-objects-style-sheets", windowTotalSizes.mStyleSheets, 
         "Memory used for style sheets within windows. "
         "This is the sum of all windows' 'style-sheets' numbers.");
    
  REPORT("window-objects-layout-arenas", windowTotalSizes.mLayoutArenas, 
         "Memory used by layout PresShell, PresContext, and other related "
         "areas within windows. This is the sum of all windows' "
         "'layout/arenas' numbers.");
    
  REPORT("window-objects-layout-style-sets", windowTotalSizes.mLayoutStyleSets, 
         "Memory used for style sets within windows. "
         "This is the sum of all windows' 'layout/style-sets' numbers.");
    
  REPORT("window-objects-layout-text-runs", windowTotalSizes.mLayoutTextRuns, 
         "Memory used for text runs within windows. "
         "This is the sum of all windows' 'layout/text-runs' numbers.");

#undef REPORT
    
  return NS_OK;
}
Exemplo n.º 2
0
NS_IMETHODIMP
nsDOMMemoryMultiReporter::CollectReports(nsIMemoryMultiReporterCallback* aCb,
                                         nsISupports* aClosure)
{
  nsGlobalWindow::WindowByIdTable* windowsById =
    nsGlobalWindow::GetWindowsTable();
  NS_ENSURE_TRUE(windowsById, NS_OK);

  // Hold on to every window in memory so that window objects can't be
  // destroyed while we're calling the memory reporter callback.
  WindowArray windows;
  windowsById->Enumerate(GetWindows, &windows);

  // Collect window memory usage.
  nsRefPtr<nsGlobalWindow> *w = windows.Elements();
  nsRefPtr<nsGlobalWindow> *end = w + windows.Length();
  WindowTotals windowTotals;
  for (; w != end; ++w) {
    CollectWindowReports(*w, &windowTotals, aCb, aClosure);
  }

  NS_NAMED_LITERAL_CSTRING(kDomTotalWindowsDesc,
    "Memory used for the DOM within windows.  This is the sum of all windows' "
    "'dom' numbers.");
  aCb->Callback(EmptyCString(), NS_LITERAL_CSTRING("dom-total-window"),
                nsIMemoryReporter::KIND_OTHER,
                nsIMemoryReporter::UNITS_BYTES, windowTotals.mDom,
                kDomTotalWindowsDesc, aClosure);

  NS_NAMED_LITERAL_CSTRING(kLayoutTotalWindowStyleSheetsDesc,
    "Memory used for style sheets within windows.  This is the sum of all windows' "
    "'style-sheets' numbers.");
  aCb->Callback(EmptyCString(), NS_LITERAL_CSTRING("style-sheets-total-window"),
                nsIMemoryReporter::KIND_OTHER,
                nsIMemoryReporter::UNITS_BYTES, windowTotals.mStyleSheets,
                kLayoutTotalWindowStyleSheetsDesc, aClosure);

  return NS_OK;
}