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

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: code review Created 4 years, 8 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
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..b247652a05a5cd2d5d802ed6360ed3901e5e133e
--- /dev/null
+++ b/lib/src/source_report.dart
@@ -0,0 +1,108 @@
+// 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';
+
+List<VMScriptToken> _getTokens(VMScriptRef script, Iterable<int> locations) {
+ if (locations == null) return null;
+
+ return new List<VMScriptToken>.unmodifiable(
+ locations.map((i) => newVMScriptTokenFromScript(script, i)));
+}
+
+VMSourceReport newSourceReport(Scope scope, Map json) {
+ if (json == null) return null;
+ assert(json["type"] == "SourceReport");
+
+ var scripts = (json['scripts'] as List)
+ .map((scriptItem) => newVMScriptRef(scope, scriptItem))
+ .toList();
+
+ var ranges = new List<VMSourceReportRange>.unmodifiable(
+ (json['ranges'] as List)
+ .map((rangeItem) => _newSourceReportRange(rangeItem, scripts)));
+
+ return new VMSourceReport._(ranges);
+}
+
+VMSourceReportRange _newSourceReportRange(Map json, List<VMScriptRef> scripts) {
+ if (json == null) return null;
+
+ var script = scripts[json['scriptIndex']];
+
+ var location =
+ newVMSourceLocationFromLocation(script, json['startPos'], json['endPos']);
+
+ return new VMSourceReportRange._(json, script, location);
+}
+
+/// 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 (functions,
+ /// methods, constructors, etc.)
+ ///
+ /// 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;
+
+ 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 locations at which breakpoints can be set.
+ ///
+ /// Provided only when the when the `includePossibleBreakpoints` in
+ /// `getSourceReport` is `true` and the range has been compiled.
+ final List<VMScriptToken> possibleBreakpoints;
+
+ /// A sorted list of token positions in a [VMSourceReportRang] which have been
+ /// executed.
+ ///
+ /// Provided only when the when the `includeCoverageReport` in
+ /// `getSourceReport` is `true` and the range has been compiled.
+ final List<VMScriptToken> hits;
+
+ /// A sorted list of token positions in a [VMSourceReportRange] which have not
+ /// yet been executed.
+ ///
+ /// Provided only when the
+ /// `includeCoverageReport` is true and the range has been
+ /// compiled.
+ final List<VMScriptToken> misses;
+
+ VMSourceReportRange._(Map json, VMScriptRef script, this.location)
+ : compiled = json['compiled'],
+ hits = json['coverage'] == null
+ ? null
+ : _getTokens(script, json['coverage']['hits']),
+ misses = json['coverage'] == null
+ ? null
+ : _getTokens(script, json['coverage']['misses']),
+ possibleBreakpoints = json['possibleBreakpoints'] == null
+ ? null
+ : _getTokens(script, json['possibleBreakpoints']);
+}

Powered by Google App Engine
This is Rietveld 408576698