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

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

Issue 1152283005: Revert "Add the streamListen and streamCancel rpcs to the vm service." (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 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
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 /// An RpcException represents an exceptional event that happened 7 /// An RpcException represents an exceptional event that happened
8 /// while invoking an rpc. 8 /// while invoking an rpc.
9 abstract class RpcException implements Exception { 9 abstract class RpcException implements Exception {
10 RpcException(this.message); 10 RpcException(this.message);
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 @observable Duration get upTime => 425 @observable Duration get upTime =>
426 (new DateTime.now().difference(startTime)); 426 (new DateTime.now().difference(startTime));
427 427
428 VM() : super._empty(null) { 428 VM() : super._empty(null) {
429 name = 'vm'; 429 name = 'vm';
430 vmName = 'vm'; 430 vmName = 'vm';
431 _cache['vm'] = this; 431 _cache['vm'] = this;
432 update(toObservable({'id':'vm', 'type':'@VM'})); 432 update(toObservable({'id':'vm', 'type':'@VM'}));
433 } 433 }
434 434
435 Future streamListen(String streamId) { 435 final StreamController<ServiceEvent> events =
436 return invokeRpc('streamListen', {'streamId': streamId}); 436 new StreamController.broadcast();
437 }
438 437
439 Future streamCancel(String streamId) { 438 void postServiceEvent(Map response, ByteData data) {
440 return invokeRpc('streamCancel', {'streamId': streamId});
441 }
442
443 static const kIsolateEventStreamId = 'Isolate';
444 static const kDebugEventStreamId = 'Debug';
445 static const kGCEventStreamId = 'GC';
446
447 Map<String,StreamController> _streamControllers = {};
448
449 void _streamListenHandleError(String streamId) {
450 streamListen(streamId).catchError((e, st) {
451 _getEventStreamController(streamId).addError(e, st);
452 });
453 }
454
455 void _streamCancelHandleError(String streamId) {
456 // TODO(turnidge): Consider removing the controller from the map here.
457 streamCancel(streamId).catchError((e, st) {
458 _getEventStreamController(streamId).addError(e, st);
459 });
460 }
461
462 StreamController _getEventStreamController(String streamId) {
463 var controller = _streamControllers.putIfAbsent(
464 streamId, () {
465 return new StreamController.broadcast(
466 onListen: () => _streamListenHandleError(streamId),
467 onCancel: () => _streamCancelHandleError(streamId));
468 });
469 return controller;
470 }
471
472 Stream getEventStream(String streamId) {
473 return _getEventStreamController(streamId).stream;
474 }
475
476 Stream get isolateEvents => getEventStream(kIsolateEventStreamId);
477 Stream get debugEvents => getEventStream(kDebugEventStreamId);
478 Stream get gcEvents => getEventStream(kGCEventStreamId);
479
480 void postServiceEvent(String streamId, Map response, ByteData data) {
481 assert(streamId != null);
482 var map = toObservable(response); 439 var map = toObservable(response);
483 assert(!map.containsKey('_data')); 440 assert(!map.containsKey('_data'));
484 if (data != null) { 441 if (data != null) {
485 map['_data'] = data; 442 map['_data'] = data;
486 } 443 }
487 if (map['type'] != 'ServiceEvent') { 444 if (map['type'] != 'ServiceEvent') {
488 Logger.root.severe( 445 Logger.root.severe(
489 "Expected 'ServiceEvent' but found '${map['type']}'"); 446 "Expected 'ServiceEvent' but found '${map['type']}'");
490 return; 447 return;
491 } 448 }
492 449
493 var eventIsolate = map['isolate']; 450 var eventIsolate = map['isolate'];
494 var event;
495 if (eventIsolate == null) { 451 if (eventIsolate == null) {
496 event = new ServiceObject._fromMap(vm, map); 452 var event = new ServiceObject._fromMap(vm, map);
453 events.add(event);
497 } else { 454 } else {
498 // getFromMap creates the Isolate if it hasn't been seen already. 455 // getFromMap creates the Isolate if it hasn't been seen already.
499 var isolate = getFromMap(map['isolate']); 456 var isolate = getFromMap(map['isolate']);
500 event = new ServiceObject._fromMap(isolate, map); 457 var event = new ServiceObject._fromMap(isolate, map);
501 if (event.eventType == ServiceEvent.kIsolateExit) { 458 if (event.eventType == ServiceEvent.kIsolateExit) {
502 _removeIsolate(isolate.id); 459 _removeIsolate(isolate.id);
503 } 460 }
504 // Give the isolate a chance to process the event first before
505 // dispatching it to others.
506 isolate._onEvent(event); 461 isolate._onEvent(event);
462 events.add(event);
507 } 463 }
508 _getEventStreamController(streamId).add(event);
509 } 464 }
510 465
511 void _removeIsolate(String isolateId) { 466 void _removeIsolate(String isolateId) {
512 assert(_isolateCache.containsKey(isolateId)); 467 assert(_isolateCache.containsKey(isolateId));
513 _isolateCache.remove(isolateId); 468 _isolateCache.remove(isolateId);
514 notifyPropertyChange(#isolates, true, false); 469 notifyPropertyChange(#isolates, true, false);
515 } 470 }
516 471
517 void _removeDeadIsolates(List newIsolates) { 472 void _removeDeadIsolates(List newIsolates) {
518 // Build a set of new isolates. 473 // Build a set of new isolates.
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after
1055 latestSnapshot.graph.process(_snapshotFetch).then((graph) { 1010 latestSnapshot.graph.process(_snapshotFetch).then((graph) {
1056 _snapshotFetch.add(latestSnapshot); 1011 _snapshotFetch.add(latestSnapshot);
1057 _snapshotFetch.close(); 1012 _snapshotFetch.close();
1058 }); 1013 });
1059 } 1014 }
1060 } 1015 }
1061 1016
1062 Stream fetchHeapSnapshot() { 1017 Stream fetchHeapSnapshot() {
1063 if (_snapshotFetch == null || _snapshotFetch.isClosed) { 1018 if (_snapshotFetch == null || _snapshotFetch.isClosed) {
1064 _snapshotFetch = new StreamController(); 1019 _snapshotFetch = new StreamController();
1065 isolate.vm.streamListen('_Graph'); 1020 // isolate.vm.streamListen('_Graph');
1066 isolate.invokeRpcNoUpgrade('requestHeapSnapshot', {}); 1021 isolate.invokeRpcNoUpgrade('requestHeapSnapshot', {});
1067 } 1022 }
1068 return _snapshotFetch.stream; 1023 return _snapshotFetch.stream;
1069 } 1024 }
1070 1025
1071 void updateHeapsFromMap(ObservableMap map) { 1026 void updateHeapsFromMap(ObservableMap map) {
1072 newSpace.update(map['new']); 1027 newSpace.update(map['new']);
1073 oldSpace.update(map['old']); 1028 oldSpace.update(map['old']);
1074 } 1029 }
1075 1030
(...skipping 2123 matching lines...) Expand 10 before | Expand all | Expand 10 after
3199 var v = list[i]; 3154 var v = list[i];
3200 if ((v is ObservableMap) && _isServiceMap(v)) { 3155 if ((v is ObservableMap) && _isServiceMap(v)) {
3201 list[i] = owner.getFromMap(v); 3156 list[i] = owner.getFromMap(v);
3202 } else if (v is ObservableList) { 3157 } else if (v is ObservableList) {
3203 _upgradeObservableList(v, owner); 3158 _upgradeObservableList(v, owner);
3204 } else if (v is ObservableMap) { 3159 } else if (v is ObservableMap) {
3205 _upgradeObservableMap(v, owner); 3160 _upgradeObservableMap(v, owner);
3206 } 3161 }
3207 } 3162 }
3208 } 3163 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698