[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/625616
Reviewed-by: Pavel Feldman <pfeldman@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Commit-Queue: Yang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47533}
This commit is contained in:
Yang Guo 2017-08-22 10:37:53 +02:00 committed by Commit Bot
parent c65fac58d8
commit ae1fc792c4
6 changed files with 59 additions and 128 deletions

View File

@ -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

View File

@ -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();
}

View File

@ -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>>*

View File

@ -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)

View File

@ -52,7 +52,7 @@ Running test: testPreciseCountCoverage
functions : [
[0] : {
functionName :
isBlockCoverage : true
isBlockCoverage : false
ranges : [
[0] : {
count : 1
@ -63,28 +63,13 @@ Running test: testPreciseCountCoverage
}
[1] : {
functionName : fib
isBlockCoverage : true
isBlockCoverage : false
ranges : [
[0] : {
count : 15
endOffset : 73
startOffset : 1
}
[1] : {
count : 8
endOffset : 41
startOffset : 32
}
[2] : {
count : 7
endOffset : 71
startOffset : 41
}
[3] : {
count : 0
endOffset : 72
startOffset : 71
}
]
}
[2] : {
@ -100,18 +85,13 @@ Running test: testPreciseCountCoverage
}
[3] : {
functionName : iife
isBlockCoverage : true
isBlockCoverage : false
ranges : [
[0] : {
count : 1
endOffset : 208
startOffset : 177
}
[1] : {
count : 0
endOffset : 207
startOffset : 206
}
]
}
]
@ -122,7 +102,7 @@ Running test: testPreciseCountCoverage
functions : [
[0] : {
functionName :
isBlockCoverage : true
isBlockCoverage : false
ranges : [
[0] : {
count : 1
@ -578,7 +558,7 @@ Running test: testEnablePreciseCountCoverageAtPause
functions : [
[0] : {
functionName :
isBlockCoverage : true
isBlockCoverage : false
ranges : [
[0] : {
count : 1
@ -614,7 +594,7 @@ Running test: testPreciseBinaryCoverage
functions : [
[0] : {
functionName :
isBlockCoverage : true
isBlockCoverage : false
ranges : [
[0] : {
count : 1
@ -625,18 +605,13 @@ Running test: testPreciseBinaryCoverage
}
[1] : {
functionName : fib
isBlockCoverage : true
isBlockCoverage : false
ranges : [
[0] : {
count : 1
endOffset : 73
startOffset : 1
}
[1] : {
count : 0
endOffset : 72
startOffset : 71
}
]
}
[2] : {
@ -652,18 +627,13 @@ Running test: testPreciseBinaryCoverage
}
[3] : {
functionName : iife
isBlockCoverage : true
isBlockCoverage : false
ranges : [
[0] : {
count : 1
endOffset : 208
startOffset : 177
}
[1] : {
count : 0
endOffset : 207
startOffset : 206
}
]
}
]
@ -708,35 +678,14 @@ Running test: testPreciseBinaryCoverage
[0] : {
functions : [
[0] : {
functionName : fib
isBlockCoverage : true
ranges : [
[0] : {
count : 0
endOffset : 73
startOffset : 1
}
[1] : {
count : 1
endOffset : 71
startOffset : 32
}
]
}
[1] : {
functionName : is_optimized
isBlockCoverage : true
isBlockCoverage : false
ranges : [
[0] : {
count : 1
endOffset : 175
startOffset : 74
}
[1] : {
count : 0
endOffset : 174
startOffset : 173
}
]
}
]
@ -747,7 +696,7 @@ Running test: testPreciseBinaryCoverage
functions : [
[0] : {
functionName :
isBlockCoverage : true
isBlockCoverage : false
ranges : [
[0] : {
count : 1
@ -764,7 +713,7 @@ Running test: testPreciseBinaryCoverage
functions : [
[0] : {
functionName :
isBlockCoverage : true
isBlockCoverage : false
ranges : [
[0] : {
count : 1
@ -807,7 +756,7 @@ Running test: testPreciseCountCoveragePartial
functions : [
[0] : {
functionName :
isBlockCoverage : true
isBlockCoverage : false
ranges : [
[0] : {
count : 1
@ -818,71 +767,51 @@ Running test: testPreciseCountCoveragePartial
}
[1] : {
functionName : outer
isBlockCoverage : true
isBlockCoverage : false
ranges : [
[0] : {
count : 1
endOffset : 224
startOffset : 10
}
[1] : {
count : 0
endOffset : 223
startOffset : 222
}
]
}
[2] : {
functionName : nested_0
isBlockCoverage : true
isBlockCoverage : false
ranges : [
[0] : {
count : 1
endOffset : 176
startOffset : 31
}
[1] : {
count : 0
endOffset : 175
startOffset : 172
}
]
}
[3] : {
functionName : nested_1
isBlockCoverage : true
isBlockCoverage : false
ranges : [
[0] : {
count : 1
endOffset : 172
startOffset : 64
}
[1] : {
count : 0
endOffset : 171
startOffset : 166
}
]
}
[4] : {
functionName : nested_2
isBlockCoverage : true
isBlockCoverage : false
ranges : [
[0] : {
count : 1
endOffset : 166
startOffset : 99
}
[1] : {
count : 0
endOffset : 165
startOffset : 158
}
]
}
[5] : {
functionName : nested_3
isBlockCoverage : true
isBlockCoverage : false
ranges : [
[0] : {
count : 1
@ -917,23 +846,18 @@ Running test: testPreciseCountCoveragePartial
functions : [
[0] : {
functionName : nested_1
isBlockCoverage : true
isBlockCoverage : false
ranges : [
[0] : {
count : 1
endOffset : 172
startOffset : 64
}
[1] : {
count : 0
endOffset : 171
startOffset : 166
}
]
}
[1] : {
functionName : nested_2
isBlockCoverage : true
isBlockCoverage : false
ranges : [
[0] : {
count : 0
@ -950,7 +874,7 @@ Running test: testPreciseCountCoveragePartial
functions : [
[0] : {
functionName :
isBlockCoverage : true
isBlockCoverage : false
ranges : [
[0] : {
count : 1
@ -965,4 +889,4 @@ Running test: testPreciseCountCoveragePartial
}
]
}
}
}

View File

@ -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)