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

Unified Diff: runtime/vm/coverage.cc

Issue 324843004: Significantly improve performance of code coverage tool by precomputing a map token_pos->line numbe… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 6 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 | « runtime/vm/coverage.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/coverage.cc
===================================================================
--- runtime/vm/coverage.cc (revision 37119)
+++ runtime/vm/coverage.cc (working copy)
@@ -18,8 +18,30 @@
"Enable writing coverage data into specified directory.");
+// map[token_pos] -> line-number.
+static void ComputeTokenPosToLineNumberMap(const Script& script,
+ GrowableArray<intptr_t>* map) {
+ const TokenStream& tkns = TokenStream::Handle(script.tokens());
+ const intptr_t len = ExternalTypedData::Handle(tkns.GetStream()).Length();
+ map->Clear();
+ for (intptr_t i = 0; i < len; i++) {
+ map->Add(-1);
+ }
+ TokenStream::Iterator tkit(tkns, 0, TokenStream::Iterator::kAllTokens);
+ intptr_t cur_line = script.line_offset() + 1;
+ while (tkit.CurrentTokenKind() != Token::kEOS) {
+ (*map)[tkit.CurrentPosition()] = cur_line;
+ if (tkit.CurrentTokenKind() == Token::kNEWLINE) {
+ cur_line++;
+ }
+ tkit.Advance();
+ }
+}
+
+
void CodeCoverage::CompileAndAdd(const Function& function,
- const JSONArray& hits_arr) {
+ const JSONArray& hits_arr,
+ const GrowableArray<intptr_t>& pos_to_line) {
Isolate* isolate = Isolate::Current();
if (!function.HasCode()) {
// If the function should not be compiled or if the compilation failed,
@@ -46,7 +68,6 @@
ASSERT(function.HasCode());
// Print the hit counts for all IC datas.
- const Script& script = Script::Handle(function.script());
const Code& code = Code::Handle(function.unoptimized_code());
const Array& ic_array = Array::Handle(code.ExtractTypeFeedbackArray());
const PcDescriptors& descriptors = PcDescriptors::Handle(
@@ -63,8 +84,13 @@
ic_data ^= ic_array.At(deopt_id);
if (!ic_data.IsNull()) {
intptr_t token_pos = descriptors.TokenPos(j);
- intptr_t line = -1;
- script.GetTokenLocation(token_pos, &line, NULL);
+ intptr_t line = pos_to_line[token_pos];
+#if defined(DEBUG)
+ const Script& script = Script::Handle(function.script());
+ intptr_t test_line = -1;
+ script.GetTokenLocation(token_pos, &test_line, NULL);
+ ASSERT(test_line == line);
+#endif
hits_arr.AddValue(line);
hits_arr.AddValue(ic_data.AggregateCount());
}
@@ -81,13 +107,14 @@
Script& script = Script::Handle();
String& saved_url = String::Handle();
String& url = String::Handle();
-
+ GrowableArray<intptr_t> pos_to_line;
int i = 0;
while (i < functions.Length()) {
HANDLESCOPE(isolate);
function ^= functions.At(i);
JSONObject jsobj(&jsarr);
script = function.script();
+ ComputeTokenPosToLineNumberMap(script, &pos_to_line);
saved_url = script.url();
jsobj.AddProperty("source", saved_url.ToCString());
jsobj.AddProperty("script", script);
@@ -100,12 +127,13 @@
script = function.script();
url = script.url();
if (!url.Equals(saved_url)) {
+ pos_to_line.Clear();
break;
}
- CompileAndAdd(function, hits_arr);
+ CompileAndAdd(function, hits_arr, pos_to_line);
if (function.HasImplicitClosureFunction()) {
function = function.ImplicitClosureFunction();
- CompileAndAdd(function, hits_arr);
+ CompileAndAdd(function, hits_arr, pos_to_line);
}
i++;
}
@@ -115,6 +143,7 @@
GrowableObjectArray::Handle(cls.closures());
if (!closures.IsNull()) {
i = 0;
+ pos_to_line.Clear();
// We need to keep rechecking the length of the closures array, as handling
// a closure potentially adds new entries to the end.
while (i < closures.Length()) {
@@ -122,6 +151,7 @@
function ^= closures.At(i);
JSONObject jsobj(&jsarr);
script = function.script();
+ ComputeTokenPosToLineNumberMap(script, &pos_to_line);
saved_url = script.url();
jsobj.AddProperty("source", saved_url.ToCString());
jsobj.AddProperty("script", script);
@@ -134,9 +164,10 @@
script = function.script();
url = script.url();
if (!url.Equals(saved_url)) {
+ pos_to_line.Clear();
break;
}
- CompileAndAdd(function, hits_arr);
+ CompileAndAdd(function, hits_arr, pos_to_line);
i++;
}
}
« no previous file with comments | « runtime/vm/coverage.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698