mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 02:14:43 +00:00
Bug 828844 - Add a "system-heap-allocated" memory report on Linux. r=glandium.
This gives zero when jemalloc is enabled and non-zero when jemalloc is disabled (e.g. I got 83 MiB at start-up, which sounds plausible). --HG-- extra : rebase_source : f39a15472d48643f57a77f1df03e4a29543d0867
This commit is contained in:
parent
b587e1f835
commit
01a073b5a2
@ -48,6 +48,7 @@ using namespace mozilla;
|
||||
|
||||
#if defined(XP_LINUX)
|
||||
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
@ -175,6 +176,25 @@ public:
|
||||
};
|
||||
NS_IMPL_ISUPPORTS(ResidentUniqueReporter, nsIMemoryReporter)
|
||||
|
||||
#define HAVE_SYSTEM_HEAP_REPORTER 1
|
||||
size_t
|
||||
SystemHeapSize()
|
||||
{
|
||||
struct mallinfo info = mallinfo();
|
||||
|
||||
// The documentation in the glibc man page makes it sound like |uordblks|
|
||||
// would suffice, but that only gets the small allocations that are put in
|
||||
// the brk heap. We need |hblkhd| as well to get the larger allocations
|
||||
// that are mmapped.
|
||||
//
|
||||
// The fields in |struct mallinfo| are all |int|, <sigh>, so it is
|
||||
// unreliable if memory usage gets high. However, the system heap size on
|
||||
// Linux should usually be zero (so long as jemalloc is enabled) so that
|
||||
// shouldn't be a problem. Nonetheless, cast the |int|s to |size_t| before
|
||||
// adding them to provide a small amount of extra overflow protection.
|
||||
return size_t(info.hblkhd) + size_t(info.uordblks);
|
||||
}
|
||||
|
||||
#elif defined(__DragonFly__) || defined(__FreeBSD__) \
|
||||
|| defined(__NetBSD__) || defined(__OpenBSD__) \
|
||||
|| defined(__FreeBSD_kernel__)
|
||||
@ -803,6 +823,32 @@ NS_IMPL_ISUPPORTS(ResidentReporter, nsIMemoryReporter)
|
||||
|
||||
#endif // HAVE_VSIZE_AND_RESIDENT_REPORTERS
|
||||
|
||||
#ifdef HAVE_SYSTEM_HEAP_REPORTER
|
||||
|
||||
class SystemHeapReporter final : public nsIMemoryReporter
|
||||
{
|
||||
~SystemHeapReporter() {}
|
||||
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_METHOD CollectReports(nsIHandleReportCallback* aHandleReport,
|
||||
nsISupports* aData, bool aAnonymize) override
|
||||
{
|
||||
int64_t amount = SystemHeapSize();
|
||||
|
||||
return MOZ_COLLECT_REPORT(
|
||||
"system-heap-allocated", KIND_OTHER, UNITS_BYTES, amount,
|
||||
"Memory used by the system allocator that is currently allocated to the "
|
||||
"application. This is distinct from the jemalloc heap that Firefox uses for "
|
||||
"most or all of its heap allocations. Ideally this number is zero, but "
|
||||
"on some platforms we cannot force every heap allocation through jemalloc.");
|
||||
}
|
||||
};
|
||||
NS_IMPL_ISUPPORTS(SystemHeapReporter, nsIMemoryReporter)
|
||||
|
||||
#endif // HAVE_SYSTEM_HEAP_REPORTER
|
||||
|
||||
#ifdef XP_UNIX
|
||||
|
||||
#include <sys/resource.h>
|
||||
@ -1221,6 +1267,10 @@ nsMemoryReporterManager::Init()
|
||||
RegisterStrongReporter(new PrivateReporter());
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYSTEM_HEAP_REPORTER
|
||||
RegisterStrongReporter(new SystemHeapReporter());
|
||||
#endif
|
||||
|
||||
RegisterStrongReporter(new AtomTablesReporter());
|
||||
|
||||
#ifdef DEBUG
|
||||
|
Loading…
Reference in New Issue
Block a user