зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1145007 (part 2) - Add a "resident-peak" distinguished amount and memory reporter on Unix. r=erahm.
--HG-- extra : rebase_source : 3fb7c2020d3abd29fdbf8042a0932b24d92b234b
This commit is contained in:
Родитель
1d7a94e346
Коммит
b5b1a4609e
|
@ -157,6 +157,7 @@
|
|||
"vsizeMaxContiguous",
|
||||
"resident",
|
||||
"residentFast",
|
||||
"residentPeak",
|
||||
"residentUnique",
|
||||
"heapAllocated",
|
||||
"heapOverheadRatio",
|
||||
|
|
|
@ -205,7 +205,7 @@ interface nsIFinishReportingCallback : nsISupports
|
|||
void callback(in nsISupports data);
|
||||
};
|
||||
|
||||
[scriptable, builtinclass, uuid(51e17609-e98a-47cc-9f95-095ef3c3823e)]
|
||||
[scriptable, builtinclass, uuid(5e4eaa5a-4808-4b97-8005-e7cdc4d73693)]
|
||||
interface nsIMemoryReporterManager : nsISupports
|
||||
{
|
||||
/*
|
||||
|
@ -344,6 +344,8 @@ interface nsIMemoryReporterManager : nsISupports
|
|||
* |residentFast|, and so |resident| and |residentFast| should not be used
|
||||
* together.
|
||||
*
|
||||
* |residentPeak| (UNITS_BYTES) The peak resident size.
|
||||
*
|
||||
* |residentUnique| (UNITS_BYTES) The unique set size (a.k.a. USS).
|
||||
*
|
||||
* |heapAllocated| (UNITS_BYTES) Memory mapped by the heap allocator.
|
||||
|
@ -381,6 +383,7 @@ interface nsIMemoryReporterManager : nsISupports
|
|||
readonly attribute int64_t vsizeMaxContiguous;
|
||||
readonly attribute int64_t resident;
|
||||
readonly attribute int64_t residentFast;
|
||||
readonly attribute int64_t residentPeak;
|
||||
readonly attribute int64_t residentUnique;
|
||||
|
||||
readonly attribute int64_t heapAllocated;
|
||||
|
|
|
@ -141,7 +141,7 @@ ResidentFastDistinguishedAmount(int64_t* aN)
|
|||
return ResidentDistinguishedAmount(aN);
|
||||
}
|
||||
|
||||
#define HAVE_RESIDENT_UNIQUE_REPORTER
|
||||
#define HAVE_RESIDENT_UNIQUE_REPORTER 1
|
||||
static nsresult
|
||||
ResidentUniqueDistinguishedAmount(int64_t* aN)
|
||||
{
|
||||
|
@ -291,7 +291,7 @@ GetKinfoVmentrySelf(int64_t* aPrss, uint64_t* aMaxreg)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
#define HAVE_PRIVATE_REPORTER
|
||||
#define HAVE_PRIVATE_REPORTER 1
|
||||
static nsresult
|
||||
PrivateDistinguishedAmount(int64_t* aN)
|
||||
{
|
||||
|
@ -529,7 +529,7 @@ VsizeMaxContiguousDistinguishedAmount(int64_t* aN)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
#define HAVE_PRIVATE_REPORTER
|
||||
#define HAVE_PRIVATE_REPORTER 1
|
||||
static nsresult
|
||||
PrivateDistinguishedAmount(int64_t* aN)
|
||||
{
|
||||
|
@ -804,6 +804,53 @@ NS_IMPL_ISUPPORTS(ResidentReporter, nsIMemoryReporter)
|
|||
|
||||
#include <sys/resource.h>
|
||||
|
||||
#define HAVE_RESIDENT_PEAK_REPORTER 1
|
||||
|
||||
static nsresult
|
||||
ResidentPeakDistinguishedAmount(int64_t* aN)
|
||||
{
|
||||
struct rusage usage;
|
||||
if (0 == getrusage(RUSAGE_SELF, &usage)) {
|
||||
// The units for ru_maxrrs:
|
||||
// - Mac: bytes
|
||||
// - Solaris: pages? But some sources it actually always returns 0, so
|
||||
// check for that
|
||||
// - Linux, {Net/Open/Free}BSD, DragonFly: KiB
|
||||
#ifdef XP_MACOSX
|
||||
*aN = usage.ru_maxrss;
|
||||
#elif defined(SOLARIS)
|
||||
*aN = usage.ru_maxrss * getpagesize();
|
||||
#else
|
||||
*aN = usage.ru_maxrss * 1024;
|
||||
#endif
|
||||
if (*aN > 0) {
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
class ResidentPeakReporter MOZ_FINAL : public nsIMemoryReporter
|
||||
{
|
||||
~ResidentPeakReporter() {}
|
||||
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_METHOD CollectReports(nsIHandleReportCallback* aHandleReport,
|
||||
nsISupports* aData, bool aAnonymize) MOZ_OVERRIDE
|
||||
{
|
||||
int64_t amount = 0;
|
||||
nsresult rv = ResidentPeakDistinguishedAmount(&amount);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return MOZ_COLLECT_REPORT(
|
||||
"resident-peak", KIND_OTHER, UNITS_BYTES, amount,
|
||||
"The peak 'resident' value for the lifetime of the process.");
|
||||
}
|
||||
};
|
||||
NS_IMPL_ISUPPORTS(ResidentPeakReporter, nsIMemoryReporter)
|
||||
|
||||
#define HAVE_PAGE_FAULT_REPORTERS 1
|
||||
|
||||
class PageFaultsSoftReporter MOZ_FINAL : public nsIMemoryReporter
|
||||
|
@ -880,7 +927,7 @@ public:
|
|||
};
|
||||
NS_IMPL_ISUPPORTS(PageFaultsHardReporter, nsIMemoryReporter)
|
||||
|
||||
#endif // HAVE_PAGE_FAULT_REPORTERS
|
||||
#endif // XP_UNIX
|
||||
|
||||
/**
|
||||
** memory reporter implementation for jemalloc and OSX malloc,
|
||||
|
@ -1154,6 +1201,10 @@ nsMemoryReporterManager::Init()
|
|||
RegisterStrongReporter(new VsizeMaxContiguousReporter());
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_RESIDENT_PEAK_REPORTER
|
||||
RegisterStrongReporter(new ResidentPeakReporter());
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_RESIDENT_UNIQUE_REPORTER
|
||||
RegisterStrongReporter(new ResidentUniqueReporter());
|
||||
#endif
|
||||
|
@ -1859,6 +1910,30 @@ nsMemoryReporterManager::ResidentFast()
|
|||
#endif
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMemoryReporterManager::GetResidentPeak(int64_t* aAmount)
|
||||
{
|
||||
#ifdef HAVE_RESIDENT_PEAK_REPORTER
|
||||
return ResidentPeakDistinguishedAmount(aAmount);
|
||||
#else
|
||||
*aAmount = 0;
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*static*/ int64_t
|
||||
nsMemoryReporterManager::ResidentPeak()
|
||||
{
|
||||
#ifdef HAVE_RESIDENT_PEAK_REPORTER
|
||||
int64_t amount = 0;
|
||||
nsresult rv = ResidentPeakDistinguishedAmount(&amount);
|
||||
NS_ENSURE_SUCCESS(rv, 0);
|
||||
return amount;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMemoryReporterManager::GetResidentUnique(int64_t* aAmount)
|
||||
{
|
||||
|
|
|
@ -151,6 +151,9 @@ public:
|
|||
// when debugging transient memory spikes with printf instrumentation.
|
||||
static int64_t ResidentFast();
|
||||
|
||||
// Convenience function to get peak RSS easily from other code.
|
||||
static int64_t ResidentPeak();
|
||||
|
||||
// Convenience function to get USS easily from other code. This is useful
|
||||
// when debugging unshared memory pages for forked processes.
|
||||
static int64_t ResidentUnique();
|
||||
|
|
Загрузка…
Ссылка в новой задаче