Commit 347700c7 authored by Clemens Backes's avatar Clemens Backes Committed by Commit Bot

Reland "[inspector] Check that wasm wrappers appear in profiles"

This is a reland of 78defee4

Original change's description:
> [inspector] Check that wasm wrappers appear in profiles
>
> This extends the existing wasm profiling test to also check that
> wasm-to-js and js-to-wasm wrappers appear in the profiles as expected.
> It thus serves as a regression test for the status quo.
>
> R=bmeurer@chromium.org
>
> Bug: chromium:1054386
> Change-Id: I5d4d8e6a252c6eb266b910621fca43a6ff0837bd
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2066970
> Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
> Commit-Queue: Clemens Backes <clemensb@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#66401}

TBR=bmeurer@chromium.org

Bug: chromium:1054386, v8:10266
Change-Id: Iae04c0564ee8f0330d61ce954d895a41497c5a85
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2071260Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66424}
parent 0d0d38fe
Test that console profiles contain wasm function names. Test that console profiles contain wasm function names.
Compiling wasm. Compiling wasm.
Running fib with increasing input until it shows up in the profile. Running fib with increasing input until it shows up in the profile.
Found fib in profile. Found expected functions in profile.
...@@ -2,13 +2,18 @@ ...@@ -2,13 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// TODO(v8:10266): Figure out why this fails on tsan with --always-opt.
// Flags: --no-always-opt
let {session, contextGroup, Protocol} = InspectorTest.start( let {session, contextGroup, Protocol} = InspectorTest.start(
'Test that console profiles contain wasm function names.'); 'Test that console profiles contain wasm function names.');
utils.load('test/mjsunit/wasm/wasm-module-builder.js'); utils.load('test/mjsunit/wasm/wasm-module-builder.js');
// Add fibonacci function. // Add fibonacci function, calling back and forth between JS and Wasm to also
// check for the occurrence of the wrappers.
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
const imp_index = builder.addImport('q', 'f', kSig_i_i);
builder.addFunction('fib', kSig_i_i) builder.addFunction('fib', kSig_i_i)
.addBody([ .addBody([
kExprLocalGet, 0, kExprLocalGet, 0,
...@@ -17,9 +22,9 @@ builder.addFunction('fib', kSig_i_i) ...@@ -17,9 +22,9 @@ builder.addFunction('fib', kSig_i_i)
kExprI32LeS, // i < 2 ? kExprI32LeS, // i < 2 ?
kExprBrIf, 0, // --> return i kExprBrIf, 0, // --> return i
kExprI32Const, 1, kExprI32Sub, // i - 1 kExprI32Const, 1, kExprI32Sub, // i - 1
kExprCallFunction, 0, // fib(i - 1) kExprCallFunction, imp_index, // imp(i - 1)
kExprLocalGet, 0, kExprI32Const, 2, kExprI32Sub, // i - 2 kExprLocalGet, 0, kExprI32Const, 2, kExprI32Sub, // i - 2
kExprCallFunction, 0, // fib(i - 2) kExprCallFunction, imp_index, // imp(i - 2)
kExprI32Add kExprI32Add
]) ])
.exportFunc(); .exportFunc();
...@@ -32,28 +37,38 @@ function compile(bytes) { ...@@ -32,28 +37,38 @@ function compile(bytes) {
view[i] = bytes[i] | 0; view[i] = bytes[i] | 0;
} }
let module = new WebAssembly.Module(buffer); let module = new WebAssembly.Module(buffer);
let instance = new WebAssembly.Instance(module); let fib = undefined;
function imp(i) { return fib(i); }
let instance = new WebAssembly.Instance(module, {q: {f: imp}});
fib = instance.exports.fib;
return instance; return instance;
} }
function checkError(message) function checkError(message) {
{ if (!message.error) return;
if (message.error) { InspectorTest.log('Error: ');
InspectorTest.log("Error: "); InspectorTest.logMessage(message);
InspectorTest.logMessage(message); InspectorTest.completeTest();
InspectorTest.completeTest();
}
} }
(async function test() { (async function test() {
Protocol.Profiler.enable(); Protocol.Profiler.enable();
checkError(await Protocol.Profiler.start()); checkError(await Protocol.Profiler.start());
let found_fib_in_profile = false; let found_good_profile = false;
let finished_profiles = 0; let finished_profiles = 0;
Protocol.Profiler.onConsoleProfileFinished(e => { Protocol.Profiler.onConsoleProfileFinished(e => {
++finished_profiles; ++finished_profiles;
if (e.params.profile.nodes.some(n => n.callFrame.functionName === 'fib')) let function_names =
found_fib_in_profile = true; e.params.profile.nodes.map(n => n.callFrame.functionName);
// InspectorTest.log(function_names.join(', '));
// Check for at least one full cycle of
// fib -> wasm-to-js -> imp -> js-to-wasm -> fib.
const expected = ['fib', 'wasm-to-js:i:i', 'imp', 'js-to-wasm:i:i', 'fib'];
for (let i = 0; i <= function_names.length - expected.length; ++i) {
if (expected.every((val, idx) => val == function_names[i + idx])) {
found_good_profile = true;
}
}
}); });
InspectorTest.log('Compiling wasm.'); InspectorTest.log('Compiling wasm.');
checkError(await Protocol.Runtime.evaluate({ checkError(await Protocol.Runtime.evaluate({
...@@ -62,7 +77,7 @@ function checkError(message) ...@@ -62,7 +77,7 @@ function checkError(message)
})); }));
InspectorTest.log( InspectorTest.log(
'Running fib with increasing input until it shows up in the profile.'); 'Running fib with increasing input until it shows up in the profile.');
for (let i = 1; !found_fib_in_profile; ++i) { for (let i = 1; !found_good_profile; ++i) {
checkError(await Protocol.Runtime.evaluate( checkError(await Protocol.Runtime.evaluate(
{expression: 'console.profile(\'profile\');'})); {expression: 'console.profile(\'profile\');'}));
checkError(await Protocol.Runtime.evaluate( checkError(await Protocol.Runtime.evaluate(
...@@ -75,6 +90,6 @@ function checkError(message) ...@@ -75,6 +90,6 @@ function checkError(message)
finished_profiles + ')'); finished_profiles + ')');
} }
} }
InspectorTest.log('Found fib in profile.'); InspectorTest.log('Found expected functions in profile.');
InspectorTest.completeTest(); InspectorTest.completeTest();
})().catch(e => InspectorTest.log('caught: ' + e)); })().catch(e => InspectorTest.log('caught: ' + e));
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