Commit 5e0c178f authored by yangguo's avatar yangguo Committed by Commit bot

[debugger] remove default count for top-level functions.

If the top-level function cannot be found, we previously assumed an
invocation count of 1. This is wrong when we expect the invocation
counts to be reset for precise coverage.

TBR=jgruber@chromium.org
R=caseq@chromium.org,pfeldman@chromium.org
BUG=v8:5808

Review-Url: https://codereview.chromium.org/2723003007
Cr-Commit-Position: refs/heads/master@{#43620}
parent 562da356
......@@ -103,27 +103,16 @@ Coverage* Coverage::Collect(Isolate* isolate, bool reset_count) {
std::vector<CoverageFunction>* functions = &result->back().functions;
std::vector<SharedFunctionInfo*> sorted;
bool has_toplevel = false;
{
// Sort functions by start position, from outer to inner functions.
SharedFunctionInfo::ScriptIterator infos(script_handle);
while (SharedFunctionInfo* info = infos.Next()) {
has_toplevel |= info->is_toplevel();
sorted.push_back(info);
}
std::sort(sorted.begin(), sorted.end(), CompareSharedFunctionInfo);
}
functions->reserve(sorted.size() + (has_toplevel ? 0 : 1));
if (!has_toplevel) {
// Add a replacement toplevel function if it does not exist.
int source_end = String::cast(script->source())->length();
functions->emplace_back(0, source_end, 1u,
isolate->factory()->empty_string());
}
// Use sorted list to reconstruct function nesting.
for (SharedFunctionInfo* info : sorted) {
int start = StartPosition(info);
......
Test collecting code coverage data with Profiler.collectCoverage.
Running test: testPreciseBaseline
{
id : <messageId>
result : {
result : [
[0] : {
functions : [
[0] : {
functionName : fib
ranges : [
[0] : {
count : 0
endColumnNumber : 1
endLineNumber : 4
startColumnNumber : 0
startLineNumber : 1
}
]
}
]
scriptId : <scriptId>
url : 0
}
]
}
}
{
id : <messageId>
result : {
result : [
[0] : {
functions : [
[0] : {
functionName : fib
ranges : [
[0] : {
count : 0
endColumnNumber : 1
endLineNumber : 4
startColumnNumber : 0
startLineNumber : 1
}
]
}
]
scriptId : <scriptId>
url : 0
}
]
}
}
Running test: testPreciseCoverage
{
id : <messageId>
......
......@@ -17,8 +17,11 @@ fib(5);
InspectorTest.log("Test collecting code coverage data with Profiler.collectCoverage.");
function ClearAndGC() {
return Protocol.Runtime.evaluate({ expression: "fib = null;" })
.then(() => Protocol.HeapProfiler.enable())
return Protocol.Runtime.evaluate({ expression: "fib = null;" }).then(GC);
}
function GC() {
return Protocol.HeapProfiler.enable()
.then(() => Protocol.HeapProfiler.collectGarbage())
.then(() => Protocol.HeapProfiler.disable());
}
......@@ -29,6 +32,24 @@ function LogSorted(message) {
}
InspectorTest.runTestSuite([
function testPreciseBaseline(next)
{
Protocol.Runtime.enable()
.then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL: "0", persistScript: true }))
.then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scriptId }))
.then(GC)
.then(Protocol.Profiler.enable)
.then(Protocol.Profiler.startPreciseCoverage)
.then(Protocol.Profiler.takePreciseCoverage)
.then(LogSorted)
.then(Protocol.Profiler.takePreciseCoverage)
.then(LogSorted)
.then(Protocol.Profiler.stopPreciseCoverage)
.then(ClearAndGC)
.then(Protocol.Profiler.disable)
.then(Protocol.Runtime.disable)
.then(next);
},
function testPreciseCoverage(next)
{
Protocol.Runtime.enable()
......
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