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

Side by Side Diff: runtime/bin/vmservice/client/lib/src/service/object.dart

Issue 357763004: Observatory requests coverage per script (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: add deployed Created 6 years, 5 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
« no previous file with comments | « runtime/bin/vmservice/client/lib/src/elements/script_view.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 service; 5 part of service;
6 6
7 /// A [ServiceObject] is an object known to the VM service and is tied 7 /// A [ServiceObject] is an object known to the VM service and is tied
8 /// to an owning [Isolate]. 8 /// to an owning [Isolate].
9 abstract class ServiceObject extends Observable { 9 abstract class ServiceObject extends Observable {
10 /// The owner of this [ServiceObject]. This can be an [Isolate], a 10 /// The owner of this [ServiceObject]. This can be an [Isolate], a
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 assert(!canCache); 153 assert(!canCache);
154 } 154 }
155 _id = map['id']; 155 _id = map['id'];
156 156
157 _serviceType = mapType; 157 _serviceType = mapType;
158 _update(map, mapIsRef); 158 _update(map, mapIsRef);
159 } 159 }
160 160
161 // Updates internal state from [map]. [map] can be a reference. 161 // Updates internal state from [map]. [map] can be a reference.
162 void _update(ObservableMap map, bool mapIsRef); 162 void _update(ObservableMap map, bool mapIsRef);
163
164 String relativeLink(String id) {
165 assert(id != null);
166 return "${link}/${id}";
167 }
168 }
169
170 abstract class Coverage {
171 // Following getters and functions will be provided by [ServiceObject].
172 ServiceObjectOwner get owner;
173 String get serviceType;
174 VM get vm;
175 String relativeLink(String id);
176
177 /// Default handler for coverage data.
178 void processCoverageData(List coverageData) {
179 coverageData.forEach((scriptCoverage) {
180 assert(scriptCoverage['script'] != null);
181 scriptCoverage['script']._processHits(scriptCoverage['hits']);
182 });
183 }
184
185 Future refreshCoverage() {
186 return vm.getAsMap(relativeLink('coverage')).then((ObservableMap map) {
187 var coverageOwner = (serviceType == 'Isolate') ? this : owner;
188 var coverage = new ServiceObject._fromMap(coverageOwner, map);
189 assert(coverage.serviceType == 'CodeCoverage');
190 var coverageList = coverage['coverage'];
191 assert(coverageList != null);
192 processCoverageData(coverageList);
193 });
194 }
163 } 195 }
164 196
165 abstract class ServiceObjectOwner extends ServiceObject { 197 abstract class ServiceObjectOwner extends ServiceObject {
166 /// Creates an empty [ServiceObjectOwner]. 198 /// Creates an empty [ServiceObjectOwner].
167 ServiceObjectOwner._empty(ServiceObjectOwner owner) : super._empty(owner); 199 ServiceObjectOwner._empty(ServiceObjectOwner owner) : super._empty(owner);
168 200
169 /// Builds a [ServiceObject] corresponding to the [id] from [map]. 201 /// Builds a [ServiceObject] corresponding to the [id] from [map].
170 /// The result may come from the cache. The result will not necessarily 202 /// The result may come from the cache. The result will not necessarily
171 /// be [loaded]. 203 /// be [loaded].
172 ServiceObject getFromMap(ObservableMap map); 204 ServiceObject getFromMap(ObservableMap map);
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 used = heapMap['used']; 533 used = heapMap['used'];
502 capacity = heapMap['capacity']; 534 capacity = heapMap['capacity'];
503 external = heapMap['external']; 535 external = heapMap['external'];
504 collections = heapMap['collections']; 536 collections = heapMap['collections'];
505 totalCollectionTimeInSeconds = heapMap['time']; 537 totalCollectionTimeInSeconds = heapMap['time'];
506 averageCollectionPeriodInMillis = heapMap['avgCollectionPeriodMillis']; 538 averageCollectionPeriodInMillis = heapMap['avgCollectionPeriodMillis'];
507 } 539 }
508 } 540 }
509 541
510 /// State for a running isolate. 542 /// State for a running isolate.
511 class Isolate extends ServiceObjectOwner { 543 class Isolate extends ServiceObjectOwner with Coverage {
512 @reflectable VM get vm => owner; 544 @reflectable VM get vm => owner;
513 @reflectable Isolate get isolate => this; 545 @reflectable Isolate get isolate => this;
514 @observable ObservableMap counters = new ObservableMap(); 546 @observable ObservableMap counters = new ObservableMap();
515 547
516 String get link => '/${_id}'; 548 String get link => '/${_id}';
517 549
518 @observable ServiceMap pauseEvent = null; 550 @observable ServiceMap pauseEvent = null;
519 bool get _isPaused => pauseEvent != null; 551 bool get _isPaused => pauseEvent != null;
520 552
521 @observable bool running = false; 553 @observable bool running = false;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 601
570 void _updateProfileData(ServiceMap profile, List<Code> codeTable) { 602 void _updateProfileData(ServiceMap profile, List<Code> codeTable) {
571 var codeRegions = profile['codes']; 603 var codeRegions = profile['codes'];
572 var sampleCount = profile['samples']; 604 var sampleCount = profile['samples'];
573 for (var codeRegion in codeRegions) { 605 for (var codeRegion in codeRegions) {
574 Code code = codeRegion['code']; 606 Code code = codeRegion['code'];
575 code.updateProfileData(codeRegion, codeTable, sampleCount); 607 code.updateProfileData(codeRegion, codeTable, sampleCount);
576 } 608 }
577 } 609 }
578 610
579 Future refreshCoverage() {
580 return get('coverage').then(_processCoverage);
581 }
582
583 void _processCoverage(ServiceMap coverage) {
584 assert(coverage.serviceType == 'CodeCoverage');
585 var coverageList = coverage['coverage'];
586 assert(coverageList != null);
587 coverageList.forEach((scriptCoverage) {
588 _processScriptCoverage(scriptCoverage);
589 });
590 }
591
592 void _processScriptCoverage(ObservableMap scriptCoverage) {
593 // Because the coverage data was upgraded into a ServiceObject,
594 // the script can be directly accessed.
595 Script script = scriptCoverage['script'];
596 assert(_cache.containsValue(script));
597 script._processHits(scriptCoverage['hits']);
598 }
599
600 /// Fetches and builds the class hierarchy for this isolate. Returns the 611 /// Fetches and builds the class hierarchy for this isolate. Returns the
601 /// Object class object. 612 /// Object class object.
602 Future<Class> getClassHierarchy() { 613 Future<Class> getClassHierarchy() {
603 return get('classes').then(_loadClasses).then(_buildClassHierarchy); 614 return get('classes').then(_loadClasses).then(_buildClassHierarchy);
604 } 615 }
605 616
606 /// Given the class list, loads each class. 617 /// Given the class list, loads each class.
607 Future<List<Class>> _loadClasses(ServiceMap classList) { 618 Future<List<Class>> _loadClasses(ServiceMap classList) {
608 assert(classList.serviceType == 'ClassList'); 619 assert(classList.serviceType == 'ClassList');
609 var futureClasses = []; 620 var futureClasses = [];
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 956
946 void _update(ObservableMap map, bool mapIsRef) { 957 void _update(ObservableMap map, bool mapIsRef) {
947 kind = map['kind']; 958 kind = map['kind'];
948 message = map['message']; 959 message = map['message'];
949 response = map['response']; 960 response = map['response'];
950 name = 'ServiceException $kind'; 961 name = 'ServiceException $kind';
951 vmName = name; 962 vmName = name;
952 } 963 }
953 } 964 }
954 965
955 class Library extends ServiceObject { 966 class Library extends ServiceObject with Coverage {
956 @observable String url; 967 @observable String url;
957 @reflectable final imports = new ObservableList<Library>(); 968 @reflectable final imports = new ObservableList<Library>();
958 @reflectable final scripts = new ObservableList<Script>(); 969 @reflectable final scripts = new ObservableList<Script>();
959 @reflectable final classes = new ObservableList<Class>(); 970 @reflectable final classes = new ObservableList<Class>();
960 @reflectable final variables = new ObservableList<ServiceMap>(); 971 @reflectable final variables = new ObservableList<ServiceMap>();
961 @reflectable final functions = new ObservableList<ServiceMap>(); 972 @reflectable final functions = new ObservableList<ServiceMap>();
962 973
963 bool get canCache => true; 974 bool get canCache => true;
964 bool get immutable => false; 975 bool get immutable => false;
965 976
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 void update(List stats) { 1035 void update(List stats) {
1025 accumulated.instances = stats[ACCUMULATED]; 1036 accumulated.instances = stats[ACCUMULATED];
1026 accumulated.bytes = stats[ACCUMULATED_SIZE]; 1037 accumulated.bytes = stats[ACCUMULATED_SIZE];
1027 current.instances = stats[LIVE_AFTER_GC] + stats[ALLOCATED_SINCE_GC]; 1038 current.instances = stats[LIVE_AFTER_GC] + stats[ALLOCATED_SINCE_GC];
1028 current.bytes = stats[LIVE_AFTER_GC_SIZE] + stats[ALLOCATED_SINCE_GC_SIZE]; 1039 current.bytes = stats[LIVE_AFTER_GC_SIZE] + stats[ALLOCATED_SINCE_GC_SIZE];
1029 } 1040 }
1030 1041
1031 bool get empty => accumulated.empty && current.empty; 1042 bool get empty => accumulated.empty && current.empty;
1032 } 1043 }
1033 1044
1034 class Class extends ServiceObject { 1045 class Class extends ServiceObject with Coverage {
1035 @observable Library library; 1046 @observable Library library;
1036 @observable Script script; 1047 @observable Script script;
1037 @observable Class superClass; 1048 @observable Class superClass;
1038 1049
1039 @observable bool isAbstract; 1050 @observable bool isAbstract;
1040 @observable bool isConst; 1051 @observable bool isConst;
1041 @observable bool isFinalized; 1052 @observable bool isFinalized;
1042 @observable bool isPatch; 1053 @observable bool isPatch;
1043 @observable bool isImplemented; 1054 @observable bool isImplemented;
1044 1055
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1131 } 1142 }
1132 } 1143 }
1133 1144
1134 class ScriptLine extends Observable { 1145 class ScriptLine extends Observable {
1135 final int line; 1146 final int line;
1136 final String text; 1147 final String text;
1137 @observable int hits; 1148 @observable int hits;
1138 ScriptLine(this.line, this.text); 1149 ScriptLine(this.line, this.text);
1139 } 1150 }
1140 1151
1141 class Script extends ServiceObject { 1152 class Script extends ServiceObject with Coverage {
1142 final lines = new ObservableList<ScriptLine>(); 1153 final lines = new ObservableList<ScriptLine>();
1143 final _hits = new Map<int, int>(); 1154 final _hits = new Map<int, int>();
1144 @observable String kind; 1155 @observable String kind;
1145 @observable int firstTokenPos; 1156 @observable int firstTokenPos;
1146 @observable int lastTokenPos; 1157 @observable int lastTokenPos;
1147 bool get canCache => true; 1158 bool get canCache => true;
1148 bool get immutable => true; 1159 bool get immutable => true;
1149 1160
1150 String _shortUrl; 1161 String _shortUrl;
1151 String _url; 1162 String _url;
(...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after
1829 var v = list[i]; 1840 var v = list[i];
1830 if ((v is ObservableMap) && _isServiceMap(v)) { 1841 if ((v is ObservableMap) && _isServiceMap(v)) {
1831 list[i] = owner.getFromMap(v); 1842 list[i] = owner.getFromMap(v);
1832 } else if (v is ObservableList) { 1843 } else if (v is ObservableList) {
1833 _upgradeObservableList(v, owner); 1844 _upgradeObservableList(v, owner);
1834 } else if (v is ObservableMap) { 1845 } else if (v is ObservableMap) {
1835 _upgradeObservableMap(v, owner); 1846 _upgradeObservableMap(v, owner);
1836 } 1847 }
1837 } 1848 }
1838 } 1849 }
OLDNEW
« no previous file with comments | « runtime/bin/vmservice/client/lib/src/elements/script_view.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698