Upload Kmake

This commit is contained in:
Gorochu
2026-05-26 23:36:42 -07:00
parent ba051b2f74
commit 555ec72358
41615 changed files with 13344630 additions and 1 deletions

View File

@ -0,0 +1,9 @@
Test console profiles for asm.js.
testEnableProfilerEarly
Compiling asm.js module with sentinel 0.
testEnableProfilerLate
Compiling asm.js module with sentinel 1.
testEnableProfilerAfterDebugger
Compiling asm.js module with sentinel 2.
testEnableProfilerBeforeDebugger
Compiling asm.js module with sentinel 3.

View File

@ -0,0 +1,94 @@
// Copyright 2021 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 console profiles for asm.js.');
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 fib = undefined;
function imp(i) { return fib(i); }
let instance = new WebAssembly.Instance(module, {q: {f: imp}});
fib = instance.exports.fib;
return instance;
}
function checkError(message) {
if (!message.error) return;
InspectorTest.log('Error: ');
InspectorTest.logMessage(message);
InspectorTest.completeTest();
}
// When build asm.js modules, include a sentinel such that the module will not
// be reused from the cache.
let sentinel = 0;
function AsmModule(stdlib, foreign, heap) {
"use asm";
function f() {
return sentinel;
}
return {f: f};
}
async function compileAsmJs() {
InspectorTest.log(`Compiling asm.js module with sentinel ${sentinel}.`);
let code = AsmModule.toString().replace('sentinel', sentinel.toString());
++sentinel;
checkError(await Protocol.Runtime.evaluate({expression: `(${code})().f()`}));
}
async function testEnableProfilerEarly() {
InspectorTest.log(arguments.callee.name);
checkError(await Protocol.Profiler.enable());
checkError(await Protocol.Profiler.start());
await compileAsmJs();
checkError(await Protocol.Profiler.disable());
}
async function testEnableProfilerLate() {
InspectorTest.log(arguments.callee.name);
await compileAsmJs();
checkError(await Protocol.Profiler.enable());
checkError(await Protocol.Profiler.start());
checkError(await Protocol.Profiler.disable());
}
async function testEnableProfilerAfterDebugger() {
InspectorTest.log(arguments.callee.name);
checkError(await Protocol.Debugger.enable());
await compileAsmJs();
checkError(await Protocol.Profiler.enable());
checkError(await Protocol.Profiler.start());
checkError(await Protocol.Profiler.disable());
checkError(await Protocol.Debugger.disable());
}
async function testEnableProfilerBeforeDebugger() {
InspectorTest.log(arguments.callee.name);
await compileAsmJs();
await Protocol.Profiler.enable();
await Protocol.Debugger.enable();
checkError(await Protocol.Profiler.start());
await Protocol.Debugger.disable();
await Protocol.Profiler.disable();
}
(async function test() {
try {
await testEnableProfilerEarly();
await testEnableProfilerLate();
await testEnableProfilerAfterDebugger();
await testEnableProfilerBeforeDebugger();
} catch (e) {
InspectorTest.log('caught: ' + e);
}
})().catch(e => InspectorTest.log('caught: ' + e))
.finally(InspectorTest.completeTest);

View File

@ -0,0 +1,3 @@
Tests that console.profile/profileEnd will record CPU profile when inspector front-end is connected.
SUCCESS: retrieved '42' profile
SUCCESS: found 'collectProfiles' function in the profile

View File

@ -0,0 +1,47 @@
Test that console profiles contain wasm function names.
Running test: testEnableProfilerEarly
Compiling wasm.
Building wasm module with sentinel 1.
Running fib with increasing input until it shows up in the profile.
Found expected functions in profile.
Wasm script id is set.
Wasm position: wasm://wasm/ed5627ce@0:47
Running test: testEnableProfilerLate
Compiling wasm.
Building wasm module with sentinel 2.
Running fib with increasing input until it shows up in the profile.
Found expected functions in profile.
Wasm script id is set.
Wasm position: wasm://wasm/def0f3f2@0:47
Running test: testEnableProfilerAfterDebugger
Compiling wasm.
Building wasm module with sentinel 3.
Running fib with increasing input until it shows up in the profile.
Found expected functions in profile.
Wasm script id is set.
Wasm position: wasm://wasm/e950bb4a@0:47
Running test: testEnableProfilerBeforeDebugger
Compiling wasm.
Building wasm module with sentinel 4.
Running fib with increasing input until it shows up in the profile.
Found expected functions in profile.
Wasm script id is set.
Wasm position: wasm://wasm/d8d4f97a@0:47
Running test: testRunningCodeInDifferentIsolate
Building wasm module with sentinel 5.
Instantiating in inspector isolate.
Instantiating in the debugged isolate.
Compiling wasm.
Enabling profiler in the debugged isolate.
Running in the inspector isolate.
Running in the debugged isolate.
Running fib with increasing input until it shows up in the profile.
Found expected functions in profile.
Wasm script id is set.
Wasm position: wasm://wasm/8ffda0ce@0:47
Disabling profiler.

View File

@ -0,0 +1,208 @@
// 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.
// TODO(v8:10266): Figure out why this fails on tsan with --always-turbofan.
// Flags: --no-always-turbofan --no-turbo-inline-js-wasm-calls
let {session, contextGroup, Protocol} = InspectorTest.start(
'Test that console profiles contain wasm function names.');
utils.load('test/mjsunit/wasm/wasm-module-builder.js');
// Build module bytes, including a sentinel such that the module will not be
// reused from the cache.
let sentinel = 0;
function buildModuleBytes() {
++sentinel;
InspectorTest.log(`Building wasm module with sentinel ${sentinel}.`);
// Add fibonacci function, calling back and forth between JS and Wasm to also
// check for the occurrence of the wrappers.
var builder = new WasmModuleBuilder();
const imp_index = builder.addImport('q', 'f', kSig_i_i);
builder.addFunction('fib', kSig_i_i)
.addBody([
...wasmI32Const(sentinel), kExprDrop,
kExprLocalGet, 0,
kExprLocalGet, 0,
kExprI32Const, 2,
kExprI32LeS, // i < 2 ?
kExprBrIf, 0, // --> return i
kExprI32Const, 1, kExprI32Sub, // i - 1
kExprCallFunction, imp_index, // imp(i - 1)
kExprLocalGet, 0, kExprI32Const, 2, kExprI32Sub, // i - 2
kExprCallFunction, imp_index, // imp(i - 2)
kExprI32Add
])
.exportFunc();
return builder.toArray();
}
function instantiate(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 fib = undefined;
function imp(i) { return fib(i); }
let instance = new WebAssembly.Instance(module, {q: {f: imp}});
fib = instance.exports.fib;
return instance;
}
function checkError(message) {
if (!message.error) return;
InspectorTest.log('Error: ');
InspectorTest.logMessage(message);
InspectorTest.completeTest();
}
let found_good_profile = false;
let found_wasm_script_id;
let wasm_position;
let finished_profiles = 0;
// Remember which sequences of functions we have seen in profiles so far. This
// is printed in the error case to aid debugging.
let seen_profiles = [];
function addSeenProfile(function_names) {
let arrays_equal = (a, b) =>
a.length == b.length && a.every((val, index) => val == b[index]);
if (seen_profiles.some(a => arrays_equal(a, function_names))) return false;
seen_profiles.push(function_names.slice());
return true;
}
function resetGlobalData() {
found_good_profile = false;
finished_profiles = 0;
seen_profiles = [];
}
Protocol.Profiler.onConsoleProfileFinished(e => {
++finished_profiles;
let nodes = e.params.profile.nodes;
let function_names = nodes.map(n => n.callFrame.functionName);
// Check for at least one full cycle of
// fib -> wasm-to-js -> imp -> js-to-wasm -> fib.
// There are two different kinds of js-to-wasm-wrappers, so there are two
// possible positive traces.
const expected = [
['fib'], ['wasm-to-js', 'wasm-to-js:i:i'], ['imp'],
['js-to-wasm', 'js-to-wasm:i:i'], ['fib']
];
if (!addSeenProfile(function_names)) return;
for (let i = 0; i <= function_names.length - expected.length; ++i) {
if (expected.every((val, idx) => val.includes(function_names[i + idx]))) {
found_good_profile = true;
let wasm_frame = nodes[i].callFrame;
found_wasm_script_id = wasm_frame.scriptId != 0;
wasm_position = `${wasm_frame.url}@${wasm_frame.lineNumber}:${
wasm_frame.columnNumber}`;
}
}
});
async function runFibUntilProfileFound() {
InspectorTest.log(
'Running fib with increasing input until it shows up in the profile.');
resetGlobalData();
const start = Date.now();
const kTimeoutMs = 30000;
for (let i = 1; !found_good_profile; ++i) {
checkError(await Protocol.Runtime.evaluate(
{expression: `console.profile('profile');`}));
checkError(await Protocol.Runtime.evaluate(
{expression: `globalThis.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})`);
}
if (Date.now() - start > kTimeoutMs) {
InspectorTest.log('Seen profiles so far:');
for (let profile of seen_profiles) {
InspectorTest.log(' - ' + profile.join(" -> "));
}
throw new Error(
`fib did not show up in the profile within ` +
`${kTimeoutMs}ms (after ${i} executions)`);
}
}
InspectorTest.log('Found expected functions in profile.');
InspectorTest.log(
`Wasm script id is ${found_wasm_script_id ? 'set.' : 'NOT SET.'}`);
InspectorTest.log(`Wasm position: ${wasm_position}`);
}
async function compileWasm(module_bytes) {
InspectorTest.log('Compiling wasm.');
if (module_bytes === undefined) module_bytes = buildModuleBytes();
checkError(await Protocol.Runtime.evaluate({
expression: `globalThis.instance = (${instantiate})(${
JSON.stringify(module_bytes)});`
}));
}
InspectorTest.runAsyncTestSuite([
async function testEnableProfilerEarly() {
checkError(await Protocol.Profiler.enable());
checkError(await Protocol.Profiler.start());
await compileWasm();
await runFibUntilProfileFound();
checkError(await Protocol.Profiler.disable());
},
async function testEnableProfilerLate() {
await compileWasm();
checkError(await Protocol.Profiler.enable());
checkError(await Protocol.Profiler.start());
await runFibUntilProfileFound();
checkError(await Protocol.Profiler.disable());
},
async function testEnableProfilerAfterDebugger() {
checkError(await Protocol.Debugger.enable());
await compileWasm();
checkError(await Protocol.Profiler.enable());
checkError(await Protocol.Profiler.start());
await runFibUntilProfileFound();
checkError(await Protocol.Profiler.disable());
checkError(await Protocol.Debugger.disable());
},
async function testEnableProfilerBeforeDebugger() {
await compileWasm();
await Protocol.Profiler.enable();
await Protocol.Debugger.enable();
checkError(await Protocol.Profiler.start());
await runFibUntilProfileFound();
await Protocol.Debugger.disable();
await Protocol.Profiler.disable();
},
async function testRunningCodeInDifferentIsolate() {
// Do instantiate the module in the inspector isolate *and* in the debugged
// isolate. Trigger lazy compilation in the inspector isolate then. Check
// that we can profile in the debugged isolate later, i.e. the lazily
// compiled code was logged there.
let module_bytes = buildModuleBytes();
InspectorTest.log('Instantiating in inspector isolate.');
let instance = instantiate(module_bytes);
InspectorTest.log('Instantiating in the debugged isolate.');
await compileWasm(module_bytes);
InspectorTest.log('Enabling profiler in the debugged isolate.');
await Protocol.Profiler.enable();
checkError(await Protocol.Profiler.start());
InspectorTest.log('Running in the inspector isolate.');
instance.exports.fib(26);
InspectorTest.log('Running in the debugged isolate.');
await runFibUntilProfileFound();
InspectorTest.log('Disabling profiler.');
await Protocol.Profiler.disable();
}
]);

View File

@ -0,0 +1,59 @@
// Copyright 2016 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("Tests that console.profile/profileEnd will record CPU profile when inspector front-end is connected.");
contextGroup.addScript(`
function collectProfiles()
{
console.profile("outer");
console.profile(42);
console.profileEnd("outer");
console.profileEnd(42);
}`);
InspectorTest.fail = function(message)
{
InspectorTest.log("FAIL: " + message);
InspectorTest.completeTest();
}
Protocol.Profiler.enable();
Protocol.Runtime.evaluate({ expression: "collectProfiles()"}).then(didCollectProfiles);
var headers = [];
Protocol.Profiler.onConsoleProfileFinished(function(messageObject)
{
headers.push({
profile: messageObject["params"]["profile"],
title: messageObject["params"]["title"]
});
});
function didCollectProfiles(messageObject)
{
if (headers.length !== 2)
return InspectorTest.fail("Cannot retrive headers: " + JSON.stringify(messageObject, null, 4));
for (var i = 0; i < headers.length; i++) {
if (headers[i].title === "42") {
checkInnerProfile(headers[i].profile);
return;
}
}
InspectorTest.fail("Cannot find '42' profile header");
}
function checkInnerProfile(profile)
{
InspectorTest.log("SUCCESS: retrieved '42' profile");
if (!findFunctionInProfile(profile.nodes, "collectProfiles"))
return InspectorTest.fail("collectProfiles function not found in the profile: " + JSON.stringify(profile, null, 4));
InspectorTest.log("SUCCESS: found 'collectProfiles' function in the profile");
InspectorTest.completeTest();
}
function findFunctionInProfile(nodes, functionName)
{
return nodes.some(n => n.callFrame.functionName === functionName);
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,293 @@
// Copyright 2017 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.
// Flags: --allow-natives-syntax --no-always-turbofan --turbofan
// Flags: --no-stress-flush-code
// Flags: --no-stress-incremental-marking
// Flags: --no-concurrent-recompilation
// Flags: --no-maglev
var source =
`
function fib(x) {
if (x < 2) return 1;
return fib(x-1) + fib(x-2);
}
function is_optimized(f) {
return (%GetOptimizationStatus(f) & 16) ? "optimized" : "unoptimized";
}
(function iife() {
return 1;
})();
fib(5);
`;
var break_source =
`
function g() {
debugger;
}
function f(x) {
if (x == 0) g();
else f(x - 1);
}
function h() {
g();
}
f(3);
`;
var nested =
`
var f = (function outer() {
function nested_0() {
return function nested_1() {
return function nested_2() {
return function nested_3() {}
}
}
}
function nested_4() {}
return nested_0();
})();
f()()();
`;
let {session, contextGroup, Protocol} = InspectorTest.start("Test collecting code coverage data with Profiler.collectCoverage.");
function ClearAndGC() {
return Protocol.Runtime.evaluate({ expression: "fib = g = f = h = is_optimized = null;" })
.then(GC);
}
function GC() {
return Protocol.HeapProfiler.collectGarbage();
}
function LogSorted(message) {
message.result.result.sort((a, b) => parseInt(a.scriptId) - parseInt(b.scriptId));
return InspectorTest.logMessage(message);
}
InspectorTest.runTestSuite([
function testPreciseCountBaseline(next)
{
Protocol.Runtime.enable()
.then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL: arguments.callee.name, persistScript: true }))
.then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scriptId }))
.then(GC)
.then(Protocol.Profiler.enable)
.then(() => Protocol.Profiler.startPreciseCoverage({callCount: true, detailed: true}))
.then(Protocol.Profiler.takePreciseCoverage)
.then(LogSorted)
.then(Protocol.Profiler.takePreciseCoverage)
.then(LogSorted)
.then(Protocol.Profiler.stopPreciseCoverage)
.then(Protocol.Profiler.disable)
.then(Protocol.Runtime.disable)
.then(ClearAndGC)
.then(next);
},
function testPreciseCountCoverage(next)
{
Protocol.Runtime.enable()
.then(Protocol.Profiler.enable)
.then(() => Protocol.Profiler.startPreciseCoverage({callCount: true, detailed: true}))
.then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL: arguments.callee.name, persistScript: true }))
.then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scriptId }))
.then(InspectorTest.logMessage)
.then(ClearAndGC)
.then(Protocol.Profiler.takePreciseCoverage)
.then(LogSorted)
.then(Protocol.Profiler.takePreciseCoverage)
.then(LogSorted)
.then(Protocol.Profiler.stopPreciseCoverage)
.then(Protocol.Profiler.disable)
.then(Protocol.Runtime.disable)
.then(ClearAndGC)
.then(next);
},
function testPreciseCountCoverageIncremental(next)
{
Protocol.Runtime.enable()
.then(Protocol.Profiler.enable)
.then(() => Protocol.Profiler.startPreciseCoverage({callCount: true, detailed: true}))
.then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL: arguments.callee.name, persistScript: true }))
.then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scriptId }))
.then(InspectorTest.logMessage)
.then(Protocol.Profiler.takePreciseCoverage)
.then(LogSorted)
.then(() => Protocol.Runtime.evaluate({ expression: "is_optimized(fib)" }))
.then(message => InspectorTest.logMessage(message))
.then(() => Protocol.Runtime.evaluate({ expression: "fib(20)" }))
.then(message => InspectorTest.logMessage(message))
.then(() => Protocol.Runtime.evaluate({ expression: "is_optimized(fib)" }))
.then(message => InspectorTest.logMessage(message))
.then(Protocol.Profiler.takePreciseCoverage)
.then(LogSorted)
.then(Protocol.Profiler.stopPreciseCoverage)
.then(Protocol.Profiler.disable)
.then(Protocol.Runtime.disable)
.then(ClearAndGC)
.then(next);
},
function testPreciseCoverageFail(next)
{
Protocol.Runtime.enable()
.then(Protocol.Profiler.enable)
.then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL: arguments.callee.name, persistScript: true }))
.then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scriptId }))
.then(InspectorTest.logMessage)
.then(ClearAndGC)
.then(Protocol.Profiler.takePreciseCoverage)
.then(InspectorTest.logMessage)
.then(Protocol.Profiler.disable)
.then(Protocol.Runtime.disable)
.then(ClearAndGC)
.then(next);
},
function testBestEffortCoverage(next)
{
Protocol.Runtime.enable()
.then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL: arguments.callee.name, persistScript: true }))
.then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scriptId }))
.then(InspectorTest.logMessage)
.then(ClearAndGC)
.then(Protocol.Profiler.getBestEffortCoverage)
.then(LogSorted)
.then(Protocol.Profiler.getBestEffortCoverage)
.then(LogSorted)
.then(Protocol.Runtime.disable)
.then(ClearAndGC)
.then(next);
},
function testBestEffortCoverageWithPreciseBinaryEnabled(next)
{
Protocol.Runtime.enable()
.then(Protocol.Profiler.enable)
.then(() => Protocol.Profiler.startPreciseCoverage({detailed: true}))
.then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL: arguments.callee.name, persistScript: true }))
.then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scriptId }))
.then(InspectorTest.logMessage)
.then(ClearAndGC)
.then(Protocol.Profiler.getBestEffortCoverage)
.then(LogSorted)
.then(Protocol.Profiler.getBestEffortCoverage)
.then(LogSorted)
.then(ClearAndGC)
.then(Protocol.Profiler.stopPreciseCoverage)
.then(Protocol.Profiler.disable)
.then(Protocol.Runtime.disable)
.then(ClearAndGC)
.then(next);
},
function testBestEffortCoverageWithPreciseCountEnabled(next)
{
Protocol.Runtime.enable()
.then(Protocol.Profiler.enable)
.then(() => Protocol.Profiler.startPreciseCoverage({callCount: true, detailed: true}))
.then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL: arguments.callee.name, persistScript: true }))
.then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scriptId }))
.then(InspectorTest.logMessage)
.then(ClearAndGC)
.then(Protocol.Profiler.getBestEffortCoverage)
.then(LogSorted)
.then(Protocol.Profiler.getBestEffortCoverage)
.then(LogSorted)
.then(ClearAndGC)
.then(Protocol.Profiler.stopPreciseCoverage)
.then(Protocol.Profiler.disable)
.then(Protocol.Runtime.disable)
.then(ClearAndGC)
.then(next);
},
function testEnablePreciseCountCoverageAtPause(next)
{
function handleDebuggerPause() {
Protocol.Profiler.enable()
.then(() => Protocol.Profiler.startPreciseCoverage({callCount: true, detailed: true}))
.then(Protocol.Debugger.resume)
}
Protocol.Debugger.enable();
Protocol.Debugger.oncePaused().then(handleDebuggerPause);
Protocol.Runtime.enable()
.then(() => Protocol.Runtime.compileScript({ expression: break_source, sourceURL: arguments.callee.name, persistScript: true }))
.then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scriptId }))
.then(InspectorTest.logMessage)
.then(ClearAndGC)
.then(Protocol.Profiler.takePreciseCoverage)
.then(LogSorted)
.then(ClearAndGC)
.then(Protocol.Profiler.stopPreciseCoverage)
.then(Protocol.Profiler.disable)
.then(Protocol.Runtime.disable)
.then(Protocol.Debugger.disable)
.then(ClearAndGC)
.then(next);
},
function testPreciseBinaryCoverage(next)
{
Protocol.Runtime.enable()
.then(Protocol.Profiler.enable)
.then(() => Protocol.Profiler.startPreciseCoverage({detailed: true}))
.then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL: arguments.callee.name, persistScript: true }))
.then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scriptId }))
.then(InspectorTest.logMessage)
.then(Protocol.Profiler.takePreciseCoverage)
.then(LogSorted)
.then(() => Protocol.Runtime.evaluate({ expression: "is_optimized(fib)" }))
.then(message => InspectorTest.logMessage(message))
.then(() => Protocol.Runtime.evaluate({ expression: "fib(20)" }))
.then(message => InspectorTest.logMessage(message))
.then(() => Protocol.Runtime.evaluate({ expression: "is_optimized(fib)" }))
.then(message => InspectorTest.logMessage(message))
.then(Protocol.Profiler.takePreciseCoverage)
.then(LogSorted)
.then(Protocol.Profiler.stopPreciseCoverage)
.then(Protocol.Profiler.disable)
.then(Protocol.Runtime.disable)
.then(ClearAndGC)
.then(next);
},
function testPreciseEmptyScriptCoverageEntries(next)
{
// Enabling the debugger holds onto script objects even though its
// functions can be garbage collected. We would get empty ScriptCoverage
// entires unless we remove them.
Protocol.Debugger.enable()
.then(Protocol.Runtime.enable)
.then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL: arguments.callee.name, persistScript: true }))
.then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scriptId }))
.then(ClearAndGC)
.then(Protocol.Profiler.enable)
.then(() => Protocol.Profiler.startPreciseCoverage({detailed: true}))
.then(Protocol.Profiler.takePreciseCoverage)
.then(LogSorted)
.then(Protocol.Profiler.stopPreciseCoverage)
.then(Protocol.Profiler.disable)
.then(Protocol.Runtime.disable)
.then(Protocol.Debugger.disable)
.then(ClearAndGC)
.then(next);
},
function testPreciseCountCoveragePartial(next)
{
Protocol.Runtime.enable()
.then(Protocol.Profiler.enable)
.then(() => Protocol.Profiler.startPreciseCoverage({callCount: true, detailed: true}))
.then(() => Protocol.Runtime.compileScript({ expression: nested, sourceURL: arguments.callee.name, persistScript: true }))
.then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scriptId }))
.then(InspectorTest.logMessage)
.then(Protocol.Profiler.takePreciseCoverage)
.then(LogSorted)
.then(() => Protocol.Runtime.evaluate({ expression: "f()" }))
.then(Protocol.Profiler.takePreciseCoverage)
.then(LogSorted)
.then(Protocol.Profiler.stopPreciseCoverage)
.then(Protocol.Profiler.disable)
.then(Protocol.Runtime.disable)
.then(ClearAndGC)
.then(next);
},
]);

View File

@ -0,0 +1,835 @@
Test collecting code coverage data with Profiler.collectCoverage.
Running test: testPreciseCountBaseline
{
id : <messageId>
result : {
result : [
]
timestamp : <timestamp>
}
}
{
id : <messageId>
result : {
result : [
]
timestamp : <timestamp>
}
}
Running test: testPreciseCountCoverage
{
id : <messageId>
result : {
result : {
description : 8
type : number
value : 8
}
}
}
{
id : <messageId>
result : {
result : [
[0] : {
functions : [
[0] : {
functionName :
isBlockCoverage : false
ranges : [
[0] : {
count : 1
endOffset : 221
startOffset : 0
}
]
}
[1] : {
functionName : fib
isBlockCoverage : false
ranges : [
[0] : {
count : 15
endOffset : 73
startOffset : 1
}
]
}
[2] : {
functionName : is_optimized
isBlockCoverage : false
ranges : [
[0] : {
count : 0
endOffset : 175
startOffset : 74
}
]
}
[3] : {
functionName : iife
isBlockCoverage : false
ranges : [
[0] : {
count : 1
endOffset : 208
startOffset : 177
}
]
}
]
scriptId : <scriptId>
url : testPreciseCountCoverage
}
[1] : {
functions : [
[0] : {
functionName :
isBlockCoverage : false
ranges : [
[0] : {
count : 1
endOffset : 38
startOffset : 0
}
]
}
]
scriptId : <scriptId>
url :
}
]
timestamp : <timestamp>
}
}
{
id : <messageId>
result : {
result : [
]
timestamp : <timestamp>
}
}
Running test: testPreciseCoverageFail
{
id : <messageId>
result : {
result : {
description : 8
type : number
value : 8
}
}
}
{
error : {
code : -32000
message : Precise coverage has not been started.
}
id : <messageId>
}
Running test: testBestEffortCoverage
{
id : <messageId>
result : {
result : {
description : 8
type : number
value : 8
}
}
}
{
id : <messageId>
result : {
result : [
]
}
}
{
id : <messageId>
result : {
result : [
]
}
}
Running test: testBestEffortCoverageWithPreciseBinaryEnabled
{
id : <messageId>
result : {
result : {
description : 8
type : number
value : 8
}
}
}
{
id : <messageId>
result : {
result : [
[0] : {
functions : [
[0] : {
functionName :
isBlockCoverage : false
ranges : [
[0] : {
count : 1
endOffset : 221
startOffset : 0
}
]
}
[1] : {
functionName : fib
isBlockCoverage : false
ranges : [
[0] : {
count : 1
endOffset : 73
startOffset : 1
}
]
}
[2] : {
functionName : is_optimized
isBlockCoverage : false
ranges : [
[0] : {
count : 0
endOffset : 175
startOffset : 74
}
]
}
[3] : {
functionName : iife
isBlockCoverage : false
ranges : [
[0] : {
count : 1
endOffset : 208
startOffset : 177
}
]
}
]
scriptId : <scriptId>
url : testBestEffortCoverageWithPreciseBinaryEnabled
}
[1] : {
functions : [
[0] : {
functionName :
isBlockCoverage : false
ranges : [
[0] : {
count : 1
endOffset : 38
startOffset : 0
}
]
}
]
scriptId : <scriptId>
url :
}
]
}
}
{
id : <messageId>
result : {
result : [
[0] : {
functions : [
[0] : {
functionName :
isBlockCoverage : false
ranges : [
[0] : {
count : 1
endOffset : 221
startOffset : 0
}
]
}
[1] : {
functionName : fib
isBlockCoverage : false
ranges : [
[0] : {
count : 1
endOffset : 73
startOffset : 1
}
]
}
[2] : {
functionName : is_optimized
isBlockCoverage : false
ranges : [
[0] : {
count : 0
endOffset : 175
startOffset : 74
}
]
}
[3] : {
functionName : iife
isBlockCoverage : false
ranges : [
[0] : {
count : 1
endOffset : 208
startOffset : 177
}
]
}
]
scriptId : <scriptId>
url : testBestEffortCoverageWithPreciseBinaryEnabled
}
[1] : {
functions : [
[0] : {
functionName :
isBlockCoverage : false
ranges : [
[0] : {
count : 1
endOffset : 38
startOffset : 0
}
]
}
]
scriptId : <scriptId>
url :
}
]
}
}
Running test: testBestEffortCoverageWithPreciseCountEnabled
{
id : <messageId>
result : {
result : {
description : 8
type : number
value : 8
}
}
}
{
id : <messageId>
result : {
result : [
[0] : {
functions : [
[0] : {
functionName :
isBlockCoverage : false
ranges : [
[0] : {
count : 1
endOffset : 221
startOffset : 0
}
]
}
[1] : {
functionName : fib
isBlockCoverage : false
ranges : [
[0] : {
count : 1
endOffset : 73
startOffset : 1
}
]
}
[2] : {
functionName : is_optimized
isBlockCoverage : false
ranges : [
[0] : {
count : 0
endOffset : 175
startOffset : 74
}
]
}
[3] : {
functionName : iife
isBlockCoverage : false
ranges : [
[0] : {
count : 1
endOffset : 208
startOffset : 177
}
]
}
]
scriptId : <scriptId>
url : testBestEffortCoverageWithPreciseCountEnabled
}
[1] : {
functions : [
[0] : {
functionName :
isBlockCoverage : false
ranges : [
[0] : {
count : 1
endOffset : 38
startOffset : 0
}
]
}
]
scriptId : <scriptId>
url :
}
]
}
}
{
id : <messageId>
result : {
result : [
[0] : {
functions : [
[0] : {
functionName :
isBlockCoverage : false
ranges : [
[0] : {
count : 1
endOffset : 221
startOffset : 0
}
]
}
[1] : {
functionName : fib
isBlockCoverage : false
ranges : [
[0] : {
count : 1
endOffset : 73
startOffset : 1
}
]
}
[2] : {
functionName : is_optimized
isBlockCoverage : false
ranges : [
[0] : {
count : 0
endOffset : 175
startOffset : 74
}
]
}
[3] : {
functionName : iife
isBlockCoverage : false
ranges : [
[0] : {
count : 1
endOffset : 208
startOffset : 177
}
]
}
]
scriptId : <scriptId>
url : testBestEffortCoverageWithPreciseCountEnabled
}
[1] : {
functions : [
[0] : {
functionName :
isBlockCoverage : false
ranges : [
[0] : {
count : 1
endOffset : 38
startOffset : 0
}
]
}
]
scriptId : <scriptId>
url :
}
]
}
}
Running test: testEnablePreciseCountCoverageAtPause
{
id : <messageId>
result : {
result : {
type : undefined
}
}
}
{
id : <messageId>
result : {
result : [
[0] : {
functions : [
[0] : {
functionName :
isBlockCoverage : false
ranges : [
[0] : {
count : 1
endOffset : 38
startOffset : 0
}
]
}
]
scriptId : <scriptId>
url :
}
]
timestamp : <timestamp>
}
}
Running test: testPreciseBinaryCoverage
{
id : <messageId>
result : {
result : {
description : 8
type : number
value : 8
}
}
}
{
id : <messageId>
result : {
result : [
[0] : {
functions : [
[0] : {
functionName :
isBlockCoverage : false
ranges : [
[0] : {
count : 1
endOffset : 221
startOffset : 0
}
]
}
[1] : {
functionName : fib
isBlockCoverage : false
ranges : [
[0] : {
count : 1
endOffset : 73
startOffset : 1
}
]
}
[2] : {
functionName : is_optimized
isBlockCoverage : false
ranges : [
[0] : {
count : 0
endOffset : 175
startOffset : 74
}
]
}
[3] : {
functionName : iife
isBlockCoverage : false
ranges : [
[0] : {
count : 1
endOffset : 208
startOffset : 177
}
]
}
]
scriptId : <scriptId>
url : testPreciseBinaryCoverage
}
]
timestamp : <timestamp>
}
}
{
id : <messageId>
result : {
result : {
type : string
value : unoptimized
}
}
}
{
id : <messageId>
result : {
result : {
description : 10946
type : number
value : 10946
}
}
}
{
id : <messageId>
result : {
result : {
type : string
value : optimized
}
}
}
{
id : <messageId>
result : {
result : [
[0] : {
functions : [
[0] : {
functionName : is_optimized
isBlockCoverage : false
ranges : [
[0] : {
count : 1
endOffset : 175
startOffset : 74
}
]
}
]
scriptId : <scriptId>
url : testPreciseBinaryCoverage
}
[1] : {
functions : [
[0] : {
functionName :
isBlockCoverage : false
ranges : [
[0] : {
count : 1
endOffset : 17
startOffset : 0
}
]
}
]
scriptId : <scriptId>
url :
}
[2] : {
functions : [
[0] : {
functionName :
isBlockCoverage : false
ranges : [
[0] : {
count : 1
endOffset : 7
startOffset : 0
}
]
}
]
scriptId : <scriptId>
url :
}
]
timestamp : <timestamp>
}
}
Running test: testPreciseEmptyScriptCoverageEntries
{
id : <messageId>
result : {
result : [
]
timestamp : <timestamp>
}
}
Running test: testPreciseCountCoveragePartial
{
id : <messageId>
result : {
result : {
type : undefined
}
}
}
{
id : <messageId>
result : {
result : [
[0] : {
functions : [
[0] : {
functionName :
isBlockCoverage : false
ranges : [
[0] : {
count : 1
endOffset : 238
startOffset : 0
}
]
}
[1] : {
functionName : outer
isBlockCoverage : false
ranges : [
[0] : {
count : 1
endOffset : 224
startOffset : 10
}
]
}
[2] : {
functionName : nested_0
isBlockCoverage : false
ranges : [
[0] : {
count : 1
endOffset : 176
startOffset : 31
}
]
}
[3] : {
functionName : nested_1
isBlockCoverage : false
ranges : [
[0] : {
count : 1
endOffset : 172
startOffset : 64
}
]
}
[4] : {
functionName : nested_2
isBlockCoverage : false
ranges : [
[0] : {
count : 1
endOffset : 166
startOffset : 99
}
]
}
[5] : {
functionName : nested_3
isBlockCoverage : false
ranges : [
[0] : {
count : 1
endOffset : 158
startOffset : 136
}
]
}
[6] : {
functionName : nested_4
isBlockCoverage : false
ranges : [
[0] : {
count : 0
endOffset : 201
startOffset : 179
}
]
}
]
scriptId : <scriptId>
url : testPreciseCountCoveragePartial
}
]
timestamp : <timestamp>
}
}
{
id : <messageId>
result : {
result : [
[0] : {
functions : [
[0] : {
functionName : nested_1
isBlockCoverage : false
ranges : [
[0] : {
count : 1
endOffset : 172
startOffset : 64
}
]
}
[1] : {
functionName : nested_2
isBlockCoverage : false
ranges : [
[0] : {
count : 0
endOffset : 166
startOffset : 99
}
]
}
]
scriptId : <scriptId>
url : testPreciseCountCoveragePartial
}
[1] : {
functions : [
[0] : {
functionName :
isBlockCoverage : false
ranges : [
[0] : {
count : 1
endOffset : 3
startOffset : 0
}
]
}
]
scriptId : <scriptId>
url :
}
]
timestamp : <timestamp>
}
}

View File

@ -0,0 +1,270 @@
// Copyright 2017 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.
// Flags: --allow-natives-syntax --no-always-turbofan --turbofan
// Flags: --no-stress-flush-code
// Flags: --no-stress-incremental-marking
// Flags: --no-concurrent-recompilation
// Flags: --no-baseline-batch-compilation
// Flags: --no-maglev
var source =
`
function fib(x) {
if (x < 2) return 1;
return fib(x-1) + fib(x-2);
}
function is_optimized(f) {
return (%GetOptimizationStatus(f) & 16) ? "optimized" : "unoptimized";
}
(function iife() {
return 1;
})();
fib(5);
`;
var break_source =
`
function g() {
debugger;
}
function f(x) {
if (x == 0) g();
else f(x - 1);
}
function h() {
g();
}
f(3);
`;
var nested =
`
var f = (function outer() {
function nested_0() {
return function nested_1() {
return function nested_2() {
return function nested_3() {}
}
}
}
function nested_4() {}
return nested_0();
})();
f()()();
`;
let {session, contextGroup, Protocol} = InspectorTest.start("Test collecting code coverage data with Profiler.collectCoverage.");
function ClearAndGC() {
return Protocol.Runtime.evaluate({ expression: "fib = g = f = h = is_optimized = null;" })
.then(GC);
}
function GC() {
return Protocol.HeapProfiler.collectGarbage();
}
function LogSorted(message) {
message.result.result.sort((a, b) => parseInt(a.scriptId) - parseInt(b.scriptId));
return InspectorTest.logMessage(message);
}
InspectorTest.runTestSuite([
function testPreciseCountBaseline(next)
{
Protocol.Runtime.enable()
.then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL: arguments.callee.name, persistScript: true }))
.then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scriptId }))
.then(GC)
.then(Protocol.Profiler.enable)
.then(() => Protocol.Profiler.startPreciseCoverage({callCount: true, detailed: false}))
.then(Protocol.Profiler.takePreciseCoverage)
.then(LogSorted)
.then(Protocol.Profiler.takePreciseCoverage)
.then(LogSorted)
.then(Protocol.Profiler.stopPreciseCoverage)
.then(Protocol.Profiler.disable)
.then(Protocol.Runtime.disable)
.then(ClearAndGC)
.then(next);
},
function testPreciseCountCoverage(next)
{
Protocol.Runtime.enable()
.then(Protocol.Profiler.enable)
.then(() => Protocol.Profiler.startPreciseCoverage({callCount: true, detailed: false}))
.then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL: arguments.callee.name, persistScript: true }))
.then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scriptId }))
.then(InspectorTest.logMessage)
.then(ClearAndGC)
.then(Protocol.Profiler.takePreciseCoverage)
.then(LogSorted)
.then(Protocol.Profiler.takePreciseCoverage)
.then(LogSorted)
.then(Protocol.Profiler.stopPreciseCoverage)
.then(Protocol.Profiler.disable)
.then(Protocol.Runtime.disable)
.then(ClearAndGC)
.then(next);
},
function testPreciseCoverageFail(next)
{
Protocol.Runtime.enable()
.then(Protocol.Profiler.enable)
.then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL: arguments.callee.name, persistScript: true }))
.then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scriptId }))
.then(InspectorTest.logMessage)
.then(ClearAndGC)
.then(Protocol.Profiler.takePreciseCoverage)
.then(InspectorTest.logMessage)
.then(Protocol.Profiler.disable)
.then(Protocol.Runtime.disable)
.then(ClearAndGC)
.then(next);
},
function testBestEffortCoverage(next)
{
Protocol.Runtime.enable()
.then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL: arguments.callee.name, persistScript: true }))
.then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scriptId }))
.then(InspectorTest.logMessage)
.then(ClearAndGC)
.then(Protocol.Profiler.getBestEffortCoverage)
.then(LogSorted)
.then(Protocol.Profiler.getBestEffortCoverage)
.then(LogSorted)
.then(Protocol.Runtime.disable)
.then(ClearAndGC)
.then(next);
},
function testBestEffortCoverageWithPreciseBinaryEnabled(next)
{
Protocol.Runtime.enable()
.then(Protocol.Profiler.enable)
.then(() => Protocol.Profiler.startPreciseCoverage({detailed: false}))
.then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL: arguments.callee.name, persistScript: true }))
.then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scriptId }))
.then(InspectorTest.logMessage)
.then(ClearAndGC)
.then(Protocol.Profiler.getBestEffortCoverage)
.then(LogSorted)
.then(Protocol.Profiler.getBestEffortCoverage)
.then(LogSorted)
.then(ClearAndGC)
.then(Protocol.Profiler.stopPreciseCoverage)
.then(Protocol.Profiler.disable)
.then(Protocol.Runtime.disable)
.then(ClearAndGC)
.then(next);
},
function testBestEffortCoverageWithPreciseCountEnabled(next)
{
Protocol.Runtime.enable()
.then(Protocol.Profiler.enable)
.then(() => Protocol.Profiler.startPreciseCoverage({callCount: true, detailed: false}))
.then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL: arguments.callee.name, persistScript: true }))
.then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scriptId }))
.then(InspectorTest.logMessage)
.then(ClearAndGC)
.then(Protocol.Profiler.getBestEffortCoverage)
.then(LogSorted)
.then(Protocol.Profiler.getBestEffortCoverage)
.then(LogSorted)
.then(ClearAndGC)
.then(Protocol.Profiler.stopPreciseCoverage)
.then(Protocol.Profiler.disable)
.then(Protocol.Runtime.disable)
.then(ClearAndGC)
.then(next);
},
function testEnablePreciseCountCoverageAtPause(next)
{
function handleDebuggerPause() {
Protocol.Profiler.enable()
.then(() => Protocol.Profiler.startPreciseCoverage({callCount: true, detailed: false}))
.then(Protocol.Debugger.resume)
}
Protocol.Debugger.enable();
Protocol.Debugger.oncePaused().then(handleDebuggerPause);
Protocol.Runtime.enable()
.then(() => Protocol.Runtime.compileScript({ expression: break_source, sourceURL: arguments.callee.name, persistScript: true }))
.then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scriptId }))
.then(InspectorTest.logMessage)
.then(ClearAndGC)
.then(Protocol.Profiler.takePreciseCoverage)
.then(LogSorted)
.then(ClearAndGC)
.then(Protocol.Profiler.stopPreciseCoverage)
.then(Protocol.Profiler.disable)
.then(Protocol.Runtime.disable)
.then(Protocol.Debugger.disable)
.then(ClearAndGC)
.then(next);
},
function testPreciseBinaryCoverage(next)
{
Protocol.Runtime.enable()
.then(Protocol.Profiler.enable)
.then(() => Protocol.Profiler.startPreciseCoverage({detailed: false}))
.then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL: arguments.callee.name, persistScript: true }))
.then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scriptId }))
.then(InspectorTest.logMessage)
.then(Protocol.Profiler.takePreciseCoverage)
.then(LogSorted)
.then(() => Protocol.Runtime.evaluate({ expression: "is_optimized(fib)" }))
.then(message => InspectorTest.logMessage(message))
.then(() => Protocol.Runtime.evaluate({ expression: "fib(20)" }))
.then(message => InspectorTest.logMessage(message))
.then(() => Protocol.Runtime.evaluate({ expression: "is_optimized(fib)" }))
.then(message => InspectorTest.logMessage(message))
.then(Protocol.Profiler.takePreciseCoverage)
.then(LogSorted)
.then(Protocol.Profiler.stopPreciseCoverage)
.then(Protocol.Profiler.disable)
.then(Protocol.Runtime.disable)
.then(ClearAndGC)
.then(next);
},
function testPreciseEmptyScriptCoverageEntries(next)
{
// Enabling the debugger holds onto script objects even though its
// functions can be garbage collected. We would get empty ScriptCoverage
// entries unless we remove them.
Protocol.Debugger.enable()
.then(Protocol.Runtime.enable)
.then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL: arguments.callee.name, persistScript: true }))
.then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scriptId }))
.then(ClearAndGC)
.then(Protocol.Profiler.enable)
.then(() => Protocol.Profiler.startPreciseCoverage({detailed: false}))
.then(Protocol.Profiler.takePreciseCoverage)
.then(LogSorted)
.then(Protocol.Profiler.stopPreciseCoverage)
.then(Protocol.Profiler.disable)
.then(Protocol.Runtime.disable)
.then(Protocol.Debugger.disable)
.then(ClearAndGC)
.then(next);
},
function testPreciseCountCoveragePartial(next)
{
Protocol.Runtime.enable()
.then(Protocol.Profiler.enable)
.then(() => Protocol.Profiler.startPreciseCoverage({callCount: true, detailed: false}))
.then(() => Protocol.Runtime.compileScript({ expression: nested, sourceURL: arguments.callee.name, persistScript: true }))
.then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scriptId }))
.then(InspectorTest.logMessage)
.then(Protocol.Profiler.takePreciseCoverage)
.then(LogSorted)
.then(() => Protocol.Runtime.evaluate({ expression: "f()" }))
.then(Protocol.Profiler.takePreciseCoverage)
.then(LogSorted)
.then(Protocol.Profiler.stopPreciseCoverage)
.then(Protocol.Profiler.disable)
.then(Protocol.Runtime.disable)
.then(ClearAndGC)
.then(next);
},
]);

View File

@ -0,0 +1,8 @@
Test that profiling can only be started when Profiler was enabled and that Profiler.disable command will stop recording all profiles.
PASS: didFailToStartWhenDisabled
PASS: didStartFrontendProfile
PASS: console initiated profile started
PASS: didStartConsoleProfile
PASS: didDisableProfiler
PASS: no front-end initiated profiles found
PASS: didStopConsoleProfile

View File

@ -0,0 +1,89 @@
// Copyright 2016 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 profiling can only be started when Profiler was enabled and that Profiler.disable command will stop recording all profiles.");
Protocol.Profiler.start().then(didFailToStartWhenDisabled);
disallowConsoleProfiles();
function disallowConsoleProfiles()
{
Protocol.Profiler.onConsoleProfileStarted(function(messageObject)
{
InspectorTest.log("FAIL: console profile started " + JSON.stringify(messageObject, null, 4));
});
Protocol.Profiler.onConsoleProfileFinished(function(messageObject)
{
InspectorTest.log("FAIL: unexpected profile received " + JSON.stringify(messageObject, null, 4));
});
}
function allowConsoleProfiles()
{
Protocol.Profiler.onConsoleProfileStarted(function(messageObject)
{
InspectorTest.log("PASS: console initiated profile started");
});
Protocol.Profiler.onConsoleProfileFinished(function(messageObject)
{
InspectorTest.log("PASS: console initiated profile received");
});
}
function didFailToStartWhenDisabled(messageObject)
{
if (!expectedError("didFailToStartWhenDisabled", messageObject))
return;
allowConsoleProfiles();
Protocol.Profiler.enable();
Protocol.Profiler.start().then(didStartFrontendProfile);
}
function didStartFrontendProfile(messageObject)
{
if (!expectedSuccess("didStartFrontendProfile", messageObject))
return;
Protocol.Runtime.evaluate({expression: "console.profile('p1');"}).then(didStartConsoleProfile);
}
function didStartConsoleProfile(messageObject)
{
if (!expectedSuccess("didStartConsoleProfile", messageObject))
return;
Protocol.Profiler.disable().then(didDisableProfiler);
}
function didDisableProfiler(messageObject)
{
if (!expectedSuccess("didDisableProfiler", messageObject))
return;
Protocol.Profiler.enable();
Protocol.Profiler.stop().then(didStopFrontendProfile);
}
function didStopFrontendProfile(messageObject)
{
if (!expectedError("no front-end initiated profiles found", messageObject))
return;
disallowConsoleProfiles();
Protocol.Runtime.evaluate({expression: "console.profileEnd();"}).then(didStopConsoleProfile);
}
function didStopConsoleProfile(messageObject)
{
if (!expectedSuccess("didStopConsoleProfile", messageObject))
return;
InspectorTest.completeTest();
}
function checkExpectation(fail, name, messageObject)
{
if (fail === !!messageObject.error) {
InspectorTest.log("PASS: " + name);
return true;
}
InspectorTest.log("FAIL: " + name + ": " + JSON.stringify(messageObject));
InspectorTest.completeTest();
return false;
}
var expectedSuccess = checkExpectation.bind(null, false);
var expectedError = checkExpectation.bind(null, true);

View File

@ -0,0 +1,7 @@
Test that profiler is able to record a profile. Also it tests that profiler returns an error when it unable to find the profile.
PASS: startFrontendProfile
PASS: startConsoleProfile
PASS: stopConsoleProfile
PASS: stoppedFrontendProfile
PASS: startFrontendProfileSecondTime
PASS: stopFrontendProfileSecondTime

View File

@ -0,0 +1,62 @@
// Copyright 2016 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 profiler is able to record a profile. Also it tests that profiler returns an error when it unable to find the profile.");
Protocol.Profiler.enable();
Protocol.Profiler.start().then(didStartFrontendProfile);
function didStartFrontendProfile(messageObject)
{
if (!expectedSuccess("startFrontendProfile", messageObject))
return;
Protocol.Runtime.evaluate({expression: "console.profile('Profile 1');"}).then(didStartConsoleProfile);
}
function didStartConsoleProfile(messageObject)
{
if (!expectedSuccess("startConsoleProfile", messageObject))
return;
Protocol.Runtime.evaluate({expression: "console.profileEnd('Profile 1');"}).then(didStopConsoleProfile);
}
function didStopConsoleProfile(messageObject)
{
if (!expectedSuccess("stopConsoleProfile", messageObject))
return;
Protocol.Profiler.stop().then(didStopFrontendProfile);
}
function didStopFrontendProfile(messageObject)
{
if (!expectedSuccess("stoppedFrontendProfile", messageObject))
return;
Protocol.Profiler.start().then(didStartFrontendProfile2);
}
function didStartFrontendProfile2(messageObject)
{
if (!expectedSuccess("startFrontendProfileSecondTime", messageObject))
return;
Protocol.Profiler.stop().then(didStopFrontendProfile2);
}
function didStopFrontendProfile2(messageObject)
{
expectedSuccess("stopFrontendProfileSecondTime", messageObject)
InspectorTest.completeTest();
}
function checkExpectation(fail, name, messageObject)
{
if (fail === !!messageObject.error) {
InspectorTest.log("PASS: " + name);
return true;
}
InspectorTest.log("FAIL: " + name + ": " + JSON.stringify(messageObject));
InspectorTest.completeTest();
return false;
}
var expectedSuccess = checkExpectation.bind(null, false);
var expectedError = checkExpectation.bind(null, true);

View File

@ -0,0 +1,2 @@
Test that profiler doesn't crash when we call stop without preceding start.
PASS: ProfileAgent.stop

View File

@ -0,0 +1,26 @@
// Copyright 2016 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 profiler doesn't crash when we call stop without preceding start.");
Protocol.Profiler.stop().then(didStopProfile);
function didStopProfile(messageObject)
{
expectedError("ProfileAgent.stop", messageObject);
InspectorTest.completeTest();
}
function checkExpectation(fail, name, messageObject)
{
if (fail === !!messageObject.error) {
InspectorTest.log("PASS: " + name);
return true;
}
InspectorTest.log("FAIL: " + name + ": " + JSON.stringify(messageObject));
InspectorTest.completeTest();
return false;
}
var expectedSuccess = checkExpectation.bind(null, false);
var expectedError = checkExpectation.bind(null, true);