Commit 151237c0 authored by Alexei Filippov's avatar Alexei Filippov Committed by Commit Bot

DevTools: Show all OOPIFs JS memory in performance monitor.

Change-Id: Iea75bf9bce3d1409122b94154c262667696a95f4
Reviewed-on: https://chromium-review.googlesource.com/985966
Commit-Queue: Alexei Filippov <alph@chromium.org>
Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#547536}
parent a5f7ba11
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
// 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();
})();
...@@ -71,8 +71,31 @@ SDK.PerformanceMetricsModel = class extends SDK.SDKModel { ...@@ -71,8 +71,31 @@ SDK.PerformanceMetricsModel = class extends SDK.SDKModel {
} }
metrics.set(metric.name, value); 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 {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} */ /** @enum {symbol} */
......
...@@ -492,7 +492,7 @@ Timeline.PerformanceMonitor.MetricIndicator = class { ...@@ -492,7 +492,7 @@ Timeline.PerformanceMonitor.MetricIndicator = class {
case Timeline.PerformanceMonitor.Format.Percent: case Timeline.PerformanceMonitor.Format.Percent:
return value.toLocaleString('en-US', {maximumFractionDigits: 1, style: 'percent'}); return value.toLocaleString('en-US', {maximumFractionDigits: 1, style: 'percent'});
case Timeline.PerformanceMonitor.Format.Bytes: case Timeline.PerformanceMonitor.Format.Bytes:
return Common.UIString('%s\xa0MB', (value / 1e6).toLocaleString('en-US', {maximumFractionDigits: 1})); return Number.bytesToString(value);
default: default:
return value.toLocaleString('en-US', {maximumFractionDigits: 1}); return value.toLocaleString('en-US', {maximumFractionDigits: 1});
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment