Skip to content

Commit

Permalink
DevTools: Show all OOPIFs JS memory in performance monitor.
Browse files Browse the repository at this point in the history
Change-Id: Iea75bf9bce3d1409122b94154c262667696a95f4
Reviewed-on: https://chromium-review.googlesource.com/985966
Commit-Queue: Alexei Filippov <alph@chromium.org>
Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#547536}
  • Loading branch information
a1ph authored and Commit Bot committed Apr 2, 2018
1 parent a5f7ba1 commit 151237c
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Tests list of performance metrics and that memory is not double counted.


Metrics reported:
AudioHandlers
Documents
DomContentLoaded
FirstMeaningfulPaint
Frames
JSEventListeners
JSHeapTotalSize
JSHeapUsedSize
LayoutCount
LayoutDuration
LayoutObjects
MediaKeySessions
MediaKeys
NavigationStart
Nodes
PausableObjects
RTCPeerConnections
RecalcStyleCount
RecalcStyleDuration
ResourceFetchers
Resources
ScriptDuration
ScriptPromises
TaskDuration
Timestamp
UACSSResources
V8PerContextDatas
WorkerGlobalScopes

Targets after navigate
Main
iframe.html
inner-iframe.html
inner-iframe.html

metrics size is twice smaller than simple sum: true

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

(async function() {
TestRunner.addResult(`Tests list of performance metrics and that memory is not double counted.\n`);

const model = SDK.targetManager.mainTarget().model(SDK.PerformanceMetricsModel);
await model.enable();
let metrics = (await model.requestMetrics()).metrics;

TestRunner.addResult('\nMetrics reported:');
TestRunner.addResults(metrics.keysArray().sort());

await TestRunner.navigatePromise('resources/page.html');
TestRunner.addResult('\nTargets after navigate');
TestRunner.addResults(SDK.targetManager.targets().map(t => t.name()).sort());

let lastTotal, total;
do {
metrics = (await model.requestMetrics()).metrics;
lastTotal = total;
total = 0;
for (const m of SDK.targetManager.models(SDK.RuntimeModel))
total += (await m.heapUsage()).totalSize;
} while (total !== lastTotal);

TestRunner.addResult('\nmetrics size is twice smaller than simple sum: ' +
(metrics.get('JSHeapTotalSize') * 2 === total));

TestRunner.completeTest();
})();
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,31 @@ SDK.PerformanceMetricsModel = class extends SDK.SDKModel {
}
metrics.set(metric.name, value);
}
const totalMemoryUsage = await this._requestTotalMemory();
metrics.set('JSHeapUsedSize', totalMemoryUsage.usedSize);
metrics.set('JSHeapTotalSize', totalMemoryUsage.totalSize);
return {metrics: metrics, timestamp: timestamp};
}

/**
* @return {!Promise<!{usedSize: number, totalSize: number}>}
*/
async _requestTotalMemory() {
const models = SDK.targetManager.models(SDK.RuntimeModel);
const isolates = await Promise.all(models.map(model => model.isolateId()));
/** @type {!Map<string, !SDK.RuntimeModel>} */
const modelsByIsolate = new Map();
for (let i = 0; i < isolates.length; ++i)
modelsByIsolate.set(isolates[i], models[i]);
const usages = await Promise.all(modelsByIsolate.valuesArray().map(model => model.heapUsage()));
let totalSize = 0;
let usedSize = 0;
for (const usage of usages) {
totalSize += usage ? usage.totalSize : 0;
usedSize += usage ? usage.usedSize : 0;
}
return {totalSize, usedSize};
}
};

/** @enum {symbol} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ Timeline.PerformanceMonitor.MetricIndicator = class {
case Timeline.PerformanceMonitor.Format.Percent:
return value.toLocaleString('en-US', {maximumFractionDigits: 1, style: 'percent'});
case Timeline.PerformanceMonitor.Format.Bytes:
return Common.UIString('%s\xa0MB', (value / 1e6).toLocaleString('en-US', {maximumFractionDigits: 1}));
return Number.bytesToString(value);
default:
return value.toLocaleString('en-US', {maximumFractionDigits: 1});
}
Expand Down

0 comments on commit 151237c

Please sign in to comment.