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

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

Issue 1275713002: Order the vm's isolate list by isolate start time. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 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
« no previous file with comments | « runtime/observatory/lib/src/elements/debugger.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 /// 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 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 @reflectable Isolate get isolate => null; 499 @reflectable Isolate get isolate => null;
500 500
501 // TODO(turnidge): The connection should not be stored in the VM object. 501 // TODO(turnidge): The connection should not be stored in the VM object.
502 bool get isDisconnected; 502 bool get isDisconnected;
503 503
504 // TODO(johnmccutchan): Ensure that isolates do not end up in _cache. 504 // TODO(johnmccutchan): Ensure that isolates do not end up in _cache.
505 Map<String,ServiceObject> _cache = new Map<String,ServiceObject>(); 505 Map<String,ServiceObject> _cache = new Map<String,ServiceObject>();
506 final ObservableMap<String,Isolate> _isolateCache = 506 final ObservableMap<String,Isolate> _isolateCache =
507 new ObservableMap<String,Isolate>(); 507 new ObservableMap<String,Isolate>();
508 508
509 @reflectable Iterable<Isolate> get isolates => _isolateCache.values; 509 // The list of live isolates, ordered by isolate start time.
510 final ObservableList<Isolate> isolates = new ObservableList<Isolate>();
510 511
511 @observable String version = 'unknown'; 512 @observable String version = 'unknown';
512 @observable String targetCPU; 513 @observable String targetCPU;
513 @observable int architectureBits; 514 @observable int architectureBits;
514 @observable bool assertsEnabled = false; 515 @observable bool assertsEnabled = false;
515 @observable bool typeChecksEnabled = false; 516 @observable bool typeChecksEnabled = false;
516 @observable String pid = ''; 517 @observable String pid = '';
517 @observable DateTime startTime; 518 @observable DateTime startTime;
518 @observable DateTime refreshTime; 519 @observable DateTime refreshTime;
519 @observable Duration get upTime => 520 @observable Duration get upTime =>
(...skipping 20 matching lines...) Expand all
540 541
541 var eventIsolate = map['isolate']; 542 var eventIsolate = map['isolate'];
542 var event; 543 var event;
543 if (eventIsolate == null) { 544 if (eventIsolate == null) {
544 event = new ServiceObject._fromMap(vm, map); 545 event = new ServiceObject._fromMap(vm, map);
545 } else { 546 } else {
546 // getFromMap creates the Isolate if it hasn't been seen already. 547 // getFromMap creates the Isolate if it hasn't been seen already.
547 var isolate = getFromMap(map['isolate']); 548 var isolate = getFromMap(map['isolate']);
548 event = new ServiceObject._fromMap(isolate, map); 549 event = new ServiceObject._fromMap(isolate, map);
549 if (event.kind == ServiceEvent.kIsolateExit) { 550 if (event.kind == ServiceEvent.kIsolateExit) {
550 _removeIsolate(isolate.id); 551 _isolateCache.remove(isolate.id);
552 _buildIsolateList();
551 } 553 }
552 } 554 }
553 var eventStream = _eventStreams[streamId]; 555 var eventStream = _eventStreams[streamId];
554 if (eventStream != null) { 556 if (eventStream != null) {
555 eventStream.addEvent(event); 557 eventStream.addEvent(event);
556 } else { 558 } else {
557 Logger.root.warning("Ignoring unexpected event on stream '${streamId}'"); 559 Logger.root.warning("Ignoring unexpected event on stream '${streamId}'");
558 } 560 }
559 } 561 }
560 562
561 void _removeIsolate(String isolateId) { 563 int _compareIsolates(Isolate a, Isolate b) {
562 assert(_isolateCache.containsKey(isolateId)); 564 var aStart = a.startTime;
563 _isolateCache.remove(isolateId); 565 var bStart = b.startTime;
564 notifyPropertyChange(#isolates, true, false); 566 if (aStart == null) {
567 if (bStart == null) {
568 return 0;
569 } else {
570 return 1;
571 }
572 }
573 if (bStart == null) {
574 return -1;
575 }
576 return aStart.compareTo(bStart);
577 }
578
579 void _buildIsolateList() {
580 var isolateList = _isolateCache.values.toList();
581 print("IL $isolateList");
Cutch 2015/08/05 21:41:56 Remove print
582 isolateList.sort(_compareIsolates);
583 isolates.clear();
584 isolates.addAll(isolateList);
565 } 585 }
566 586
567 void _removeDeadIsolates(List newIsolates) { 587 void _removeDeadIsolates(List newIsolates) {
568 // Build a set of new isolates. 588 // Build a set of new isolates.
569 var newIsolateSet = new Set(); 589 var newIsolateSet = new Set();
570 newIsolates.forEach((iso) => newIsolateSet.add(iso.id)); 590 newIsolates.forEach((iso) => newIsolateSet.add(iso.id));
571 591
572 // Remove any old isolates which no longer exist. 592 // Remove any old isolates which no longer exist.
573 List toRemove = []; 593 List toRemove = [];
574 _isolateCache.forEach((id, _) { 594 _isolateCache.forEach((id, _) {
575 if (!newIsolateSet.contains(id)) { 595 if (!newIsolateSet.contains(id)) {
576 toRemove.add(id); 596 toRemove.add(id);
577 } 597 }
578 }); 598 });
579 toRemove.forEach((id) => _removeIsolate(id)); 599 toRemove.forEach((id) => _isolateCache.remove(id));
580 notifyPropertyChange(#isolates, true, false); 600 _buildIsolateList();
581 } 601 }
582 602
583 static final String _isolateIdPrefix = 'isolates/'; 603 static final String _isolateIdPrefix = 'isolates/';
584 604
585 ServiceObject getFromMap(ObservableMap map) { 605 ServiceObject getFromMap(ObservableMap map) {
586 if (map == null) { 606 if (map == null) {
587 return null; 607 return null;
588 } 608 }
589 String id = map['id']; 609 String id = map['id'];
590 if (!id.startsWith(_isolateIdPrefix)) { 610 if (!id.startsWith(_isolateIdPrefix)) {
591 // Currently the VM only supports upgrading Isolate ServiceObjects. 611 // Currently the VM only supports upgrading Isolate ServiceObjects.
592 throw new UnimplementedError(); 612 throw new UnimplementedError();
593 } 613 }
594 614
595 // Check cache. 615 // Check cache.
596 var isolate = _isolateCache[id]; 616 var isolate = _isolateCache[id];
597 if (isolate == null) { 617 if (isolate == null) {
598 // Add new isolate to the cache. 618 // Add new isolate to the cache.
599 isolate = new ServiceObject._fromMap(this, map); 619 isolate = new ServiceObject._fromMap(this, map);
600 _isolateCache[id] = isolate; 620 _isolateCache[id] = isolate;
601 notifyPropertyChange(#isolates, true, false); 621 _buildIsolateList();
602 622
603 // Eagerly load the isolate. 623 // Eagerly load the isolate.
604 isolate.load().catchError((e, stack) { 624 isolate.load().catchError((e, stack) {
605 Logger.root.info('Eagerly loading an isolate failed: $e\n$stack'); 625 Logger.root.info('Eagerly loading an isolate failed: $e\n$stack');
606 }); 626 });
607 } else { 627 } else {
608 isolate.update(map); 628 isolate.update(map);
609 } 629 }
610 return isolate; 630 return isolate;
611 } 631 }
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
1194 return; 1214 return;
1195 } 1215 }
1196 _loaded = true; 1216 _loaded = true;
1197 loading = false; 1217 loading = false;
1198 1218
1199 _upgradeCollection(map, isolate); 1219 _upgradeCollection(map, isolate);
1200 rootLibrary = map['rootLib']; 1220 rootLibrary = map['rootLib'];
1201 if (map['entry'] != null) { 1221 if (map['entry'] != null) {
1202 entry = map['entry']; 1222 entry = map['entry'];
1203 } 1223 }
1224 var savedStartTime = startTime;
1204 var startTimeInMillis = map['startTime']; 1225 var startTimeInMillis = map['startTime'];
1205 startTime = new DateTime.fromMillisecondsSinceEpoch(startTimeInMillis); 1226 startTime = new DateTime.fromMillisecondsSinceEpoch(startTimeInMillis);
1206 notifyPropertyChange(#upTime, 0, 1); 1227 notifyPropertyChange(#upTime, 0, 1);
1207 var countersMap = map['_tagCounters']; 1228 var countersMap = map['_tagCounters'];
1208 if (countersMap != null) { 1229 if (countersMap != null) {
1209 var names = countersMap['names']; 1230 var names = countersMap['names'];
1210 var counts = countersMap['counters']; 1231 var counts = countersMap['counters'];
1211 assert(names.length == counts.length); 1232 assert(names.length == counts.length);
1212 var sum = 0; 1233 var sum = 0;
1213 for (var i = 0; i < counts.length; i++) { 1234 for (var i = 0; i < counts.length; i++) {
(...skipping 29 matching lines...) Expand all
1243 _updateBreakpoints(map['breakpoints']); 1264 _updateBreakpoints(map['breakpoints']);
1244 exceptionsPauseInfo = map['_debuggerSettings']['_exceptions']; 1265 exceptionsPauseInfo = map['_debuggerSettings']['_exceptions'];
1245 1266
1246 pauseEvent = map['pauseEvent']; 1267 pauseEvent = map['pauseEvent'];
1247 _updateRunState(); 1268 _updateRunState();
1248 error = map['error']; 1269 error = map['error'];
1249 1270
1250 libraries.clear(); 1271 libraries.clear();
1251 libraries.addAll(map['libraries']); 1272 libraries.addAll(map['libraries']);
1252 libraries.sort(ServiceObject.LexicalSortName); 1273 libraries.sort(ServiceObject.LexicalSortName);
1274 if (savedStartTime == null) {
1275 vm._buildIsolateList();
1276 }
1253 } 1277 }
1254 1278
1255 Future<TagProfile> updateTagProfile() { 1279 Future<TagProfile> updateTagProfile() {
1256 return isolate.invokeRpcNoUpgrade('_getTagProfile', {}).then( 1280 return isolate.invokeRpcNoUpgrade('_getTagProfile', {}).then(
1257 (ObservableMap map) { 1281 (ObservableMap map) {
1258 var seconds = new DateTime.now().millisecondsSinceEpoch / 1000.0; 1282 var seconds = new DateTime.now().millisecondsSinceEpoch / 1000.0;
1259 tagProfile._processTagProfile(seconds, map); 1283 tagProfile._processTagProfile(seconds, map);
1260 return tagProfile; 1284 return tagProfile;
1261 }); 1285 });
1262 } 1286 }
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
1561 } 1585 }
1562 1586
1563 Future<ObservableMap<String, ServiceMetric>> refreshNativeMetrics() { 1587 Future<ObservableMap<String, ServiceMetric>> refreshNativeMetrics() {
1564 return _refreshMetrics('Native', nativeMetrics); 1588 return _refreshMetrics('Native', nativeMetrics);
1565 } 1589 }
1566 1590
1567 Future refreshMetrics() { 1591 Future refreshMetrics() {
1568 return Future.wait([refreshDartMetrics(), refreshNativeMetrics()]); 1592 return Future.wait([refreshDartMetrics(), refreshNativeMetrics()]);
1569 } 1593 }
1570 1594
1571 String toString() => "Isolate($_id)"; 1595 String toString() => "Isolate($name)";
1572 } 1596 }
1573 1597
1574 /// A [ServiceObject] which implements [ObservableMap]. 1598 /// A [ServiceObject] which implements [ObservableMap].
1575 class ServiceMap extends ServiceObject implements ObservableMap { 1599 class ServiceMap extends ServiceObject implements ObservableMap {
1576 final ObservableMap _map = new ObservableMap(); 1600 final ObservableMap _map = new ObservableMap();
1577 static String objectIdRingPrefix = 'objects/'; 1601 static String objectIdRingPrefix = 'objects/';
1578 1602
1579 bool get canCache { 1603 bool get canCache {
1580 return (_type == 'Class' || 1604 return (_type == 'Class' ||
1581 _type == 'Function' || 1605 _type == 'Function' ||
(...skipping 2080 matching lines...) Expand 10 before | Expand all | Expand 10 after
3662 var v = list[i]; 3686 var v = list[i];
3663 if ((v is ObservableMap) && _isServiceMap(v)) { 3687 if ((v is ObservableMap) && _isServiceMap(v)) {
3664 list[i] = owner.getFromMap(v); 3688 list[i] = owner.getFromMap(v);
3665 } else if (v is ObservableList) { 3689 } else if (v is ObservableList) {
3666 _upgradeObservableList(v, owner); 3690 _upgradeObservableList(v, owner);
3667 } else if (v is ObservableMap) { 3691 } else if (v is ObservableMap) {
3668 _upgradeObservableMap(v, owner); 3692 _upgradeObservableMap(v, owner);
3669 } 3693 }
3670 } 3694 }
3671 } 3695 }
OLDNEW
« no previous file with comments | « runtime/observatory/lib/src/elements/debugger.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698