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

Side by Side Diff: runtime/vm/coverage.cc

Issue 392933003: vm/observatory: Clean up script access (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/coverage.h ('k') | runtime/vm/coverage_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/coverage.h" 5 #include "vm/coverage.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 8
9 #include "vm/compiler.h" 9 #include "vm/compiler.h"
10 #include "vm/isolate.h" 10 #include "vm/isolate.h"
11 #include "vm/json_stream.h" 11 #include "vm/json_stream.h"
12 #include "vm/object.h" 12 #include "vm/object.h"
13 #include "vm/object_store.h" 13 #include "vm/object_store.h"
14 14
15 namespace dart { 15 namespace dart {
16 16
17 DEFINE_FLAG(charp, coverage_dir, NULL, 17 DEFINE_FLAG(charp, coverage_dir, NULL,
18 "Enable writing coverage data into specified directory."); 18 "Enable writing coverage data into specified directory.");
19 19
20 20
21 class CoverageFilterAll : public CoverageFilter { 21 class CoverageFilterAll : public CoverageFilter {
22 public: 22 public:
23 bool ShouldOutputCoverageFor(const Library& lib, 23 bool ShouldOutputCoverageFor(const Library& lib,
24 const String& script_url, 24 const Script& script,
25 const Class& cls, 25 const Class& cls,
26 const Function& func) const { 26 const Function& func) const {
27 return true; 27 return true;
28 } 28 }
29 }; 29 };
30 30
31 31
32 // map[token_pos] -> line-number. 32 // map[token_pos] -> line-number.
33 static void ComputeTokenPosToLineNumberMap(const Script& script, 33 static void ComputeTokenPosToLineNumberMap(const Script& script,
34 GrowableArray<intptr_t>* map) { 34 GrowableArray<intptr_t>* map) {
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 Script& script = Script::Handle(); 148 Script& script = Script::Handle();
149 String& saved_url = String::Handle(); 149 String& saved_url = String::Handle();
150 String& url = String::Handle(); 150 String& url = String::Handle();
151 GrowableArray<intptr_t> pos_to_line; 151 GrowableArray<intptr_t> pos_to_line;
152 int i = 0; 152 int i = 0;
153 while (i < functions.Length()) { 153 while (i < functions.Length()) {
154 HANDLESCOPE(isolate); 154 HANDLESCOPE(isolate);
155 function ^= functions.At(i); 155 function ^= functions.At(i);
156 script = function.script(); 156 script = function.script();
157 saved_url = script.url(); 157 saved_url = script.url();
158 if (!filter->ShouldOutputCoverageFor(lib, saved_url, cls, function)) { 158 if (!filter->ShouldOutputCoverageFor(lib, script, cls, function)) {
159 i++; 159 i++;
160 continue; 160 continue;
161 } 161 }
162 ComputeTokenPosToLineNumberMap(script, &pos_to_line); 162 ComputeTokenPosToLineNumberMap(script, &pos_to_line);
163 JSONObject jsobj(&jsarr); 163 JSONObject jsobj(&jsarr);
164 jsobj.AddProperty("source", saved_url.ToCString()); 164 jsobj.AddProperty("source", saved_url.ToCString());
165 jsobj.AddProperty("script", script); 165 jsobj.AddProperty("script", script);
166 JSONArray hits_arr(&jsobj, "hits"); 166 JSONArray hits_arr(&jsobj, "hits");
167 167
168 // We stay within this loop while we are seeing functions from the same 168 // We stay within this loop while we are seeing functions from the same
169 // source URI. 169 // source URI.
170 while (i < functions.Length()) { 170 while (i < functions.Length()) {
171 function ^= functions.At(i); 171 function ^= functions.At(i);
172 script = function.script(); 172 script = function.script();
173 url = script.url(); 173 url = script.url();
174 if (!url.Equals(saved_url)) { 174 if (!url.Equals(saved_url)) {
175 pos_to_line.Clear(); 175 pos_to_line.Clear();
176 break; 176 break;
177 } 177 }
178 if (!filter->ShouldOutputCoverageFor(lib, saved_url, cls, function)) { 178 if (!filter->ShouldOutputCoverageFor(lib, script, cls, function)) {
179 i++; 179 i++;
180 continue; 180 continue;
181 } 181 }
182 CompileAndAdd(function, hits_arr, pos_to_line); 182 CompileAndAdd(function, hits_arr, pos_to_line);
183 if (function.HasImplicitClosureFunction()) { 183 if (function.HasImplicitClosureFunction()) {
184 function = function.ImplicitClosureFunction(); 184 function = function.ImplicitClosureFunction();
185 CompileAndAdd(function, hits_arr, pos_to_line); 185 CompileAndAdd(function, hits_arr, pos_to_line);
186 } 186 }
187 i++; 187 i++;
188 } 188 }
189 } 189 }
190 190
191 GrowableObjectArray& closures = 191 GrowableObjectArray& closures =
192 GrowableObjectArray::Handle(cls.closures()); 192 GrowableObjectArray::Handle(cls.closures());
193 if (!closures.IsNull()) { 193 if (!closures.IsNull()) {
194 i = 0; 194 i = 0;
195 pos_to_line.Clear(); 195 pos_to_line.Clear();
196 // We need to keep rechecking the length of the closures array, as handling 196 // We need to keep rechecking the length of the closures array, as handling
197 // a closure potentially adds new entries to the end. 197 // a closure potentially adds new entries to the end.
198 while (i < closures.Length()) { 198 while (i < closures.Length()) {
199 HANDLESCOPE(isolate); 199 HANDLESCOPE(isolate);
200 function ^= closures.At(i); 200 function ^= closures.At(i);
201 script = function.script(); 201 script = function.script();
202 saved_url = script.url(); 202 saved_url = script.url();
203 if (!filter->ShouldOutputCoverageFor(lib, saved_url, cls, function)) { 203 if (!filter->ShouldOutputCoverageFor(lib, script, cls, function)) {
204 i++; 204 i++;
205 continue; 205 continue;
206 } 206 }
207 ComputeTokenPosToLineNumberMap(script, &pos_to_line); 207 ComputeTokenPosToLineNumberMap(script, &pos_to_line);
208 JSONObject jsobj(&jsarr); 208 JSONObject jsobj(&jsarr);
209 jsobj.AddProperty("source", saved_url.ToCString()); 209 jsobj.AddProperty("source", saved_url.ToCString());
210 jsobj.AddProperty("script", script); 210 jsobj.AddProperty("script", script);
211 JSONArray hits_arr(&jsobj, "hits"); 211 JSONArray hits_arr(&jsobj, "hits");
212 212
213 // We stay within this loop while we are seeing functions from the same 213 // We stay within this loop while we are seeing functions from the same
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 cls = it.GetNextClass(); 283 cls = it.GetNextClass();
284 ASSERT(!cls.IsNull()); 284 ASSERT(!cls.IsNull());
285 PrintClass(lib, cls, jsarr, filter); 285 PrintClass(lib, cls, jsarr, filter);
286 } 286 }
287 } 287 }
288 } 288 }
289 } 289 }
290 290
291 291
292 } // namespace dart 292 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/coverage.h ('k') | runtime/vm/coverage_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698