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

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

Issue 346003003: vmservice: Add /coverage collection to scripts, classes and libraries. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: exclude service_classescoverage from simmips tests 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 unified diff | Download patch | Annotate | Revision Log
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"
(...skipping 23 matching lines...) Expand all
34 while (tkit.CurrentTokenKind() != Token::kEOS) { 34 while (tkit.CurrentTokenKind() != Token::kEOS) {
35 (*map)[tkit.CurrentPosition()] = cur_line; 35 (*map)[tkit.CurrentPosition()] = cur_line;
36 if (tkit.CurrentTokenKind() == Token::kNEWLINE) { 36 if (tkit.CurrentTokenKind() == Token::kNEWLINE) {
37 cur_line++; 37 cur_line++;
38 } 38 }
39 tkit.Advance(); 39 tkit.Advance();
40 } 40 }
41 } 41 }
42 42
43 43
44 static inline void PrintJSONPreamble(JSONObject* jsobj) {
45 jsobj->AddProperty("type", "CodeCoverage");
46 jsobj->AddProperty("id", "coverage");
47 }
48
49
44 void CodeCoverage::CompileAndAdd(const Function& function, 50 void CodeCoverage::CompileAndAdd(const Function& function,
45 const JSONArray& hits_arr, 51 const JSONArray& hits_arr,
46 const GrowableArray<intptr_t>& pos_to_line) { 52 const GrowableArray<intptr_t>& pos_to_line) {
47 Isolate* isolate = Isolate::Current(); 53 Isolate* isolate = Isolate::Current();
48 if (!function.HasCode()) { 54 if (!function.HasCode()) {
49 // If the function should not be compiled or if the compilation failed, 55 // If the function should not be compiled or if the compilation failed,
50 // then just skip this method. 56 // then just skip this method.
51 // TODO(iposva): Maybe we should skip synthesized methods in general too. 57 // TODO(iposva): Maybe we should skip synthesized methods in general too.
52 if (function.is_abstract() || function.IsRedirectingFactory()) { 58 if (function.is_abstract() || function.IsRedirectingFactory()) {
53 return; 59 return;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 } 122 }
117 } 123 }
118 // Write last hit value if needed. 124 // Write last hit value if needed.
119 if (last_line != -1) { 125 if (last_line != -1) {
120 hits_arr.AddValue(last_line); 126 hits_arr.AddValue(last_line);
121 hits_arr.AddValue(last_count); 127 hits_arr.AddValue(last_count);
122 } 128 }
123 } 129 }
124 130
125 131
126 void CodeCoverage::PrintClass(const Class& cls, const JSONArray& jsarr) { 132 void CodeCoverage::PrintClass(const Class& cls,
133 const JSONArray& jsarr,
134 const Script& script_filter) {
127 Isolate* isolate = Isolate::Current(); 135 Isolate* isolate = Isolate::Current();
128 if (cls.EnsureIsFinalized(isolate) != Error::null()) { 136 if (cls.EnsureIsFinalized(isolate) != Error::null()) {
129 // Only classes that have been finalized do have a meaningful list of 137 // Only classes that have been finalized do have a meaningful list of
130 // functions. 138 // functions.
131 return; 139 return;
132 } 140 }
133 Array& functions = Array::Handle(cls.functions()); 141 Array& functions = Array::Handle(cls.functions());
134 ASSERT(!functions.IsNull()); 142 ASSERT(!functions.IsNull());
135 Function& function = Function::Handle(); 143 Function& function = Function::Handle();
136 Script& script = Script::Handle(); 144 Script& script = Script::Handle();
137 String& saved_url = String::Handle(); 145 String& saved_url = String::Handle();
138 String& url = String::Handle(); 146 String& url = String::Handle();
139 GrowableArray<intptr_t> pos_to_line; 147 GrowableArray<intptr_t> pos_to_line;
140 int i = 0; 148 int i = 0;
141 while (i < functions.Length()) { 149 while (i < functions.Length()) {
142 HANDLESCOPE(isolate); 150 HANDLESCOPE(isolate);
143 function ^= functions.At(i); 151 function ^= functions.At(i);
152 script = function.script();
153 if (!script_filter.IsNull() && script_filter.raw() != script.raw()) {
154 i++;
155 continue;
156 }
157 saved_url = script.url();
158 ComputeTokenPosToLineNumberMap(script, &pos_to_line);
144 JSONObject jsobj(&jsarr); 159 JSONObject jsobj(&jsarr);
145 script = function.script();
146 ComputeTokenPosToLineNumberMap(script, &pos_to_line);
147 saved_url = script.url();
148 jsobj.AddProperty("source", saved_url.ToCString()); 160 jsobj.AddProperty("source", saved_url.ToCString());
149 jsobj.AddProperty("script", script); 161 jsobj.AddProperty("script", script);
150 JSONArray hits_arr(&jsobj, "hits"); 162 JSONArray hits_arr(&jsobj, "hits");
151 163
152 // We stay within this loop while we are seeing functions from the same 164 // We stay within this loop while we are seeing functions from the same
153 // source URI. 165 // source URI.
154 while (i < functions.Length()) { 166 while (i < functions.Length()) {
155 function ^= functions.At(i); 167 function ^= functions.At(i);
156 script = function.script(); 168 script = function.script();
157 url = script.url(); 169 url = script.url();
(...skipping 13 matching lines...) Expand all
171 GrowableObjectArray& closures = 183 GrowableObjectArray& closures =
172 GrowableObjectArray::Handle(cls.closures()); 184 GrowableObjectArray::Handle(cls.closures());
173 if (!closures.IsNull()) { 185 if (!closures.IsNull()) {
174 i = 0; 186 i = 0;
175 pos_to_line.Clear(); 187 pos_to_line.Clear();
176 // We need to keep rechecking the length of the closures array, as handling 188 // We need to keep rechecking the length of the closures array, as handling
177 // a closure potentially adds new entries to the end. 189 // a closure potentially adds new entries to the end.
178 while (i < closures.Length()) { 190 while (i < closures.Length()) {
179 HANDLESCOPE(isolate); 191 HANDLESCOPE(isolate);
180 function ^= closures.At(i); 192 function ^= closures.At(i);
193 script = function.script();
194 if (!script_filter.IsNull() && script_filter.raw() != script.raw()) {
195 i++;
196 continue;
197 }
198 saved_url = script.url();
199 ComputeTokenPosToLineNumberMap(script, &pos_to_line);
181 JSONObject jsobj(&jsarr); 200 JSONObject jsobj(&jsarr);
182 script = function.script();
183 ComputeTokenPosToLineNumberMap(script, &pos_to_line);
184 saved_url = script.url();
185 jsobj.AddProperty("source", saved_url.ToCString()); 201 jsobj.AddProperty("source", saved_url.ToCString());
186 jsobj.AddProperty("script", script); 202 jsobj.AddProperty("script", script);
187 JSONArray hits_arr(&jsobj, "hits"); 203 JSONArray hits_arr(&jsobj, "hits");
188 204
189 // We stay within this loop while we are seeing functions from the same 205 // We stay within this loop while we are seeing functions from the same
190 // source URI. 206 // source URI.
191 while (i < closures.Length()) { 207 while (i < closures.Length()) {
192 function ^= closures.At(i); 208 function ^= closures.At(i);
193 script = function.script(); 209 script = function.script();
194 url = script.url(); 210 url = script.url();
195 if (!url.Equals(saved_url)) { 211 if (!url.Equals(saved_url)) {
196 pos_to_line.Clear(); 212 pos_to_line.Clear();
197 break; 213 break;
198 } 214 }
199 CompileAndAdd(function, hits_arr, pos_to_line); 215 CompileAndAdd(function, hits_arr, pos_to_line);
200 i++; 216 i++;
201 } 217 }
202 } 218 }
203 } 219 }
204 } 220 }
205 221
206 222
223 void CodeCoverage::PrintJSONForClass(const Class& cls,
224 JSONStream* stream) {
225 JSONObject coverage(stream);
226 PrintJSONPreamble(&coverage);
227 {
228 JSONArray jsarr(&coverage, "coverage");
229 PrintClass(cls, jsarr, Script::Handle());
230 }
231 }
232
233
234 void CodeCoverage::PrintJSONForLibrary(const Library& lib,
235 const Script& script_filter,
236 JSONStream* stream) {
237 Class& cls = Class::Handle();
238 JSONObject coverage(stream);
239 PrintJSONPreamble(&coverage);
240 {
241 JSONArray jsarr(&coverage, "coverage");
242 ClassDictionaryIterator it(lib, ClassDictionaryIterator::kIteratePrivate);
243 while (it.HasNext()) {
244 cls = it.GetNextClass();
245 ASSERT(!cls.IsNull());
246 PrintClass(cls, jsarr, script_filter);
247 }
248 }
249 }
250
251
252 void CodeCoverage::PrintJSONForScript(const Script& script,
253 JSONStream* stream) {
254 Library& lib = Library::Handle();
255 lib = script.FindLibrary();
256 ASSERT(!lib.IsNull());
257 PrintJSONForLibrary(lib, script, stream);
258 }
259
260
207 void CodeCoverage::Write(Isolate* isolate) { 261 void CodeCoverage::Write(Isolate* isolate) {
208 if (FLAG_coverage_dir == NULL) { 262 if (FLAG_coverage_dir == NULL) {
209 return; 263 return;
210 } 264 }
211 265
212 Dart_FileOpenCallback file_open = Isolate::file_open_callback(); 266 Dart_FileOpenCallback file_open = Isolate::file_open_callback();
213 Dart_FileWriteCallback file_write = Isolate::file_write_callback(); 267 Dart_FileWriteCallback file_write = Isolate::file_write_callback();
214 Dart_FileCloseCallback file_close = Isolate::file_close_callback(); 268 Dart_FileCloseCallback file_close = Isolate::file_close_callback();
215 if ((file_open == NULL) || (file_write == NULL) || (file_close == NULL)) { 269 if ((file_open == NULL) || (file_write == NULL) || (file_close == NULL)) {
216 return; 270 return;
(...skipping 27 matching lines...) Expand all
244 JSONObject coverage(stream); 298 JSONObject coverage(stream);
245 coverage.AddProperty("type", "CodeCoverage"); 299 coverage.AddProperty("type", "CodeCoverage");
246 coverage.AddProperty("id", "coverage"); 300 coverage.AddProperty("id", "coverage");
247 { 301 {
248 JSONArray jsarr(&coverage, "coverage"); 302 JSONArray jsarr(&coverage, "coverage");
249 for (int i = 0; i < libs.Length(); i++) { 303 for (int i = 0; i < libs.Length(); i++) {
250 lib ^= libs.At(i); 304 lib ^= libs.At(i);
251 ClassDictionaryIterator it(lib, ClassDictionaryIterator::kIteratePrivate); 305 ClassDictionaryIterator it(lib, ClassDictionaryIterator::kIteratePrivate);
252 while (it.HasNext()) { 306 while (it.HasNext()) {
253 cls = it.GetNextClass(); 307 cls = it.GetNextClass();
254 PrintClass(cls, jsarr); 308 ASSERT(!cls.IsNull());
309 PrintClass(cls, jsarr, Script::Handle());
255 } 310 }
256 } 311 }
257 } 312 }
258 } 313 }
259 314
260 315
261 } // namespace dart 316 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/coverage.h ('k') | runtime/vm/object.h » ('j') | runtime/vm/object.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698