Commit ae1fc792 authored by Yang Guo's avatar Yang Guo Committed by Commit Bot

[inspector] add flag to specify coverage granularity.

Add "detailed" flag to Profiler.startPreciseCoverage to specify
granularity (block coverage vs function coverage).

The default value is currently set to FLAG_block_coverage, which
is currently true. This is so that the V8 roll does not break
LayoutTests. I'll set it to false once I made changes to Blink.

R=jgruber@chromium.org, pfeldman@chromium.org

Bug: v8:6738
Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I7242e897ab02713188a5292ca8c8bb58985e3a9b
Reviewed-on: https://chromium-review.googlesource.com/625616Reviewed-by: 's avatarPavel Feldman <pfeldman@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Commit-Queue: Yang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47533}
parent c65fac58
......@@ -916,7 +916,8 @@
{
"name": "startPreciseCoverage",
"parameters": [
{ "name": "callCount", "type": "boolean", "optional": true, "description": "Collect accurate call counts beyond simple 'covered' or 'not covered'." }
{ "name": "callCount", "type": "boolean", "optional": true, "description": "Collect accurate call counts beyond simple 'covered' or 'not covered'." },
{ "name": "detailed", "type": "boolean", "optional": true, "description": "Collect block-based coverage." }
],
"description": "Enable precise code coverage. Coverage data for JavaScript executed before enabling precise code coverage may be incomplete. Enabling prevents running optimized code and resets execution counters.",
"experimental": true
......
......@@ -25,6 +25,7 @@ static const char userInitiatedProfiling[] = "userInitiatedProfiling";
static const char profilerEnabled[] = "profilerEnabled";
static const char preciseCoverageStarted[] = "preciseCoverageStarted";
static const char preciseCoverageCallCount[] = "preciseCoverageCallCount";
static const char preciseCoverageDetailed[] = "preciseCoverageDetailed";
}
namespace {
......@@ -243,7 +244,10 @@ void V8ProfilerAgentImpl::restore() {
false)) {
bool callCount = m_state->booleanProperty(
ProfilerAgentState::preciseCoverageCallCount, false);
startPreciseCoverage(Maybe<bool>(callCount));
bool detailed =
m_state->booleanProperty(ProfilerAgentState::preciseCoverageDetailed,
v8::internal::FLAG_block_coverage);
startPreciseCoverage(Maybe<bool>(callCount), Maybe<bool>(detailed));
}
}
......@@ -274,25 +278,25 @@ Response V8ProfilerAgentImpl::stop(
return Response::OK();
}
Response V8ProfilerAgentImpl::startPreciseCoverage(Maybe<bool> callCount) {
Response V8ProfilerAgentImpl::startPreciseCoverage(Maybe<bool> callCount,
Maybe<bool> detailed) {
if (!m_enabled) return Response::Error("Profiler is not enabled");
bool callCountValue = callCount.fromMaybe(false);
bool detailedValue = detailed.fromMaybe(v8::internal::FLAG_block_coverage);
m_state->setBoolean(ProfilerAgentState::preciseCoverageStarted, true);
m_state->setBoolean(ProfilerAgentState::preciseCoverageCallCount,
callCountValue);
m_state->setBoolean(ProfilerAgentState::preciseCoverageDetailed,
detailedValue);
// BlockCount is a superset of PreciseCount. It includes block-granularity
// coverage data if it exists (at the time of writing, that's the case for
// each function recompiled after the BlockCount mode has been set); and
// function-granularity coverage data otherwise.
// TODO(jgruber): Implement block binary coverage.
v8::debug::Coverage::Mode count_mode =
v8::internal::FLAG_block_coverage ? v8::debug::Coverage::kBlockCount
: v8::debug::Coverage::kPreciseCount;
v8::debug::Coverage::Mode binary_mode =
v8::internal::FLAG_block_coverage ? v8::debug::Coverage::kBlockBinary
: v8::debug::Coverage::kPreciseBinary;
v8::debug::Coverage::SelectMode(m_isolate,
callCountValue ? count_mode : binary_mode);
typedef v8::debug::Coverage C;
C::Mode mode = callCountValue
? (detailedValue ? C::kBlockCount : C::kPreciseCount)
: (detailedValue ? C::kBlockBinary : C::kPreciseBinary);
C::SelectMode(m_isolate, mode);
return Response::OK();
}
......@@ -300,6 +304,7 @@ Response V8ProfilerAgentImpl::stopPreciseCoverage() {
if (!m_enabled) return Response::Error("Profiler is not enabled");
m_state->setBoolean(ProfilerAgentState::preciseCoverageStarted, false);
m_state->setBoolean(ProfilerAgentState::preciseCoverageCallCount, false);
m_state->setBoolean(ProfilerAgentState::preciseCoverageDetailed, false);
v8::debug::Coverage::SelectMode(m_isolate, v8::debug::Coverage::kBestEffort);
return Response::OK();
}
......
......@@ -38,7 +38,8 @@ class V8ProfilerAgentImpl : public protocol::Profiler::Backend {
Response start() override;
Response stop(std::unique_ptr<protocol::Profiler::Profile>*) override;
Response startPreciseCoverage(Maybe<bool> binary) override;
Response startPreciseCoverage(Maybe<bool> binary,
Maybe<bool> detailed) override;
Response stopPreciseCoverage() override;
Response takePreciseCoverage(
std::unique_ptr<protocol::Array<protocol::Profiler::ScriptCoverage>>*
......
......@@ -2,7 +2,7 @@
// 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-opt --opt --block-coverage
// Flags: --allow-natives-syntax --no-always-opt --opt
var source =
`
......@@ -74,7 +74,7 @@ InspectorTest.runTestSuite([
.then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scriptId }))
.then(GC)
.then(Protocol.Profiler.enable)
.then(() => Protocol.Profiler.startPreciseCoverage({callCount: true}))
.then(() => Protocol.Profiler.startPreciseCoverage({callCount: true, detailed: true}))
.then(Protocol.Profiler.takePreciseCoverage)
.then(LogSorted)
.then(Protocol.Profiler.takePreciseCoverage)
......@@ -89,7 +89,7 @@ InspectorTest.runTestSuite([
{
Protocol.Runtime.enable()
.then(Protocol.Profiler.enable)
.then(() => Protocol.Profiler.startPreciseCoverage({callCount: true}))
.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)
......@@ -108,7 +108,7 @@ InspectorTest.runTestSuite([
{
Protocol.Runtime.enable()
.then(Protocol.Profiler.enable)
.then(() => Protocol.Profiler.startPreciseCoverage({callCount: true}))
.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)
......@@ -162,7 +162,7 @@ InspectorTest.runTestSuite([
{
Protocol.Runtime.enable()
.then(Protocol.Profiler.enable)
.then(Protocol.Profiler.startPreciseCoverage)
.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)
......@@ -182,7 +182,7 @@ InspectorTest.runTestSuite([
{
Protocol.Runtime.enable()
.then(Protocol.Profiler.enable)
.then(() => Protocol.Profiler.startPreciseCoverage({callCount: true}))
.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)
......@@ -202,7 +202,7 @@ InspectorTest.runTestSuite([
{
function handleDebuggerPause() {
Protocol.Profiler.enable()
.then(() => Protocol.Profiler.startPreciseCoverage({callCount: true}))
.then(() => Protocol.Profiler.startPreciseCoverage({callCount: true, detailed: true}))
.then(Protocol.Debugger.resume)
}
Protocol.Debugger.enable();
......@@ -226,7 +226,7 @@ InspectorTest.runTestSuite([
{
Protocol.Runtime.enable()
.then(Protocol.Profiler.enable)
.then(Protocol.Profiler.startPreciseCoverage)
.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)
......@@ -257,7 +257,7 @@ InspectorTest.runTestSuite([
.then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scriptId }))
.then(ClearAndGC)
.then(Protocol.Profiler.enable)
.then(Protocol.Profiler.startPreciseCoverage)
.then(() => Protocol.Profiler.startPreciseCoverage({detailed: true}))
.then(Protocol.Profiler.takePreciseCoverage)
.then(LogSorted)
.then(Protocol.Profiler.stopPreciseCoverage)
......@@ -271,7 +271,7 @@ InspectorTest.runTestSuite([
{
Protocol.Runtime.enable()
.then(Protocol.Profiler.enable)
.then(() => Protocol.Profiler.startPreciseCoverage({callCount: true}))
.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)
......
......@@ -74,7 +74,7 @@ InspectorTest.runTestSuite([
.then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scriptId }))
.then(GC)
.then(Protocol.Profiler.enable)
.then(() => Protocol.Profiler.startPreciseCoverage({callCount: true}))
.then(() => Protocol.Profiler.startPreciseCoverage({callCount: true, detailed: false}))
.then(Protocol.Profiler.takePreciseCoverage)
.then(LogSorted)
.then(Protocol.Profiler.takePreciseCoverage)
......@@ -89,7 +89,7 @@ InspectorTest.runTestSuite([
{
Protocol.Runtime.enable()
.then(Protocol.Profiler.enable)
.then(() => Protocol.Profiler.startPreciseCoverage({callCount: true}))
.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)
......@@ -138,7 +138,7 @@ InspectorTest.runTestSuite([
{
Protocol.Runtime.enable()
.then(Protocol.Profiler.enable)
.then(Protocol.Profiler.startPreciseCoverage)
.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)
......@@ -158,7 +158,7 @@ InspectorTest.runTestSuite([
{
Protocol.Runtime.enable()
.then(Protocol.Profiler.enable)
.then(() => Protocol.Profiler.startPreciseCoverage({callCount: true}))
.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)
......@@ -178,7 +178,7 @@ InspectorTest.runTestSuite([
{
function handleDebuggerPause() {
Protocol.Profiler.enable()
.then(() => Protocol.Profiler.startPreciseCoverage({callCount: true}))
.then(() => Protocol.Profiler.startPreciseCoverage({callCount: true, detailed: false}))
.then(Protocol.Debugger.resume)
}
Protocol.Debugger.enable();
......@@ -202,7 +202,7 @@ InspectorTest.runTestSuite([
{
Protocol.Runtime.enable()
.then(Protocol.Profiler.enable)
.then(Protocol.Profiler.startPreciseCoverage)
.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)
......@@ -233,7 +233,7 @@ InspectorTest.runTestSuite([
.then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scriptId }))
.then(ClearAndGC)
.then(Protocol.Profiler.enable)
.then(Protocol.Profiler.startPreciseCoverage)
.then(() => Protocol.Profiler.startPreciseCoverage({detailed: false}))
.then(Protocol.Profiler.takePreciseCoverage)
.then(LogSorted)
.then(Protocol.Profiler.stopPreciseCoverage)
......@@ -247,7 +247,7 @@ InspectorTest.runTestSuite([
{
Protocol.Runtime.enable()
.then(Protocol.Profiler.enable)
.then(() => Protocol.Profiler.startPreciseCoverage({callCount: true}))
.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)
......
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