[coverage] Extend block coverage tracing

This extends --trace-block-coverage to output not only all raw coverage
slots, but also a detailed trace of all information that is generated by
coverage collection (i.e. after filtering and transforming collected
counts and ranges).

Example output:

Coverage for function='GetCoverage', SFI=0x3d23ea6dfb59,
has_nonempty_source_range=1, function_is_relevant=1
{start: 278, end: 441, count: 1}
{start: 357, end: 440, count: 0}

Bug: v8:6000,v8:9212
Change-Id: Ide09eb40999541df97409d0682a505ee0070b3a6
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1771777
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Yang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63437}
This commit is contained in:
Jakob Gruber 2019-08-26 16:34:09 +02:00 committed by Commit Bot
parent a5d279da00
commit 8e13de18b3

View File

@ -476,6 +476,25 @@ void CollectBlockCoverage(CoverageFunction* function, SharedFunctionInfo info,
ResetAllBlockCounts(info); ResetAllBlockCounts(info);
} }
void PrintBlockCoverage(const CoverageFunction* function,
SharedFunctionInfo info, bool has_nonempty_source_range,
bool function_is_relevant) {
DCHECK(FLAG_trace_block_coverage);
std::unique_ptr<char[]> function_name =
function->name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
i::PrintF(
"Coverage for function='%s', SFI=%p, has_nonempty_source_range=%d, "
"function_is_relevant=%d\n",
function_name.get(), reinterpret_cast<void*>(info.ptr()),
has_nonempty_source_range, function_is_relevant);
i::PrintF("{start: %d, end: %d, count: %d}\n", function->start, function->end,
function->count);
for (const auto& block : function->blocks) {
i::PrintF("{start: %d, end: %d, count: %d}\n", block.start, block.end,
block.count);
}
}
void CollectAndMaybeResetCounts(Isolate* isolate, void CollectAndMaybeResetCounts(Isolate* isolate,
SharedToCounterMap* counter_map, SharedToCounterMap* counter_map,
v8::debug::CoverageMode coverage_mode) { v8::debug::CoverageMode coverage_mode) {
@ -668,9 +687,7 @@ std::unique_ptr<Coverage> Coverage::Collect(
} }
// Only include a function range if itself or its parent function is // Only include a function range if itself or its parent function is
// covered, or if it contains non-trivial block coverage. It must also // covered, or if it contains non-trivial block coverage.
// have a non-empty source range (otherwise it is not interesting to
// report).
bool is_covered = (count != 0); bool is_covered = (count != 0);
bool parent_is_covered = bool parent_is_covered =
(!nesting.empty() && functions->at(nesting.back()).count != 0); (!nesting.empty() && functions->at(nesting.back()).count != 0);
@ -678,10 +695,19 @@ std::unique_ptr<Coverage> Coverage::Collect(
bool function_is_relevant = bool function_is_relevant =
(is_covered || parent_is_covered || has_block_coverage); (is_covered || parent_is_covered || has_block_coverage);
if (function.HasNonEmptySourceRange() && function_is_relevant) { // It must also have a non-empty source range (otherwise it is not
// interesting to report).
bool has_nonempty_source_range = function.HasNonEmptySourceRange();
if (has_nonempty_source_range && function_is_relevant) {
nesting.push_back(functions->size()); nesting.push_back(functions->size());
functions->emplace_back(function); functions->emplace_back(function);
} }
if (FLAG_trace_block_coverage) {
PrintBlockCoverage(&function, info, has_nonempty_source_range,
function_is_relevant);
}
} }
// Remove entries for scripts that have no coverage. // Remove entries for scripts that have no coverage.