Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(245)

Unified Diff: src/debug/debug-coverage.cc

Issue 2700743002: [inspector] extend protocol for code coverage. (Closed)
Patch Set: fix Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/debug/debug-coverage.h ('k') | src/debug/debug-interface.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/debug/debug-coverage.cc
diff --git a/src/debug/debug-coverage.cc b/src/debug/debug-coverage.cc
index 76a88b095271869710c78341055f9520de283e0a..8a13b6c92dc5facc5e738d6eb5e673a8b5098fcb 100644
--- a/src/debug/debug-coverage.cc
+++ b/src/debug/debug-coverage.cc
@@ -58,12 +58,7 @@ bool CompareSharedFunctionInfo(SharedFunctionInfo* a, SharedFunctionInfo* b) {
}
} // anonymous namespace
-CoverageScript::CoverageScript(Isolate* isolate, Handle<Script> s,
- int source_length)
- : script(s),
- toplevel(0, source_length, 1, isolate->factory()->empty_string()) {}
-
-Coverage* Coverage::Collect(Isolate* isolate) {
+Coverage* Coverage::Collect(Isolate* isolate, bool reset_count) {
SharedToCounterMap counter_map;
// Feed invocation count into the counter map.
@@ -76,6 +71,7 @@ Coverage* Coverage::Collect(Isolate* isolate) {
SharedFunctionInfo* shared = vector->shared_function_info();
DCHECK(shared->IsSubjectToDebugging());
uint32_t count = static_cast<uint32_t>(vector->invocation_count());
+ if (reset_count) vector->clear_invocation_count();
counter_map.Add(shared, count);
}
} else {
@@ -88,6 +84,7 @@ Coverage* Coverage::Collect(Isolate* isolate) {
SharedFunctionInfo* shared = vector->shared_function_info();
if (!shared->IsSubjectToDebugging()) continue;
uint32_t count = static_cast<uint32_t>(vector->invocation_count());
+ if (reset_count) vector->clear_invocation_count();
counter_map.Add(shared, count);
}
}
@@ -101,47 +98,39 @@ Coverage* Coverage::Collect(Isolate* isolate) {
if (script->type() != Script::TYPE_NORMAL) continue;
// Create and add new script data.
- int source_end = String::cast(script->source())->length();
Handle<Script> script_handle(script, isolate);
- result->emplace_back(isolate, script_handle, source_end);
+ result->emplace_back(isolate, script_handle);
+ std::vector<CoverageFunction>* functions = &result->back().functions;
std::vector<SharedFunctionInfo*> sorted;
+ bool has_toplevel = false;
{
- // Collect a list of shared function infos sorted by start position.
- // Shared function infos are usually already sorted. Except for classes.
- // If the start position is the same, sort from outer to inner function.
+ // Sort functions by start position, from outer to inner functions.
SharedFunctionInfo::ScriptIterator infos(script_handle);
- while (SharedFunctionInfo* info = infos.Next()) sorted.push_back(info);
+ while (SharedFunctionInfo* info = infos.Next()) {
+ has_toplevel |= info->is_toplevel();
+ sorted.push_back(info);
+ }
std::sort(sorted.begin(), sorted.end(), CompareSharedFunctionInfo);
}
- std::vector<CoverageRange*> stack;
- stack.push_back(&result->back().toplevel);
+ 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);
int end = info->end_position();
uint32_t count = counter_map.Get(info);
- if (info->is_toplevel()) {
- // Top-level function is available.
- DCHECK_EQ(1, stack.size());
- result->back().toplevel.start = start;
- result->back().toplevel.end = end;
- result->back().toplevel.count = count;
- } else {
- // The shared function infos are sorted by start.
- DCHECK_LE(stack.back()->start, start);
- // Drop the stack to the outer function.
- while (start >= stack.back()->end) stack.pop_back();
- CoverageRange* outer = stack.back();
- // New nested function.
- DCHECK_LE(end, outer->end);
- Handle<String> name(info->DebugName(), isolate);
- outer->inner.emplace_back(start, end, count, name);
- stack.push_back(&outer->inner.back());
- }
+ Handle<String> name(info->DebugName(), isolate);
+ functions->emplace_back(start, end, count, name);
}
}
return result;
« no previous file with comments | « src/debug/debug-coverage.h ('k') | src/debug/debug-interface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698