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

Unified 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: nits 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/source_location.dart ('k') | lib/vm_service_client.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/source_report.dart
diff --git a/lib/src/source_report.dart b/lib/src/source_report.dart
new file mode 100644
index 0000000000000000000000000000000000000000..b1d9f3fb160771595fac193390bec31d2ecaf130
--- /dev/null
+++ b/lib/src/source_report.dart
@@ -0,0 +1,120 @@
+// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'script.dart';
+import 'scope.dart';
+import 'source_location.dart';
+
+VMSourceReport newSourceReport(Scope scope, Map json) {
+ if (json == null) return null;
+ assert(json["type"] == "SourceReport");
+
+ var scripts = (json['scripts'] as List)
+ .map((script) => newVMScriptRef(scope, script))
+ .toList();
+
+ var ranges = new List<VMSourceReportRange>.unmodifiable(
+ (json['ranges'] as List).map((rangeItem) =>
+ new VMSourceReportRange._fromJson(rangeItem, scripts)));
+
+ return new VMSourceReport._(ranges);
+}
+
+/// A report about ranges of source code.
+///
+/// [ranges] exposes code coverage and information on possible breakpoints.
+class VMSourceReport {
+ /// Ranges in the program source corresponding to ranges of executable code in
+ /// the user's program.
+ ///
+ /// Ranges can include members such as functions, methods, and
+ /// constructors.
+ ///
+ /// Note: ranges may nest in other ranges, in the case of nested functions.
+ /// Ranges may be duplicated, in the case of mixins.
+ final List<VMSourceReportRange> ranges;
+
+ VMSourceReport._(this.ranges);
+}
+
+/// A range of executable code (function, method, constructor, etc)
+/// in the running program.
+///
+/// This is part of a [VMSourceReport].
+class VMSourceReportRange {
+ VMScriptRef get script => location.script;
+
+ /// The location of the range in the target script.
+ final VMSourceLocation location;
+
+ /// `true` if this range been compiled by the Dart VM.
+ ///
+ /// If `false`, `possibleBreakpoints`, `hits`, and `misses` will be `null`.
+ ///
+ /// Use `forceCompile` in `getSourceReport` to ensure the target scripts are
+ /// compiled.
+ final bool compiled;
+
+ /// Token positions at which breakpoints can be set.
+ ///
+ /// Provided only when `includePossibleBreakpoints` in `getSourceReport`
+ /// is `true` and the range has been compiled.
+ final List<VMScriptToken> possibleBreakpoints;
+
+ /// Token positions in this range which have been executed.
+ ///
+ /// Provided only when `includeCoverageReport` in `getSourceReport` is `true`
+ /// and the range has been compiled.
+ ///
+ /// Sorted by the position in the source file, starting with the first hit.
+ final List<VMScriptToken> hits;
+
+ /// Token positions in this range which have not yet been executed.
+ ///
+ /// Provided only when `includeCoverageReport` in `getSourceReport` is `true`
+ /// and the range has been compiled.
+ ///
+ /// Sorted by the location in the source file, starting with the first miss.
+ final List<VMScriptToken> misses;
+
+ /// Creates a new [VMSourceReportRange].
+ ///
+ /// [json] corresponds to data returned by the `getSourceReport` RPC.
+ ///
+ /// [scripts] is used to find the [VMScriptRef] referenced by index in [json].
+ factory VMSourceReportRange._fromJson(Map json, List<VMScriptRef> scripts) {
+ var script = scripts[json['scriptIndex']];
+
+ var location = newVMSourceLocationFromPosition(
+ script, json['startPos'], json['endPos']);
+
+ var compiled = json['compiled'];
+
+ var hits = json['coverage'] == null
+ ? null
+ : _getTokens(script, json['coverage']['hits']);
+
+ var misses = json['coverage'] == null
+ ? null
+ : _getTokens(script, json['coverage']['misses']);
+
+ var possibleBreakpoints = json['possibleBreakpoints'] == null
+ ? null
+ : _getTokens(script, json['possibleBreakpoints']);
+
+ return new VMSourceReportRange._(
+ compiled, hits, misses, possibleBreakpoints, location);
+ }
+
+ VMSourceReportRange._(this.compiled, this.hits, this.misses,
+ this.possibleBreakpoints, this.location);
+
+ /// Returns an unmodifiable [List<VMScriptToken>] corresponding to the
+ /// provided token [locations].
+ static List<VMScriptToken> _getTokens(
+ VMScriptRef script, Iterable<int> locations) {
+ return new List<VMScriptToken>.unmodifiable(locations
+ .map((position) => newVMScriptTokenFromPosition(script, position)));
+ }
+}
« no previous file with comments | « lib/src/source_location.dart ('k') | lib/vm_service_client.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698