From 0d4985d0a02f1154b486c180c3fa6f7e71dc67ab Mon Sep 17 00:00:00 2001 From: Clemens Hammacher Date: Wed, 20 Feb 2019 13:04:27 +0100 Subject: [PATCH] Reland "[inspector] Add wasm profiling test" This is a reland of 6202c4458bf6288dafc0c8d9976bee84f380a882. Moved skipped test from 'variant == jitless' to 'lite_mode or variant == jitless'. Original change's description: > [inspector] Add wasm profiling test > > This adds a first simple test to check that CPU profiles contain wasm > function names. > > R=herhut@chromium.org, kozyatinskiy@chromium.org > > Bug: v8:8783 > Change-Id: I26b1fd2b7ec555c073d80a464ee8a799b017b07a > Reviewed-on: https://chromium-review.googlesource.com/c/1454597 > Commit-Queue: Clemens Hammacher > Reviewed-by: Stephan Herhut > Cr-Commit-Position: refs/heads/master@{#59703} TBR=herhut@chromium.org Bug: v8:8783 Change-Id: I4f68db86bf1caa4f0d68dd4fa227ded25bf5145a Reviewed-on: https://chromium-review.googlesource.com/c/1477678 Reviewed-by: Clemens Hammacher Commit-Queue: Clemens Hammacher Cr-Commit-Position: refs/heads/master@{#59730} --- .../console-profile-wasm-expected.txt | 4 + .../cpu-profiler/console-profile-wasm.js | 80 +++++++++++++++++++ test/inspector/inspector.status | 1 + 3 files changed, 85 insertions(+) create mode 100644 test/inspector/cpu-profiler/console-profile-wasm-expected.txt create mode 100644 test/inspector/cpu-profiler/console-profile-wasm.js diff --git a/test/inspector/cpu-profiler/console-profile-wasm-expected.txt b/test/inspector/cpu-profiler/console-profile-wasm-expected.txt new file mode 100644 index 0000000000..ad1d9db168 --- /dev/null +++ b/test/inspector/cpu-profiler/console-profile-wasm-expected.txt @@ -0,0 +1,4 @@ +Test that console profiles contain wasm function names. +Compiling wasm. +Running fib with increasing input until it shows up in the profile. +Found fib in profile. diff --git a/test/inspector/cpu-profiler/console-profile-wasm.js b/test/inspector/cpu-profiler/console-profile-wasm.js new file mode 100644 index 0000000000..dc96406d4a --- /dev/null +++ b/test/inspector/cpu-profiler/console-profile-wasm.js @@ -0,0 +1,80 @@ +// 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( + 'Test that console profiles contain wasm function names.'); + +utils.load('test/mjsunit/wasm/wasm-module-builder.js'); + +// Add fibonacci function. +var builder = new WasmModuleBuilder(); +builder.addFunction('fib', kSig_i_i) + .addBody([ + kExprGetLocal, 0, + kExprGetLocal, 0, + kExprI32Const, 2, + kExprI32LeS, // i < 2 ? + kExprBrIf, 0, // --> return i + kExprI32Const, 1, kExprI32Sub, // i - 1 + kExprCallFunction, 0, // fib(i - 1) + kExprGetLocal, 0, kExprI32Const, 2, kExprI32Sub, // i - 2 + kExprCallFunction, 0, // fib(i - 2) + kExprI32Add + ]) + .exportFunc(); +let module_bytes = builder.toArray(); + +function compile(bytes) { + let buffer = new ArrayBuffer(bytes.length); + let view = new Uint8Array(buffer); + for (var i = 0; i < bytes.length; i++) { + view[i] = bytes[i] | 0; + } + let module = new WebAssembly.Module(buffer); + let instance = new WebAssembly.Instance(module); + return instance; +} + +function checkError(message) +{ + if (message.error) { + InspectorTest.log("Error: "); + InspectorTest.logMessage(message); + InspectorTest.completeTest(); + } +} + +(async function test() { + Protocol.Profiler.enable(); + checkError(await Protocol.Profiler.start()); + let found_fib_in_profile = false; + let finished_profiles = 0; + Protocol.Profiler.onConsoleProfileFinished(e => { + ++finished_profiles; + if (e.params.profile.nodes.some(n => n.callFrame.functionName === 'fib')) + found_fib_in_profile = true; + }); + InspectorTest.log('Compiling wasm.'); + checkError(await Protocol.Runtime.evaluate({ + expression: 'const instance = (' + compile + ')(' + + JSON.stringify(module_bytes) + ');' + })); + InspectorTest.log( + 'Running fib with increasing input until it shows up in the profile.'); + for (let i = 1; !found_fib_in_profile; ++i) { + checkError(await Protocol.Runtime.evaluate( + {expression: 'console.profile(\'profile\');'})); + checkError(await Protocol.Runtime.evaluate( + {expression: 'instance.exports.fib(' + i + ');'})); + checkError(await Protocol.Runtime.evaluate( + {expression: 'console.profileEnd(\'profile\');'})); + if (finished_profiles != i) { + InspectorTest.log( + 'Missing consoleProfileFinished message (expected ' + i + ', got ' + + finished_profiles + ')'); + } + } + InspectorTest.log('Found fib in profile.'); + InspectorTest.completeTest(); +})().catch(e => InspectorTest.log('caught: ' + e)); diff --git a/test/inspector/inspector.status b/test/inspector/inspector.status index f09bad0eca..0a2a83b2c7 100644 --- a/test/inspector/inspector.status +++ b/test/inspector/inspector.status @@ -48,6 +48,7 @@ 'debugger/asm-js-breakpoint-before-exec': [SKIP], 'debugger/asm-js-breakpoint-during-exec': [SKIP], 'debugger/wasm-*': [SKIP], + 'cpu-profiler/console-profile-wasm': [SKIP], }], # 'lite_mode or variant == jitless' ##############################################################################