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

Side by Side Diff: runtime/observatory/lib/src/service/object.dart

Issue 1398823002: We can now name the current VM using the service protocol. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 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
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 /// Helper function for canceling a Future<StreamSubscription>. 7 /// Helper function for canceling a Future<StreamSubscription>.
8 Future cancelFutureSubscription( 8 Future cancelFutureSubscription(
9 Future<StreamSubscription> subscriptionFuture) async { 9 Future<StreamSubscription> subscriptionFuture) async {
10 if (subscriptionFuture != null) { 10 if (subscriptionFuture != null) {
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 final ObservableList<Isolate> isolates = new ObservableList<Isolate>(); 633 final ObservableList<Isolate> isolates = new ObservableList<Isolate>();
634 634
635 @observable String version = 'unknown'; 635 @observable String version = 'unknown';
636 @observable String targetCPU; 636 @observable String targetCPU;
637 @observable int architectureBits; 637 @observable int architectureBits;
638 @observable bool assertsEnabled = false; 638 @observable bool assertsEnabled = false;
639 @observable bool typeChecksEnabled = false; 639 @observable bool typeChecksEnabled = false;
640 @observable int pid = 0; 640 @observable int pid = 0;
641 @observable DateTime startTime; 641 @observable DateTime startTime;
642 @observable DateTime refreshTime; 642 @observable DateTime refreshTime;
643 @observable Duration get upTime => 643 @observable Duration get upTime {
644 (new DateTime.now().difference(startTime)); 644 if (startTime == null) {
645 return null;
646 }
647 return (new DateTime.now().difference(startTime));
648 }
649 @observable String get nameAndAddress => '${name}@${target.networkAddress}';
645 650
646 VM() : super._empty(null) { 651 VM() : super._empty(null) {
647 name = 'vm'; 652 update(toObservable({'name':'vm', 'type':'@VM'}));
648 vmName = 'vm';
649 _cache['vm'] = this;
650 update(toObservable({'id':'vm', 'type':'@VM'}));
651 } 653 }
652 654
653 void postServiceEvent(String streamId, Map response, ByteData data) { 655 void postServiceEvent(String streamId, Map response, ByteData data) {
654 var map = toObservable(response); 656 var map = toObservable(response);
655 assert(!map.containsKey('_data')); 657 assert(!map.containsKey('_data'));
656 if (data != null) { 658 if (data != null) {
657 map['_data'] = data; 659 map['_data'] = data;
658 } 660 }
659 if (map['type'] != 'Event') { 661 if (map['type'] != 'Event') {
660 Logger.root.severe( 662 Logger.root.severe(
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 toRemove.forEach((id) => _isolateCache.remove(id)); 728 toRemove.forEach((id) => _isolateCache.remove(id));
727 _buildIsolateList(); 729 _buildIsolateList();
728 } 730 }
729 731
730 static final String _isolateIdPrefix = 'isolates/'; 732 static final String _isolateIdPrefix = 'isolates/';
731 733
732 ServiceObject getFromMap(ObservableMap map) { 734 ServiceObject getFromMap(ObservableMap map) {
733 if (map == null) { 735 if (map == null) {
734 return null; 736 return null;
735 } 737 }
738 var type = _stripRef(map['type']);
739 if (type == 'VM') {
740 // Update this VM object.
741 update(map);
742 return this;
743 }
744
745 assert(type == 'Isolate');
736 String id = map['id']; 746 String id = map['id'];
737 if (!id.startsWith(_isolateIdPrefix)) { 747 if (!id.startsWith(_isolateIdPrefix)) {
738 // Currently the VM only supports upgrading Isolate ServiceObjects. 748 // Currently the VM only supports upgrading Isolate ServiceObjects.
739 throw new UnimplementedError(); 749 throw new UnimplementedError();
740 } 750 }
741 751
742 // Check cache. 752 // Check cache.
743 var isolate = _isolateCache[id]; 753 var isolate = _isolateCache[id];
744 if (isolate == null) { 754 if (isolate == null) {
745 // Add new isolate to the cache. 755 // Add new isolate to the cache.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
809 } 819 }
810 820
811 Future restart() { 821 Future restart() {
812 return invokeRpc('_restartVM', {}); 822 return invokeRpc('_restartVM', {});
813 } 823 }
814 824
815 Future<ObservableMap> _fetchDirect() async { 825 Future<ObservableMap> _fetchDirect() async {
816 if (!loaded) { 826 if (!loaded) {
817 // The vm service relies on these events to keep the VM and 827 // The vm service relies on these events to keep the VM and
818 // Isolate types up to date. 828 // Isolate types up to date.
829 await listenEventStream(kVMStream, _dispatchEventToIsolate);
819 await listenEventStream(kIsolateStream, _dispatchEventToIsolate); 830 await listenEventStream(kIsolateStream, _dispatchEventToIsolate);
820 await listenEventStream(kDebugStream, _dispatchEventToIsolate); 831 await listenEventStream(kDebugStream, _dispatchEventToIsolate);
821 await listenEventStream(_kGraphStream, _dispatchEventToIsolate); 832 await listenEventStream(_kGraphStream, _dispatchEventToIsolate);
822 } 833 }
823 return await invokeRpcNoUpgrade('getVM', {}); 834 return await invokeRpcNoUpgrade('getVM', {});
824 } 835 }
825 836
837 Future setName(String newName) {
838 return invokeRpc('setVMName', { 'name': newName });
839 }
840
826 Future<ServiceObject> getFlagList() { 841 Future<ServiceObject> getFlagList() {
827 return invokeRpc('getFlagList', {}); 842 return invokeRpc('getFlagList', {});
828 } 843 }
829 844
830 Future<ServiceObject> _streamListen(String streamId) { 845 Future<ServiceObject> _streamListen(String streamId) {
831 Map params = { 846 Map params = {
832 'streamId': streamId, 847 'streamId': streamId,
833 }; 848 };
834 return invokeRpc('streamListen', params); 849 return invokeRpc('streamListen', params);
835 } 850 }
836 851
837 Future<ServiceObject> _streamCancel(String streamId) { 852 Future<ServiceObject> _streamCancel(String streamId) {
838 Map params = { 853 Map params = {
839 'streamId': streamId, 854 'streamId': streamId,
840 }; 855 };
841 return invokeRpc('streamCancel', params); 856 return invokeRpc('streamCancel', params);
842 } 857 }
843 858
844 // A map from stream id to event stream state. 859 // A map from stream id to event stream state.
845 Map<String,_EventStreamState> _eventStreams = {}; 860 Map<String,_EventStreamState> _eventStreams = {};
846 861
847 // Well-known stream ids. 862 // Well-known stream ids.
863 static const kVMStream = 'VM';
848 static const kIsolateStream = 'Isolate'; 864 static const kIsolateStream = 'Isolate';
849 static const kDebugStream = 'Debug'; 865 static const kDebugStream = 'Debug';
850 static const kGCStream = 'GC'; 866 static const kGCStream = 'GC';
851 static const kStdoutStream = 'Stdout'; 867 static const kStdoutStream = 'Stdout';
852 static const kStderrStream = 'Stderr'; 868 static const kStderrStream = 'Stderr';
853 static const _kGraphStream = '_Graph'; 869 static const _kGraphStream = '_Graph';
854 870
855 /// Returns a single-subscription Stream object for a VM event stream. 871 /// Returns a single-subscription Stream object for a VM event stream.
856 Future<Stream> getEventStream(String streamId) async { 872 Future<Stream> getEventStream(String streamId) async {
857 var eventStream = _eventStreams.putIfAbsent( 873 var eventStream = _eventStreams.putIfAbsent(
(...skipping 10 matching lines...) Expand all
868 } 884 }
869 885
870 /// Force the VM to disconnect. 886 /// Force the VM to disconnect.
871 void disconnect(); 887 void disconnect();
872 /// Completes when the VM first connects. 888 /// Completes when the VM first connects.
873 Future get onConnect; 889 Future get onConnect;
874 /// Completes when the VM disconnects or there was an error connecting. 890 /// Completes when the VM disconnects or there was an error connecting.
875 Future get onDisconnect; 891 Future get onDisconnect;
876 892
877 void _update(ObservableMap map, bool mapIsRef) { 893 void _update(ObservableMap map, bool mapIsRef) {
894 name = map['name'];
895 notifyPropertyChange(#nameAndAddress, 0, 1);
896 vmName = map.containsKey('_vmName') ? map['_vmName'] : name;
878 if (mapIsRef) { 897 if (mapIsRef) {
879 return; 898 return;
880 } 899 }
881 // Note that upgrading the collection creates any isolates in the 900 // Note that upgrading the collection creates any isolates in the
882 // isolate list which are new. 901 // isolate list which are new.
883 _upgradeCollection(map, vm); 902 _upgradeCollection(map, vm);
884 903
885 _loaded = true; 904 _loaded = true;
886 version = map['version']; 905 version = map['version'];
887 targetCPU = map['targetCPU']; 906 targetCPU = map['targetCPU'];
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
1104 } 1123 }
1105 1124
1106 /// State for a running isolate. 1125 /// State for a running isolate.
1107 class Isolate extends ServiceObjectOwner with Coverage { 1126 class Isolate extends ServiceObjectOwner with Coverage {
1108 static const kLoggingStream = '_Logging'; 1127 static const kLoggingStream = '_Logging';
1109 @reflectable VM get vm => owner; 1128 @reflectable VM get vm => owner;
1110 @reflectable Isolate get isolate => this; 1129 @reflectable Isolate get isolate => this;
1111 @observable int number; 1130 @observable int number;
1112 @observable int originNumber; 1131 @observable int originNumber;
1113 @observable DateTime startTime; 1132 @observable DateTime startTime;
1114 @observable Duration get upTime => 1133 @observable Duration get upTime {
1115 (new DateTime.now().difference(startTime)); 1134 if (startTime == null) {
1135 return null;
1136 }
1137 return (new DateTime.now().difference(startTime));
1138 }
1116 1139
1117 @observable ObservableMap counters = new ObservableMap(); 1140 @observable ObservableMap counters = new ObservableMap();
1118 1141
1119 void _updateRunState() { 1142 void _updateRunState() {
1120 topFrame = (pauseEvent != null ? pauseEvent.topFrame : null); 1143 topFrame = (pauseEvent != null ? pauseEvent.topFrame : null);
1121 paused = (pauseEvent != null && 1144 paused = (pauseEvent != null &&
1122 pauseEvent.kind != ServiceEvent.kResume); 1145 pauseEvent.kind != ServiceEvent.kResume);
1123 running = (!paused && topFrame != null); 1146 running = (!paused && topFrame != null);
1124 idle = (!paused && topFrame == null); 1147 idle = (!paused && topFrame == null);
1125 notifyPropertyChange(#topFrame, 0, 1); 1148 notifyPropertyChange(#topFrame, 0, 1);
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
1334 return _snapshotFetch.stream; 1357 return _snapshotFetch.stream;
1335 } 1358 }
1336 1359
1337 void updateHeapsFromMap(ObservableMap map) { 1360 void updateHeapsFromMap(ObservableMap map) {
1338 newSpace.update(map['new']); 1361 newSpace.update(map['new']);
1339 oldSpace.update(map['old']); 1362 oldSpace.update(map['old']);
1340 } 1363 }
1341 1364
1342 void _update(ObservableMap map, bool mapIsRef) { 1365 void _update(ObservableMap map, bool mapIsRef) {
1343 name = map['name']; 1366 name = map['name'];
1344 vmName = map['name']; 1367 vmName = map.containsKey('_vmName') ? map['_vmName'] : name;
Cutch 2015/10/08 20:05:27 Why are we looking for the _vmName in the Isolate'
turnidge 2015/10/08 22:15:26 Resolved offline. This is not "the name of the vm
1345 number = int.parse(map['number'], onError:(_) => null); 1368 number = int.parse(map['number'], onError:(_) => null);
1346 if (mapIsRef) { 1369 if (mapIsRef) {
1347 return; 1370 return;
1348 } 1371 }
1349 _loaded = true; 1372 _loaded = true;
1350 loading = false; 1373 loading = false;
1351 1374
1352 _upgradeCollection(map, isolate); 1375 _upgradeCollection(map, isolate);
1353 originNumber = int.parse(map['_originNumber'], onError:(_) => null); 1376 originNumber = int.parse(map['_originNumber'], onError:(_) => null);
1354 rootLibrary = map['rootLib']; 1377 rootLibrary = map['rootLib'];
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
1478 1501
1479 case ServiceEvent.kGraph: 1502 case ServiceEvent.kGraph:
1480 _loadHeapSnapshot(event); 1503 _loadHeapSnapshot(event);
1481 break; 1504 break;
1482 1505
1483 case ServiceEvent.kGC: 1506 case ServiceEvent.kGC:
1484 // Ignore GC events for now. 1507 // Ignore GC events for now.
1485 break; 1508 break;
1486 1509
1487 default: 1510 default:
1488 // Log unrecognized events. 1511 // Log unexpected events.
1489 Logger.root.severe('Unrecognized event: $event'); 1512 Logger.root.severe('Unexpected event: $event');
1490 break; 1513 break;
1491 } 1514 }
1492 } 1515 }
1493 1516
1494 Future<ServiceObject> addBreakpoint( 1517 Future<ServiceObject> addBreakpoint(
1495 Script script, int line, [int col]) async { 1518 Script script, int line, [int col]) async {
1496 // TODO(turnidge): Pass line as an int instead of a string. 1519 // TODO(turnidge): Pass line as an int instead of a string.
1497 try { 1520 try {
1498 Map params = { 1521 Map params = {
1499 'scriptId': script.id, 1522 'scriptId': script.id,
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
1829 if (level.value == value) { 1852 if (level.value == value) {
1830 return level; 1853 return level;
1831 } 1854 }
1832 } 1855 }
1833 return new Level('$value', value); 1856 return new Level('$value', value);
1834 } 1857 }
1835 1858
1836 /// A [ServiceEvent] is an asynchronous event notification from the vm. 1859 /// A [ServiceEvent] is an asynchronous event notification from the vm.
1837 class ServiceEvent extends ServiceObject { 1860 class ServiceEvent extends ServiceObject {
1838 /// The possible 'kind' values. 1861 /// The possible 'kind' values.
1862 static const kVMUpdate = 'VMUpdate';
1839 static const kIsolateStart = 'IsolateStart'; 1863 static const kIsolateStart = 'IsolateStart';
1840 static const kIsolateRunnable = 'IsolateRunnable'; 1864 static const kIsolateRunnable = 'IsolateRunnable';
1841 static const kIsolateExit = 'IsolateExit'; 1865 static const kIsolateExit = 'IsolateExit';
1842 static const kIsolateUpdate = 'IsolateUpdate'; 1866 static const kIsolateUpdate = 'IsolateUpdate';
1843 static const kPauseStart = 'PauseStart'; 1867 static const kPauseStart = 'PauseStart';
1844 static const kPauseExit = 'PauseExit'; 1868 static const kPauseExit = 'PauseExit';
1845 static const kPauseBreakpoint = 'PauseBreakpoint'; 1869 static const kPauseBreakpoint = 'PauseBreakpoint';
1846 static const kPauseInterrupted = 'PauseInterrupted'; 1870 static const kPauseInterrupted = 'PauseInterrupted';
1847 static const kPauseException = 'PauseException'; 1871 static const kPauseException = 'PauseException';
1848 static const kResume = 'Resume'; 1872 static const kResume = 'Resume';
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1946 } 1970 }
1947 if (map['logRecord'] != null) { 1971 if (map['logRecord'] != null) {
1948 logRecord = map['logRecord']; 1972 logRecord = map['logRecord'];
1949 logRecord['time'] = 1973 logRecord['time'] =
1950 new DateTime.fromMillisecondsSinceEpoch(logRecord['time']); 1974 new DateTime.fromMillisecondsSinceEpoch(logRecord['time']);
1951 logRecord['level'] = _findLogLevel(logRecord['level']); 1975 logRecord['level'] = _findLogLevel(logRecord['level']);
1952 } 1976 }
1953 } 1977 }
1954 1978
1955 String toString() { 1979 String toString() {
1980 var ownerName = owner.id != null ? owner.id.toString() : owner.name;
1956 if (data == null) { 1981 if (data == null) {
1957 return "ServiceEvent(owner='${owner.id}', kind='${kind}', " 1982 return "ServiceEvent(owner='${ownerName}', kind='${kind}', "
1958 "time=${timestamp})"; 1983 "time=${timestamp})";
1959 } else { 1984 } else {
1960 return "ServiceEvent(owner='${owner.id}', kind='${kind}', " 1985 return "ServiceEvent(owner='${ownerName}', kind='${kind}', "
1961 "data.lengthInBytes=${data.lengthInBytes}, time=${timestamp})"; 1986 "data.lengthInBytes=${data.lengthInBytes}, time=${timestamp})";
1962 } 1987 }
1963 } 1988 }
1964 } 1989 }
1965 1990
1966 class Breakpoint extends ServiceObject { 1991 class Breakpoint extends ServiceObject {
1967 Breakpoint._empty(ServiceObjectOwner owner) : super._empty(owner); 1992 Breakpoint._empty(ServiceObjectOwner owner) : super._empty(owner);
1968 1993
1969 // TODO(turnidge): Add state to track if a breakpoint has been 1994 // TODO(turnidge): Add state to track if a breakpoint has been
1970 // removed from the program. Remove from the cache when deleted. 1995 // removed from the program. Remove from the cache when deleted.
(...skipping 1970 matching lines...) Expand 10 before | Expand all | Expand 10 after
3941 var v = list[i]; 3966 var v = list[i];
3942 if ((v is ObservableMap) && _isServiceMap(v)) { 3967 if ((v is ObservableMap) && _isServiceMap(v)) {
3943 list[i] = owner.getFromMap(v); 3968 list[i] = owner.getFromMap(v);
3944 } else if (v is ObservableList) { 3969 } else if (v is ObservableList) {
3945 _upgradeObservableList(v, owner); 3970 _upgradeObservableList(v, owner);
3946 } else if (v is ObservableMap) { 3971 } else if (v is ObservableMap) {
3947 _upgradeObservableMap(v, owner); 3972 _upgradeObservableMap(v, owner);
3948 } 3973 }
3949 } 3974 }
3950 } 3975 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698