v8/test/inspector/debugger/limit-size-of-collected-scripts.js
Alexei Filippov aaf3eb25f0 Reland "[inspector] Allow limiting the total size of collected scripts."
This is a reland of 5a61630d1d

Original change's description:
> [inspector] Allow limiting the total size of collected scripts.
>
> Introduces the setMaxCollectedScriptsSize Debugger protocol method.
> If the max size is set, the debugger will hold collected (not referenced by other v8 heap objects)
> scripts up to the specified total size of their sources.
>
> BUG=v8:8988
>
> Change-Id: I94d52866494102add91ca2d569a2044b08c9c593
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1518556
> Commit-Queue: Alexei Filippov <alph@chromium.org>
> Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#60227}

TBR=dgozman@chromium.org

Bug: v8:8988
Change-Id: I9b1db01856a43636c1eb8ad2ec36e3727353228d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1524668
Commit-Queue: Alexei Filippov <alph@chromium.org>
Reviewed-by: Pavel Feldman <pfeldman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60271}
2019-03-16 06:08:17 +00:00

43 lines
1.8 KiB
JavaScript

// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
let {session, contextGroup, Protocol} = InspectorTest.start(
'Checks that inspector does not retain old collected scripts.\n');
(async function main() {
InspectorTest.log('Limit scripts cache size to 1MB');
const maxScriptsCacheSize = 1e6;
Protocol.Debugger.enable({maxScriptsCacheSize});
const scriptIds = [];
Protocol.Debugger.onScriptParsed(message => scriptIds.push(message.params.scriptId));
InspectorTest.log('Generate 15 scripts 100KB each');
await Protocol.Runtime.evaluate({
expression: 'for (let i = 0; i < 15; ++i) eval(`"${new Array(5e4).fill("й").join("")}".length`);'});
await Protocol.HeapProfiler.collectGarbage();
const firstPhaseScripts = scriptIds.length;
InspectorTest.log('Generate 15 more scripts 100KB each');
await Protocol.Runtime.evaluate({
expression: 'for (let i = 0; i < 15; ++i) eval(`"${new Array(5e4).fill("й").join("")}".length`);'});
await Protocol.HeapProfiler.collectGarbage();
InspectorTest.log('Check that earlier scripts are gone');
InspectorTest.logMessage(`Total scripts size < 1KB: ${await sizeOfScripts(scriptIds.slice(0, firstPhaseScripts)) < 1e3}`);
InspectorTest.log('Check that some of the later scripts are still there');
InspectorTest.logMessage(`Total scripts size > 850KB: ${await sizeOfScripts(scriptIds) > 850e3}`);
InspectorTest.completeTest();
async function sizeOfScripts(scriptIds) {
let size = 0;
for (const scriptId of scriptIds) {
const result = await Protocol.Debugger.getScriptSource({scriptId});
size += result.result ? result.result.scriptSource.length * 2 : 0;
}
return size;
}
})();