From 8e13de18b3cece77a8d6883384b4ffa7a9c608db Mon Sep 17 00:00:00 2001 From: Jakob Gruber Date: Mon, 26 Aug 2019 16:34:09 +0200 Subject: [PATCH] [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 Reviewed-by: Yang Guo Cr-Commit-Position: refs/heads/master@{#63437} --- src/debug/debug-coverage.cc | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/src/debug/debug-coverage.cc b/src/debug/debug-coverage.cc index 15aad1fcc2..e9a1a986df 100644 --- a/src/debug/debug-coverage.cc +++ b/src/debug/debug-coverage.cc @@ -476,6 +476,25 @@ void CollectBlockCoverage(CoverageFunction* function, SharedFunctionInfo 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 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(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, SharedToCounterMap* counter_map, v8::debug::CoverageMode coverage_mode) { @@ -668,9 +687,7 @@ std::unique_ptr Coverage::Collect( } // Only include a function range if itself or its parent function is - // covered, or if it contains non-trivial block coverage. It must also - // have a non-empty source range (otherwise it is not interesting to - // report). + // covered, or if it contains non-trivial block coverage. bool is_covered = (count != 0); bool parent_is_covered = (!nesting.empty() && functions->at(nesting.back()).count != 0); @@ -678,10 +695,19 @@ std::unique_ptr Coverage::Collect( bool function_is_relevant = (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()); 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.