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

Side by Side Diff: runtime/bin/vmservice/client/lib/src/observatory/model.dart

Issue 143973005: Code coverage in Observatory (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 11 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 part of observatory; 5 part of observatory;
6 6
7 class CodeInstruction extends Observable { 7 class CodeInstruction extends Observable {
8 @observable final int address; 8 @observable final int address;
9 @observable final String machine; 9 @observable final String machine;
10 @observable final String human; 10 @observable final String human;
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 List<Code> inclusive = isolate.codes; 237 List<Code> inclusive = isolate.codes;
238 inclusive.sort((Code a, Code b) { 238 inclusive.sort((Code a, Code b) {
239 return b.inclusiveTicks - a.inclusiveTicks; 239 return b.inclusiveTicks - a.inclusiveTicks;
240 }); 240 });
241 if ((inclusive.length < count) || (count == 0)) { 241 if ((inclusive.length < count) || (count == 0)) {
242 return inclusive; 242 return inclusive;
243 } 243 }
244 return inclusive.sublist(0, count); 244 return inclusive.sublist(0, count);
245 } 245 }
246 } 246 }
247
248 class ScriptLine extends Observable {
249 @observable final int line;
250 @observable int hits = -1;
251 @observable String text = '';
252 /// Do we have coverage data for this line?
253 bool get coverage => hits >= 0;
254 /// Has this line executed before?
255 bool get covered => hits > 0;
turnidge 2014/01/21 23:34:40 the names "coverage" and "covered" are a bit simil
Cutch 2014/01/22 00:50:37 Agreed. I've gone with "executable" and "covered".
256 ScriptLine(this.line);
257 }
258
259 class Script extends Observable {
260 @observable String kind = null;
261 @observable Map scriptRef = toObservable({});
262 @observable Map libraryRef = toObservable({});
263 @observable final List<ScriptLine> lines =
264 toObservable(new List<ScriptLine>());
265 bool _needsSource = true;
266 bool get needsSource => _needsSource;
267 Script.fromMap(Map map) {
268 scriptRef = toObservable({
269 'id': map['id'],
270 'name': map['name'],
271 'user_name': map['user_name']
272 });
273 libraryRef = toObservable(map['library']);
274 kind = map['kind'];
275 _processSource(map['source']);
276 }
277
278 // Fetch (possibly create) the ScriptLine for [lineNumber].
279 ScriptLine _getLine(int lineNumber) {
280 assert(lineNumber != 0);
281 if (lineNumber >= lines.length) {
282 // Grow lines list.
283 lines.length = lineNumber + 1;
284 }
285 var line = lines[lineNumber];
286 if (line == null) {
287 // Create this line.
288 line = new ScriptLine(lineNumber);
289 lines[lineNumber] = line;
290 }
291 return line;
292 }
293
294 void _processSource(String source) {
295 if (source == null) {
296 return;
297 }
298 Logger.root.info('Loading source for ${scriptRef['name']}');
299 var sourceLines = source.split('\n');
300 _needsSource = sourceLines.length == 0;
301 for (var i = 0; i < sourceLines.length; i++) {
302 var line = _getLine(i + 1);
303 line.text = sourceLines[i];
304 }
305 }
306
307 void _processCoverageHits(List hits) {
308 for (var i = 0; i < hits.length; i += 2) {
309 var line = _getLine(hits[i]);
310 line.hits = hits[i + 1];
311 }
312 notifyPropertyChange(#coveredPercentage, 0.0, coveredPercentage());
313 }
314
315 /// What percentage of lines in this script have been covered?
316 double coveredPercentage() {
317 int coveredLines = 0;
318 int coverageLines = 0;
319 for (var line in lines) {
320 if (line == null) {
321 continue;
322 }
323 if (!line.coverage) {
324 continue;
325 }
326 coverageLines++;
327 if (!line.covered) {
328 continue;
329 }
330 coveredLines++;
331 }
332 if (coverageLines == 0) {
333 return 0.0;
334 }
335 return (coveredLines / coverageLines) * 100.0;
336 }
337 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698