From 08dc2dae6bb133d35d6c7aa7240f8ab660a81412 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 9 Apr 2012 22:52:33 -0700 Subject: [PATCH] Bug 744311 (part 1) - Preliminary whitespace and code order changes. r=jlebar. --HG-- extra : rebase_source : f700733d8aa1aed1ae1f9206b4ee9063f9a03341 --- content/media/nsMediaDecoder.cpp | 20 +-- dom/ipc/ContentChild.cpp | 16 ++- .../spellcheck/hunspell/src/mozHunspell.cpp | 12 +- ipc/glue/SharedMemory.cpp | 23 ++-- js/xpconnect/src/XPCJSRuntime.cpp | 6 +- layout/style/nsLayoutStylesheetCache.cpp | 10 +- netwerk/cache/nsCacheService.h | 3 +- startupcache/StartupCache.cpp | 24 ++-- .../aboutmemory/content/aboutMemory.js | 2 +- toolkit/components/places/History.cpp | 17 ++- xpcom/base/nsCycleCollector.cpp | 4 +- xpcom/base/nsMemoryReporterManager.cpp | 128 +++++++++--------- 12 files changed, 130 insertions(+), 135 deletions(-) diff --git a/content/media/nsMediaDecoder.cpp b/content/media/nsMediaDecoder.cpp index cdc5f2ba420..adc67d7788d 100644 --- a/content/media/nsMediaDecoder.cpp +++ b/content/media/nsMediaDecoder.cpp @@ -222,18 +222,18 @@ namespace mozilla { MediaMemoryReporter* MediaMemoryReporter::sUniqueInstance; NS_MEMORY_REPORTER_IMPLEMENT(MediaDecodedVideoMemory, - "explicit/media/decoded-video", - KIND_HEAP, - UNITS_BYTES, - MediaMemoryReporter::GetDecodedVideoMemory, - "Memory used by decoded video frames.") + "explicit/media/decoded-video", + KIND_HEAP, + UNITS_BYTES, + MediaMemoryReporter::GetDecodedVideoMemory, + "Memory used by decoded video frames.") NS_MEMORY_REPORTER_IMPLEMENT(MediaDecodedAudioMemory, - "explicit/media/decoded-audio", - KIND_HEAP, - UNITS_BYTES, - MediaMemoryReporter::GetDecodedAudioMemory, - "Memory used by decoded audio chunks.") + "explicit/media/decoded-audio", + KIND_HEAP, + UNITS_BYTES, + MediaMemoryReporter::GetDecodedAudioMemory, + "Memory used by decoded audio chunks.") MediaMemoryReporter::MediaMemoryReporter() : mMediaDecodedVideoMemory(new NS_MEMORY_REPORTER_NAME(MediaDecodedVideoMemory)) diff --git a/dom/ipc/ContentChild.cpp b/dom/ipc/ContentChild.cpp index c802a919955..ae4d8fcf733 100644 --- a/dom/ipc/ContentChild.cpp +++ b/dom/ipc/ContentChild.cpp @@ -381,14 +381,16 @@ ContentChild::RecvPMemoryReportRequestConstructor(PMemoryReportRequestChild* chi PRInt32 units; PRInt64 amount; nsCString desc; - r->GetPath(path); - r->GetKind(&kind); - r->GetUnits(&units); - r->GetAmount(&amount); - r->GetDescription(desc); - MemoryReport memreport(process, path, kind, units, amount, desc); - reports.AppendElement(memreport); + if (NS_SUCCEEDED(r->GetPath(path)) && + NS_SUCCEEDED(r->GetKind(&kind)) && + NS_SUCCEEDED(r->GetUnits(&units)) && + NS_SUCCEEDED(r->GetAmount(&amount)) && + NS_SUCCEEDED(r->GetDescription(desc))) + { + MemoryReport memreport(process, path, kind, units, amount, desc); + reports.AppendElement(memreport); + } } // Then do the memory multi-reporters, by calling CollectReports on each diff --git a/extensions/spellcheck/hunspell/src/mozHunspell.cpp b/extensions/spellcheck/hunspell/src/mozHunspell.cpp index 448bb678c5c..00d74fa996b 100644 --- a/extensions/spellcheck/hunspell/src/mozHunspell.cpp +++ b/extensions/spellcheck/hunspell/src/mozHunspell.cpp @@ -112,12 +112,12 @@ static PRInt64 HunspellGetCurrentAllocatedSize() { } NS_MEMORY_REPORTER_IMPLEMENT(Hunspell, - "explicit/spell-check", - KIND_HEAP, - UNITS_BYTES, - HunspellGetCurrentAllocatedSize, - "Memory used by the Hunspell spell checking engine. This number accounts " - "for the memory in use by Hunspell's internal data structures." + "explicit/spell-check", + KIND_HEAP, + UNITS_BYTES, + HunspellGetCurrentAllocatedSize, + "Memory used by the Hunspell spell checking engine. This number accounts " + "for the memory in use by Hunspell's internal data structures." ) nsresult diff --git a/ipc/glue/SharedMemory.cpp b/ipc/glue/SharedMemory.cpp index 58a8e27b01f..fba9522a9e6 100644 --- a/ipc/glue/SharedMemory.cpp +++ b/ipc/glue/SharedMemory.cpp @@ -53,18 +53,19 @@ static PRInt64 GetShmemAllocated() { return gShmemAllocated; } static PRInt64 GetShmemMapped() { return gShmemMapped; } NS_MEMORY_REPORTER_IMPLEMENT(ShmemAllocated, - "shmem-allocated", - KIND_OTHER, - UNITS_BYTES, - GetShmemAllocated, - "Memory shared with other processes that is accessible (but not " - "necessarily mapped).") + "shmem-allocated", + KIND_OTHER, + UNITS_BYTES, + GetShmemAllocated, + "Memory shared with other processes that is accessible (but not " + "necessarily mapped).") + NS_MEMORY_REPORTER_IMPLEMENT(ShmemMapped, - "shmem-mapped", - KIND_OTHER, - UNITS_BYTES, - GetShmemMapped, - "Memory shared with other processes that is mapped into the address space.") + "shmem-mapped", + KIND_OTHER, + UNITS_BYTES, + GetShmemMapped, + "Memory shared with other processes that is mapped into the address space.") SharedMemory::SharedMemory() : mAllocSize(0) diff --git a/js/xpconnect/src/XPCJSRuntime.cpp b/js/xpconnect/src/XPCJSRuntime.cpp index 4aa0f4e82a5..c577fd5a3da 100644 --- a/js/xpconnect/src/XPCJSRuntime.cpp +++ b/js/xpconnect/src/XPCJSRuntime.cpp @@ -1268,8 +1268,7 @@ GetJSUserCompartmentCount() // XPConnectJSCompartmentCount to avoid that problem, but then we couldn't // easily report them via telemetry, so we live with the small risk of // inconsistencies. -NS_MEMORY_REPORTER_IMPLEMENT( - XPConnectJSSystemCompartmentCount, +NS_MEMORY_REPORTER_IMPLEMENT(XPConnectJSSystemCompartmentCount, "js-compartments-system", KIND_OTHER, nsIMemoryReporter::UNITS_COUNT, @@ -1279,8 +1278,7 @@ NS_MEMORY_REPORTER_IMPLEMENT( "listed under 'js' if a garbage collection occurs at an inopportune time, " "but such cases should be rare.") -NS_MEMORY_REPORTER_IMPLEMENT( - XPConnectJSUserCompartmentCount, +NS_MEMORY_REPORTER_IMPLEMENT(XPConnectJSUserCompartmentCount, "js-compartments-user", KIND_OTHER, nsIMemoryReporter::UNITS_COUNT, diff --git a/layout/style/nsLayoutStylesheetCache.cpp b/layout/style/nsLayoutStylesheetCache.cpp index db8a42e108c..858b536b882 100644 --- a/layout/style/nsLayoutStylesheetCache.cpp +++ b/layout/style/nsLayoutStylesheetCache.cpp @@ -59,11 +59,11 @@ GetStylesheetCacheSize() } NS_MEMORY_REPORTER_IMPLEMENT(Sheets, - "explicit/layout/style-sheet-cache", - KIND_HEAP, - nsIMemoryReporter::UNITS_BYTES, - GetStylesheetCacheSize, - "Memory used for some built-in style sheets.") + "explicit/layout/style-sheet-cache", + KIND_HEAP, + nsIMemoryReporter::UNITS_BYTES, + GetStylesheetCacheSize, + "Memory used for some built-in style sheets.") NS_IMPL_ISUPPORTS1(nsLayoutStylesheetCache, nsIObserver) diff --git a/netwerk/cache/nsCacheService.h b/netwerk/cache/nsCacheService.h index ae30af28f17..713726de226 100644 --- a/netwerk/cache/nsCacheService.h +++ b/netwerk/cache/nsCacheService.h @@ -137,8 +137,7 @@ public: static nsCacheService * GlobalInstance() { return gService; } - static - PRInt64 MemoryDeviceSize(); + static PRInt64 MemoryDeviceSize(); static nsresult DoomEntry(nsCacheEntry * entry); diff --git a/startupcache/StartupCache.cpp b/startupcache/StartupCache.cpp index 2d06b0b159a..2449a01de67 100644 --- a/startupcache/StartupCache.cpp +++ b/startupcache/StartupCache.cpp @@ -95,13 +95,12 @@ GetStartupCacheMappingSize() } NS_MEMORY_REPORTER_IMPLEMENT(StartupCacheMapping, - "explicit/startup-cache/mapping", - KIND_NONHEAP, - nsIMemoryReporter::UNITS_BYTES, - GetStartupCacheMappingSize, - "Memory used to hold the mapping of the startup " - "cache from file. This memory is likely to be " - "swapped out shortly after start-up.") + "explicit/startup-cache/mapping", + KIND_NONHEAP, + nsIMemoryReporter::UNITS_BYTES, + GetStartupCacheMappingSize, + "Memory used to hold the mapping of the startup cache from file. This " + "memory is likely to be swapped out shortly after start-up.") NS_MEMORY_REPORTER_MALLOC_SIZEOF_FUN(StartupCacheDataMallocSizeOf, "startup-cache/data") @@ -113,12 +112,11 @@ GetStartupCacheDataSize() } NS_MEMORY_REPORTER_IMPLEMENT(StartupCacheData, - "explicit/startup-cache/data", - KIND_HEAP, - nsIMemoryReporter::UNITS_BYTES, - GetStartupCacheDataSize, - "Memory used by the startup cache for things " - "other than the file mapping.") + "explicit/startup-cache/data", + KIND_HEAP, + nsIMemoryReporter::UNITS_BYTES, + GetStartupCacheDataSize, + "Memory used by the startup cache for things other than the file mapping.") static const char sStartupCacheName[] = "startupCache." SC_WORDSIZE "." SC_ENDIAN; static NS_DEFINE_CID(kZipReaderCID, NS_ZIPREADER_CID); diff --git a/toolkit/components/aboutmemory/content/aboutMemory.js b/toolkit/components/aboutmemory/content/aboutMemory.js index 1acb8e384e7..a6c2408c43e 100644 --- a/toolkit/components/aboutmemory/content/aboutMemory.js +++ b/toolkit/components/aboutmemory/content/aboutMemory.js @@ -220,7 +220,7 @@ function processMemoryReporters(aMgr, aIgnoreSingle, aIgnoreMulti, // gAssertionFailureMsgPrefix in their string representation. // // - We want to continue on when faced with exceptions thrown outside this - // file (i.e. in collectReports). + // file (e.g. within a multi-reporter). let str = aE.toString(); if (str.search(gAssertionFailureMsgPrefix) >= 0) { diff --git a/toolkit/components/places/History.cpp b/toolkit/components/places/History.cpp index 7e49ce67ad2..ca78439c1af 100644 --- a/toolkit/components/places/History.cpp +++ b/toolkit/components/places/History.cpp @@ -1434,18 +1434,17 @@ NS_MEMORY_REPORTER_MALLOC_SIZEOF_FUN(HistoryLinksHashtableMallocSizeOf, PRInt64 GetHistoryObserversSize() { History* history = History::GetService(); - if (!history) - return 0; - return history->SizeOfIncludingThis(HistoryLinksHashtableMallocSizeOf); + return history ? + history->SizeOfIncludingThis(HistoryLinksHashtableMallocSizeOf) : 0; } NS_MEMORY_REPORTER_IMPLEMENT(HistoryService, - "explicit/history-links-hashtable", - KIND_HEAP, - UNITS_BYTES, - GetHistoryObserversSize, - "Memory used by the hashtable of observers Places uses to notify objects of " - "changes to links' visited state.") + "explicit/history-links-hashtable", + KIND_HEAP, + UNITS_BYTES, + GetHistoryObserversSize, + "Memory used by the hashtable of observers Places uses to notify objects of " + "changes to links' visited state.") } // anonymous namespace diff --git a/xpcom/base/nsCycleCollector.cpp b/xpcom/base/nsCycleCollector.cpp index 598bdd13652..439a63ff8bc 100644 --- a/xpcom/base/nsCycleCollector.cpp +++ b/xpcom/base/nsCycleCollector.cpp @@ -3284,7 +3284,7 @@ nsCycleCollector::WasFreed(nsISupports *n) //////////////////////// static PRInt64 -ReportCycleCollectorMem() +GetCycleCollectorSize() { if (!sCollector) return 0; @@ -3300,7 +3300,7 @@ NS_MEMORY_REPORTER_IMPLEMENT(CycleCollector, "explicit/cycle-collector", KIND_HEAP, UNITS_BYTES, - ReportCycleCollectorMem, + GetCycleCollectorSize, "Memory used by the cycle collector. This " "includes the cycle collector structure, the " "purple buffer, the graph, and the white nodes. " diff --git a/xpcom/base/nsMemoryReporterManager.cpp b/xpcom/base/nsMemoryReporterManager.cpp index 35d596c6608..a63eb3cf177 100644 --- a/xpcom/base/nsMemoryReporterManager.cpp +++ b/xpcom/base/nsMemoryReporterManager.cpp @@ -48,19 +48,6 @@ using namespace mozilla; -static PRInt64 GetExplicit() -{ - nsCOMPtr mgr = do_GetService("@mozilla.org/memory-reporter-manager;1"); - if (mgr == nsnull) - return (PRInt64)-1; - - PRInt64 n; - nsresult rv = mgr->GetExplicit(&n); - NS_ENSURE_SUCCESS(rv, rv); - - return n; -} - #if defined(MOZ_MEMORY) # define HAVE_JEMALLOC_STATS 1 # include "jemalloc.h" @@ -73,24 +60,22 @@ static PRInt64 GetExplicit() static PRInt64 GetHardPageFaults() { - struct rusage usage; - int err = getrusage(RUSAGE_SELF, &usage); - if (err != 0) { - return PRInt64(-1); - } - - return usage.ru_majflt; + struct rusage usage; + int err = getrusage(RUSAGE_SELF, &usage); + if (err != 0) { + return PRInt64(-1); + } + return usage.ru_majflt; } static PRInt64 GetSoftPageFaults() { - struct rusage usage; - int err = getrusage(RUSAGE_SELF, &usage); - if (err != 0) { - return PRInt64(-1); - } - - return usage.ru_minflt; + struct rusage usage; + int err = getrusage(RUSAGE_SELF, &usage); + if (err != 0) { + return PRInt64(-1); + } + return usage.ru_minflt; } #endif @@ -234,14 +219,25 @@ static PRInt64 GetResident() static PRInt64 GetVsize() { - MEMORYSTATUSEX s; - s.dwLength = sizeof(s); + MEMORYSTATUSEX s; + s.dwLength = sizeof(s); - bool success = GlobalMemoryStatusEx(&s); - if (!success) - return -1; + bool success = GlobalMemoryStatusEx(&s); + if (!success) + return -1; - return s.ullTotalVirtual - s.ullAvailVirtual; + return s.ullTotalVirtual - s.ullAvailVirtual; +} + +static PRInt64 GetResident() +{ + PROCESS_MEMORY_COUNTERS pmc; + pmc.cb = sizeof(PROCESS_MEMORY_COUNTERS); + + if (!GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc))) + return (PRInt64) -1; + + return pmc.WorkingSetSize; } static PRInt64 GetPrivate() @@ -265,17 +261,6 @@ NS_MEMORY_REPORTER_IMPLEMENT(Private, "is committed and marked MEM_PRIVATE, data that is not mapped, and " "executable pages that have been written to.") -static PRInt64 GetResident() -{ - PROCESS_MEMORY_COUNTERS pmc; - pmc.cb = sizeof(PROCESS_MEMORY_COUNTERS); - - if (!GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc))) - return (PRInt64) -1; - - return pmc.WorkingSetSize; -} - #else static PRInt64 GetResident() @@ -298,6 +283,18 @@ NS_MEMORY_REPORTER_IMPLEMENT(Vsize, "limited use on Mac, where processes share huge amounts of memory with one " "another. But even on other operating systems, 'resident' is a much better " "measure of the memory resources used by the process.") + +NS_MEMORY_REPORTER_IMPLEMENT(Resident, + "resident", + KIND_OTHER, + UNITS_BYTES, + GetResident, + "Memory mapped by the process that is present in physical memory, " + "also known as the resident set size (RSS). This is the best single " + "figure to use when considering the memory resources used by the process, " + "but it depends both on other processes being run and details of the OS " + "kernel and so is best used for comparing the memory usage of a single " + "process at different points in time.") #endif #if defined(XP_LINUX) || defined(XP_MACOSX) || defined(SOLARIS) @@ -333,27 +330,6 @@ NS_MEMORY_REPORTER_IMPLEMENT(PageFaultsHard, "so hard page faults a second.") #endif -NS_MEMORY_REPORTER_IMPLEMENT(Explicit, - "explicit", - KIND_OTHER, - UNITS_BYTES, - GetExplicit, - "This is the same measurement as the root of the 'explicit' tree. " - "However, it is measured at a different time and so gives slightly " - "different results.") - -NS_MEMORY_REPORTER_IMPLEMENT(Resident, - "resident", - KIND_OTHER, - UNITS_BYTES, - GetResident, - "Memory mapped by the process that is present in physical memory, " - "also known as the resident set size (RSS). This is the best single " - "figure to use when considering the memory resources used by the process, " - "but it depends both on other processes being run and details of the OS " - "kernel and so is best used for comparing the memory usage of a single " - "process at different points in time.") - /** ** memory reporter implementation for jemalloc and OSX malloc, ** to obtain info on total memory in use (that we know about, @@ -519,6 +495,28 @@ NS_MEMORY_REPORTER_IMPLEMENT(HeapAllocated, "application because the allocator regularly rounds up request sizes. (The " "exact amount requested is not recorded.)") +static PRInt64 GetExplicit() +{ + nsCOMPtr mgr = do_GetService("@mozilla.org/memory-reporter-manager;1"); + if (mgr == nsnull) + return (PRInt64)-1; + + PRInt64 n; + nsresult rv = mgr->GetExplicit(&n); + NS_ENSURE_SUCCESS(rv, rv); + + return n; +} + +NS_MEMORY_REPORTER_IMPLEMENT(Explicit, + "explicit", + KIND_OTHER, + UNITS_BYTES, + GetExplicit, + "This is the same measurement as the root of the 'explicit' tree. " + "However, it is measured at a different time and so gives slightly " + "different results.") + NS_MEMORY_REPORTER_MALLOC_SIZEOF_FUN(AtomTableMallocSizeOf, "atom-table") static PRInt64 GetAtomTableSize() {