Bug 1291970 (part 1) - Use MOZ_MUST_USE in nsMemoryReporterManager. r=erahm.

--HG--
extra : rebase_source : 11223e1aadb08c2ce71f783d68b37c135fe4bee5
This commit is contained in:
Nicholas Nethercote 2016-08-04 12:14:14 +10:00
parent f9f95c59d4
commit 9d5a878581
3 changed files with 50 additions and 41 deletions

View File

@ -450,6 +450,9 @@ typedef nsIMemoryReporterCallback nsIHandleReportCallback;
namespace mozilla {
// All the following registration/unregistration functions don't use
// MOZ_MUST_USE because ignoring failures is common and reasonable.
// Register a memory reporter. The manager service will hold a strong
// reference to this reporter.
XPCOM_API(nsresult) RegisterStrongMemoryReporter(nsIMemoryReporter* aReporter);
@ -473,7 +476,6 @@ XPCOM_API(nsresult) UnregisterWeakMemoryReporter(nsIMemoryReporter* aReporter);
// manager.
typedef int64_t (*InfallibleAmountFn)();
typedef nsresult (*FallibleAmountFn)(int64_t* aAmount);
#define DECL_REGISTER_DISTINGUISHED_AMOUNT(kind, name) \
nsresult Register##name##DistinguishedAmount(kind##AmountFn aAmountFn);

View File

@ -52,7 +52,7 @@ using namespace mozilla;
#include <string.h>
#include <stdlib.h>
static nsresult
static MOZ_MUST_USE nsresult
GetProcSelfStatmField(int aField, int64_t* aN)
{
// There are more than two fields, but we're only interested in the first
@ -72,7 +72,7 @@ GetProcSelfStatmField(int aField, int64_t* aN)
return NS_ERROR_FAILURE;
}
static nsresult
static MOZ_MUST_USE nsresult
GetProcSelfSmapsPrivate(int64_t* aN)
{
// You might be tempted to calculate USS by subtracting the "shared" value
@ -127,26 +127,26 @@ GetProcSelfSmapsPrivate(int64_t* aN)
}
#define HAVE_VSIZE_AND_RESIDENT_REPORTERS 1
static nsresult
static MOZ_MUST_USE nsresult
VsizeDistinguishedAmount(int64_t* aN)
{
return GetProcSelfStatmField(0, aN);
}
static nsresult
static MOZ_MUST_USE nsresult
ResidentDistinguishedAmount(int64_t* aN)
{
return GetProcSelfStatmField(1, aN);
}
static nsresult
static MOZ_MUST_USE nsresult
ResidentFastDistinguishedAmount(int64_t* aN)
{
return ResidentDistinguishedAmount(aN);
}
#define HAVE_RESIDENT_UNIQUE_REPORTER 1
static nsresult
static MOZ_MUST_USE nsresult
ResidentUniqueDistinguishedAmount(int64_t* aN)
{
return GetProcSelfSmapsPrivate(aN);
@ -154,7 +154,7 @@ ResidentUniqueDistinguishedAmount(int64_t* aN)
#ifdef HAVE_MALLINFO
#define HAVE_SYSTEM_HEAP_REPORTER 1
nsresult
static MOZ_MUST_USE nsresult
SystemHeapSize(int64_t* aSizeOut)
{
struct mallinfo info = mallinfo();
@ -209,7 +209,7 @@ SystemHeapSize(int64_t* aSizeOut)
#define KP_RSS(kp) (kp.p_vm_rssize * getpagesize())
#endif
static nsresult
static MOZ_MUST_USE nsresult
GetKinfoProcSelf(KINFO_PROC* aProc)
{
int mib[] = {
@ -231,7 +231,7 @@ GetKinfoProcSelf(KINFO_PROC* aProc)
}
#define HAVE_VSIZE_AND_RESIDENT_REPORTERS 1
static nsresult
static MOZ_MUST_USE nsresult
VsizeDistinguishedAmount(int64_t* aN)
{
KINFO_PROC proc;
@ -242,7 +242,7 @@ VsizeDistinguishedAmount(int64_t* aN)
return rv;
}
static nsresult
static MOZ_MUST_USE nsresult
ResidentDistinguishedAmount(int64_t* aN)
{
KINFO_PROC proc;
@ -253,7 +253,7 @@ ResidentDistinguishedAmount(int64_t* aN)
return rv;
}
static nsresult
static MOZ_MUST_USE nsresult
ResidentFastDistinguishedAmount(int64_t* aN)
{
return ResidentDistinguishedAmount(aN);
@ -263,7 +263,7 @@ ResidentFastDistinguishedAmount(int64_t* aN)
#include <libutil.h>
#include <algorithm>
static nsresult
static MOZ_MUST_USE nsresult
GetKinfoVmentrySelf(int64_t* aPrss, uint64_t* aMaxreg)
{
int cnt;
@ -294,7 +294,7 @@ GetKinfoVmentrySelf(int64_t* aPrss, uint64_t* aMaxreg)
}
#define HAVE_PRIVATE_REPORTER 1
static nsresult
static MOZ_MUST_USE nsresult
PrivateDistinguishedAmount(int64_t* aN)
{
int64_t priv;
@ -305,7 +305,7 @@ PrivateDistinguishedAmount(int64_t* aN)
}
#define HAVE_VSIZE_MAX_CONTIGUOUS_REPORTER 1
static nsresult
static MOZ_MUST_USE nsresult
VsizeMaxContiguousDistinguishedAmount(int64_t* aN)
{
uint64_t biggestRegion;
@ -323,7 +323,8 @@ VsizeMaxContiguousDistinguishedAmount(int64_t* aN)
#include <fcntl.h>
#include <unistd.h>
static void XMappingIter(int64_t& aVsize, int64_t& aResident)
static void
XMappingIter(int64_t& aVsize, int64_t& aResident)
{
aVsize = -1;
aResident = -1;
@ -365,7 +366,7 @@ static void XMappingIter(int64_t& aVsize, int64_t& aResident)
}
#define HAVE_VSIZE_AND_RESIDENT_REPORTERS 1
static nsresult
static MOZ_MUST_USE nsresult
VsizeDistinguishedAmount(int64_t* aN)
{
int64_t vsize, resident;
@ -377,7 +378,7 @@ VsizeDistinguishedAmount(int64_t* aN)
return NS_OK;
}
static nsresult
static MOZ_MUST_USE nsresult
ResidentDistinguishedAmount(int64_t* aN)
{
int64_t vsize, resident;
@ -389,7 +390,7 @@ ResidentDistinguishedAmount(int64_t* aN)
return NS_OK;
}
static nsresult
static MOZ_MUST_USE nsresult
ResidentFastDistinguishedAmount(int64_t* aN)
{
return ResidentDistinguishedAmount(aN);
@ -403,7 +404,7 @@ ResidentFastDistinguishedAmount(int64_t* aN)
#include <mach/task.h>
#include <sys/sysctl.h>
static bool
static MOZ_MUST_USE bool
GetTaskBasicInfo(struct task_basic_info* aTi)
{
mach_msg_type_number_t count = TASK_BASIC_INFO_COUNT;
@ -416,7 +417,7 @@ GetTaskBasicInfo(struct task_basic_info* aTi)
// absurdly high, eg. 2GB+ even at start-up. But both 'top' and 'ps' report
// it, so we might as well too.
#define HAVE_VSIZE_AND_RESIDENT_REPORTERS 1
static nsresult
static MOZ_MUST_USE nsresult
VsizeDistinguishedAmount(int64_t* aN)
{
task_basic_info ti;
@ -434,7 +435,7 @@ VsizeDistinguishedAmount(int64_t* aN)
//
// Purging these pages can take a long time for some users (see bug 789975),
// so we provide the option to get the RSS without purging first.
static nsresult
static MOZ_MUST_USE nsresult
ResidentDistinguishedAmountHelper(int64_t* aN, bool aDoPurge)
{
#ifdef HAVE_JEMALLOC_STATS
@ -454,13 +455,13 @@ ResidentDistinguishedAmountHelper(int64_t* aN, bool aDoPurge)
return NS_OK;
}
static nsresult
static MOZ_MUST_USE nsresult
ResidentFastDistinguishedAmount(int64_t* aN)
{
return ResidentDistinguishedAmountHelper(aN, /* doPurge = */ false);
}
static nsresult
static MOZ_MUST_USE nsresult
ResidentDistinguishedAmount(int64_t* aN)
{
return ResidentDistinguishedAmountHelper(aN, /* doPurge = */ true);
@ -494,7 +495,7 @@ InSharedRegion(mach_vm_address_t aAddr, cpu_type_t aType)
return base <= aAddr && aAddr < (base + size);
}
static nsresult
static MOZ_MUST_USE nsresult
ResidentUniqueDistinguishedAmount(int64_t* aN)
{
if (!aN) {
@ -567,7 +568,7 @@ ResidentUniqueDistinguishedAmount(int64_t* aN)
#include <algorithm>
#define HAVE_VSIZE_AND_RESIDENT_REPORTERS 1
static nsresult
static MOZ_MUST_USE nsresult
VsizeDistinguishedAmount(int64_t* aN)
{
MEMORYSTATUSEX s;
@ -581,7 +582,7 @@ VsizeDistinguishedAmount(int64_t* aN)
return NS_OK;
}
static nsresult
static MOZ_MUST_USE nsresult
ResidentDistinguishedAmount(int64_t* aN)
{
PROCESS_MEMORY_COUNTERS pmc;
@ -595,7 +596,7 @@ ResidentDistinguishedAmount(int64_t* aN)
return NS_OK;
}
static nsresult
static MOZ_MUST_USE nsresult
ResidentFastDistinguishedAmount(int64_t* aN)
{
return ResidentDistinguishedAmount(aN);
@ -603,7 +604,7 @@ ResidentFastDistinguishedAmount(int64_t* aN)
#define HAVE_RESIDENT_UNIQUE_REPORTER 1
static nsresult
static MOZ_MUST_USE nsresult
ResidentUniqueDistinguishedAmount(int64_t* aN)
{
// Determine how many entries we need.
@ -651,7 +652,7 @@ ResidentUniqueDistinguishedAmount(int64_t* aN)
}
#define HAVE_VSIZE_MAX_CONTIGUOUS_REPORTER 1
static nsresult
static MOZ_MUST_USE nsresult
VsizeMaxContiguousDistinguishedAmount(int64_t* aN)
{
SIZE_T biggestRegion = 0;
@ -680,7 +681,7 @@ VsizeMaxContiguousDistinguishedAmount(int64_t* aN)
}
#define HAVE_PRIVATE_REPORTER 1
static nsresult
static MOZ_MUST_USE nsresult
PrivateDistinguishedAmount(int64_t* aN)
{
PROCESS_MEMORY_COUNTERS_EX pmcex;
@ -699,7 +700,7 @@ PrivateDistinguishedAmount(int64_t* aN)
// Windows can have multiple separate heaps. During testing there were multiple
// heaps present but the non-default ones had sizes no more than a few 10s of
// KiBs. So we combine their sizes into a single measurement.
nsresult
static MOZ_MUST_USE nsresult
SystemHeapSize(int64_t* aSizeOut)
{
// Get the number of heaps.
@ -1143,7 +1144,7 @@ NS_IMPL_ISUPPORTS(SystemHeapReporter, nsIMemoryReporter)
#define HAVE_RESIDENT_PEAK_REPORTER 1
static nsresult
static MOZ_MUST_USE nsresult
ResidentPeakDistinguishedAmount(int64_t* aN)
{
struct rusage usage;
@ -1222,7 +1223,7 @@ public:
};
NS_IMPL_ISUPPORTS(PageFaultsSoftReporter, nsIMemoryReporter)
static nsresult
static MOZ_MUST_USE nsresult
PageFaultsHardDistinguishedAmount(int64_t* aAmount)
{
struct rusage usage;
@ -2391,7 +2392,7 @@ nsMemoryReporterManager::GetHeapOverheadFraction(int64_t* aAmount)
#endif
}
static nsresult
static MOZ_MUST_USE nsresult
GetInfallibleAmount(InfallibleAmountFn aAmountFn, int64_t* aAmount)
{
if (aAmountFn) {
@ -2625,7 +2626,7 @@ nsMemoryReporterManager::SizeOfTab(mozIDOMWindowProxy* aTopWindow,
namespace mozilla {
#define GET_MEMORY_REPORTER_MANAGER(mgr) \
RefPtr<nsMemoryReporterManager> mgr = \
RefPtr<nsMemoryReporterManager> mgr = \
nsMemoryReporterManager::GetOrCreate(); \
if (!mgr) { \
return NS_ERROR_FAILURE; \
@ -2690,6 +2691,8 @@ UnregisterWeakMemoryReporter(nsIMemoryReporter* aReporter)
return NS_OK; \
}
// Macro for generating functions that unregister distinguished amount
// functions with the memory reporter manager.
#define DEFINE_UNREGISTER_DISTINGUISHED_AMOUNT(name) \
nsresult \
Unregister##name##DistinguishedAmount() \

View File

@ -183,9 +183,12 @@ public:
SizeOfTabFns mSizeOfTabFns;
private:
nsresult RegisterReporterHelper(nsIMemoryReporter* aReporter,
bool aForce, bool aStrongRef, bool aIsAsync);
nsresult StartGettingReports();
MOZ_MUST_USE nsresult
RegisterReporterHelper(nsIMemoryReporter* aReporter,
bool aForce, bool aStrongRef, bool aIsAsync);
MOZ_MUST_USE nsresult StartGettingReports();
// No MOZ_MUST_USE here because ignoring the result is common and reasonable.
nsresult FinishReporting();
void DispatchReporter(nsIMemoryReporter* aReporter, bool aIsAsync,
@ -273,8 +276,9 @@ private:
PendingReportersState* mPendingReportersState;
PendingProcessesState* GetStateForGeneration(uint32_t aGeneration);
static bool StartChildReport(mozilla::dom::ContentParent* aChild,
const PendingProcessesState* aState);
static MOZ_MUST_USE bool
StartChildReport(mozilla::dom::ContentParent* aChild,
const PendingProcessesState* aState);
};
#define NS_MEMORY_REPORTER_MANAGER_CID \