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

Side by Side Diff: lib/src/source_report.dart

Issue 1929063002: pkg/vm_service_client: add getSourceReport to VMServiceReference (Closed) Base URL: https://github.com/dart-lang/vm_service_client.git@master
Patch Set: code review Created 4 years, 7 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
OLDNEW
(Empty)
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
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.
4
5 import 'script.dart';
6 import 'scope.dart';
7 import 'source_location.dart';
8
9 List<VMScriptToken> _getTokens(VMScriptRef script, Iterable<int> locations) {
10 if (locations == null) return null;
11
12 return new List<VMScriptToken>.unmodifiable(
13 locations.map((i) => newVMScriptTokenFromScript(script, i)));
14 }
15
16 VMSourceReport newSourceReport(Scope scope, Map json) {
17 if (json == null) return null;
18 assert(json["type"] == "SourceReport");
19
20 var scripts = (json['scripts'] as List)
21 .map((scriptItem) => newVMScriptRef(scope, scriptItem))
22 .toList();
23
24 var ranges = new List<VMSourceReportRange>.unmodifiable(
25 (json['ranges'] as List)
26 .map((rangeItem) => _newSourceReportRange(rangeItem, scripts)));
27
28 return new VMSourceReport._(ranges);
29 }
30
31 VMSourceReportRange _newSourceReportRange(Map json, List<VMScriptRef> scripts) {
32 if (json == null) return null;
33
34 var script = scripts[json['scriptIndex']];
35
36 var location =
37 newVMSourceLocationFromLocation(script, json['startPos'], json['endPos']);
38
39 return new VMSourceReportRange._(json, script, location);
40 }
41
42 /// A report about ranges of source code.
43 ///
44 /// [ranges] exposes code coverage and information on possible breakpoints.
45 class VMSourceReport {
46 /// Ranges in the program source corresponding
47 /// to ranges of executable code in the user's program (functions,
48 /// methods, constructors, etc.)
49 ///
50 /// Note:
51 /// * ranges may nest in other ranges, in the case of nested
52 /// functions.
53 /// * ranges may be duplicated, in the case of mixins.
54 final List<VMSourceReportRange> ranges;
55
56 VMSourceReport._(this.ranges);
57 }
58
59 /// A range of executable code (function, method, constructor, etc)
60 /// in the running program.
61 ///
62 /// This is part of a [VMSourceReport].
63 class VMSourceReportRange {
64 VMScriptRef get script => location.script;
65
66 final VMSourceLocation location;
67
68 /// `true` if this range been compiled by the Dart VM.
69 ///
70 /// If `false`, `possibleBreakpoints`, `hits`, and `misses` will be `null`.
71 ///
72 /// Use `forceCompile` in `getSourceReport` to ensure the target scripts are
73 /// compiled.
74 final bool compiled;
75
76 /// Token locations at which breakpoints can be set.
77 ///
78 /// Provided only when the when the `includePossibleBreakpoints` in
79 /// `getSourceReport` is `true` and the range has been compiled.
80 final List<VMScriptToken> possibleBreakpoints;
81
82 /// A sorted list of token positions in a [VMSourceReportRang] which have been
83 /// executed.
84 ///
85 /// Provided only when the when the `includeCoverageReport` in
86 /// `getSourceReport` is `true` and the range has been compiled.
87 final List<VMScriptToken> hits;
88
89 /// A sorted list of token positions in a [VMSourceReportRange] which have not
90 /// yet been executed.
91 ///
92 /// Provided only when the
93 /// `includeCoverageReport` is true and the range has been
94 /// compiled.
95 final List<VMScriptToken> misses;
96
97 VMSourceReportRange._(Map json, VMScriptRef script, this.location)
98 : compiled = json['compiled'],
99 hits = json['coverage'] == null
100 ? null
101 : _getTokens(script, json['coverage']['hits']),
102 misses = json['coverage'] == null
103 ? null
104 : _getTokens(script, json['coverage']['misses']),
105 possibleBreakpoints = json['possibleBreakpoints'] == null
106 ? null
107 : _getTokens(script, json['possibleBreakpoints']);
108 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698