Bug 976024 - Track Unique Set Size in the Developer HUD. r=21, r=njn

This commit is contained in:
Jan Keromnes 2014-06-13 06:38:00 +02:00
parent 0377b0bd09
commit a1f942ae7d
5 changed files with 90 additions and 49 deletions

View File

@ -508,6 +508,8 @@ let memoryWatcher = {
_fronts: new Map(),
_timers: new Map(),
_watching: {
uss: false,
appmemory: false,
jsobjects: false,
jsstrings: false,
jsother: false,
@ -525,60 +527,72 @@ let memoryWatcher = {
let category = key;
SettingsListener.observe('hud.' + category, false, watch => {
watching[category] = watch;
this.update();
});
}
},
SettingsListener.observe('hud.appmemory', false, enabled => {
if (this._active = enabled) {
for (let target of this._fronts.keys()) {
this.measure(target);
}
} else {
for (let target of this._fronts.keys()) {
clearTimeout(this._timers.get(target));
target.clear({name: 'memory'});
}
update: function mw_update() {
let watching = this._watching;
let active = watching.memory || watching.uss;
if (this._active) {
for (let target of this._fronts.keys()) {
if (!watching.appmemory) target.clear({name: 'memory'});
if (!watching.uss) target.clear({name: 'uss'});
if (!active) clearTimeout(this._timers.get(target));
}
});
} else if (active) {
for (let target of this._fronts.keys()) {
this.measure(target);
}
}
this._active = active;
},
measure: function mw_measure(target) {
// TODO Also track USS (bug #976024).
let watch = this._watching;
let front = this._fronts.get(target);
front.measure().then((data) => {
if (watch.uss) {
front.residentUnique().then(value => {
target.update({name: 'uss', value: value});
}, err => {
console.error(err);
});
}
let total = 0;
if (watch.jsobjects) {
total += parseInt(data.jsObjectsSize);
}
if (watch.jsstrings) {
total += parseInt(data.jsStringsSize);
}
if (watch.jsother) {
total += parseInt(data.jsOtherSize);
}
if (watch.dom) {
total += parseInt(data.domSize);
}
if (watch.style) {
total += parseInt(data.styleSize);
}
if (watch.other) {
total += parseInt(data.otherSize);
}
// TODO Also count images size (bug #976007).
if (watch.appmemory) {
front.measure().then(data => {
let total = 0;
if (watch.jsobjects) {
total += parseInt(data.jsObjectsSize);
}
if (watch.jsstrings) {
total += parseInt(data.jsStringsSize);
}
if (watch.jsother) {
total += parseInt(data.jsOtherSize);
}
if (watch.dom) {
total += parseInt(data.domSize);
}
if (watch.style) {
total += parseInt(data.styleSize);
}
if (watch.other) {
total += parseInt(data.otherSize);
}
// TODO Also count images size (bug #976007).
target.update({name: 'memory', value: total});
let duration = parseInt(data.jsMilliseconds) + parseInt(data.nonJSMilliseconds);
let timer = setTimeout(() => this.measure(target), 100 * duration);
this._timers.set(target, timer);
}, (err) => {
console.error(err);
});
target.update({name: 'memory', value: total});
}, err => {
console.error(err);
});
}
let timer = setTimeout(() => this.measure(target), 300);
this._timers.set(target, timer);
},
trackTarget: function mw_trackTarget(target) {

View File

@ -70,6 +70,13 @@ let MemoryActor = protocol.ActorClass({
}, {
request: {},
response: RetVal("json"),
}),
residentUnique: method(function() {
return this._mgr.residentUnique;
}, {
request: {},
response: { value: RetVal("number") }
})
});

View File

@ -17,7 +17,7 @@ interface nsISimpleEnumerator;
* reporter.
*/
[scriptable, function, uuid(3a61be3b-b93b-461a-a4f8-388214f558b1)]
[scriptable, function, uuid(62ef0e1c-dbd6-11e3-aa75-3c970e9f4238)]
interface nsIMemoryReporterCallback : nsISupports
{
/*
@ -311,6 +311,8 @@ interface nsIMemoryReporterManager : nsISupports
* |residentFast|, and so |resident| and |residentFast| should not be used
* together.
*
* |residentUnique| (UNITS_BYTES) The unique set size (a.k.a. USS).
*
* |heapAllocated| (UNITS_BYTES) Memory mapped by the heap allocator.
*
* |heapOverheadRatio| (UNITS_PERCENTAGE) In the heap allocator, this is the
@ -346,6 +348,7 @@ interface nsIMemoryReporterManager : nsISupports
readonly attribute int64_t vsizeMaxContiguous;
readonly attribute int64_t resident;
readonly attribute int64_t residentFast;
readonly attribute int64_t residentUnique;
readonly attribute int64_t heapAllocated;
readonly attribute int64_t heapOverheadRatio;

View File

@ -110,6 +110,12 @@ ResidentFastDistinguishedAmount(int64_t* aN)
}
#define HAVE_RESIDENT_UNIQUE_REPORTER
static nsresult
ResidentUniqueDistinguishedAmount(int64_t* aN)
{
return GetProcSelfSmapsPrivate(aN);
}
class ResidentUniqueReporter MOZ_FINAL : public nsIMemoryReporter
{
public:
@ -119,7 +125,7 @@ public:
nsISupports* aData)
{
int64_t amount = 0;
nsresult rv = GetProcSelfSmapsPrivate(&amount);
nsresult rv = ResidentUniqueDistinguishedAmount(&amount);
NS_ENSURE_SUCCESS(rv, rv);
return MOZ_COLLECT_REPORT(
@ -1556,16 +1562,29 @@ nsMemoryReporterManager::ResidentFast()
#endif
}
#if defined(XP_LINUX)
NS_IMETHODIMP
nsMemoryReporterManager::GetResidentUnique(int64_t* aAmount)
{
#ifdef HAVE_RESIDENT_UNIQUE_REPORTER
return ResidentUniqueDistinguishedAmount(aAmount);
#else
*aAmount = 0;
return NS_ERROR_NOT_AVAILABLE;
#endif
}
/*static*/ int64_t
nsMemoryReporterManager::ResidentUnique()
{
#ifdef HAVE_RESIDENT_UNIQUE_REPORTER
int64_t amount = 0;
nsresult rv = GetProcSelfSmapsPrivate(&amount);
nsresult rv = ResidentUniqueDistinguishedAmount(&amount);
NS_ENSURE_SUCCESS(rv, 0);
return amount;
}
#else
return 0;
#endif
}
NS_IMETHODIMP
nsMemoryReporterManager::GetHeapAllocated(int64_t* aAmount)

View File

@ -150,11 +150,9 @@ public:
// when debugging transient memory spikes with printf instrumentation.
static int64_t ResidentFast();
#if defined(XP_LINUX)
// Convenience function to get USS easily from other code. This is useful
// when debugging unshared memory pages for forked processes.
static int64_t ResidentUnique();
#endif
// Functions that measure per-tab memory consumption.
struct SizeOfTabFns