OLD | NEW |
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 // Some value smaller than the object ring, so requesting a large array | 7 // Some value smaller than the object ring, so requesting a large array |
8 // doesn't result in an expired ref because the elements lapped it in the | 8 // doesn't result in an expired ref because the elements lapped it in the |
9 // object ring. | 9 // object ring. |
10 const int kDefaultFieldLimit = 100; | 10 const int kDefaultFieldLimit = 100; |
(...skipping 1154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1165 void update(Map heapMap) { | 1165 void update(Map heapMap) { |
1166 used = heapMap['used']; | 1166 used = heapMap['used']; |
1167 capacity = heapMap['capacity']; | 1167 capacity = heapMap['capacity']; |
1168 external = heapMap['external']; | 1168 external = heapMap['external']; |
1169 collections = heapMap['collections']; | 1169 collections = heapMap['collections']; |
1170 totalCollectionTimeInSeconds = heapMap['time']; | 1170 totalCollectionTimeInSeconds = heapMap['time']; |
1171 averageCollectionPeriodInMillis = heapMap['avgCollectionPeriodMillis']; | 1171 averageCollectionPeriodInMillis = heapMap['avgCollectionPeriodMillis']; |
1172 } | 1172 } |
1173 } | 1173 } |
1174 | 1174 |
1175 class HeapSnapshot { | 1175 class RawHeapSnapshot { |
1176 final ObjectGraph graph; | 1176 final chunks; |
1177 final DateTime timeStamp; | 1177 final count; |
1178 final Isolate isolate; | 1178 RawHeapSnapshot(this.chunks, this.count); |
1179 | |
1180 HeapSnapshot(this.isolate, chunks, nodeCount) : | |
1181 graph = new ObjectGraph(chunks, nodeCount), | |
1182 timeStamp = new DateTime.now(); | |
1183 | |
1184 List<Future<ServiceObject>> getMostRetained({int classId, int limit}) { | |
1185 var result = []; | |
1186 for (ObjectVertex v in graph.getMostRetained(classId: classId, | |
1187 limit: limit)) { | |
1188 result.add(isolate.getObjectByAddress(v.address) | |
1189 .then((ServiceObject obj) { | |
1190 if (obj is HeapObject) { | |
1191 obj.retainedSize = v.retainedSize; | |
1192 } else { | |
1193 print("${obj.runtimeType} should be a HeapObject"); | |
1194 } | |
1195 return obj; | |
1196 })); | |
1197 } | |
1198 return result; | |
1199 } | |
1200 } | 1179 } |
1201 | 1180 |
1202 /// State for a running isolate. | 1181 /// State for a running isolate. |
1203 class Isolate extends ServiceObjectOwner implements M.Isolate { | 1182 class Isolate extends ServiceObjectOwner implements M.Isolate { |
1204 static const kLoggingStream = '_Logging'; | 1183 static const kLoggingStream = '_Logging'; |
1205 static const kExtensionStream = 'Extension'; | 1184 static const kExtensionStream = 'Extension'; |
1206 | 1185 |
1207 @reflectable VM get vm => owner; | 1186 @reflectable VM get vm => owner; |
1208 @reflectable Isolate get isolate => this; | 1187 @reflectable Isolate get isolate => this; |
1209 @observable int number; | 1188 @observable int number; |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1428 @observable String name; | 1407 @observable String name; |
1429 @observable String vmName; | 1408 @observable String vmName; |
1430 @observable ServiceFunction entry; | 1409 @observable ServiceFunction entry; |
1431 | 1410 |
1432 final HeapSpace newSpace = new HeapSpace(); | 1411 final HeapSpace newSpace = new HeapSpace(); |
1433 final HeapSpace oldSpace = new HeapSpace(); | 1412 final HeapSpace oldSpace = new HeapSpace(); |
1434 | 1413 |
1435 @observable String fileAndLine; | 1414 @observable String fileAndLine; |
1436 | 1415 |
1437 @observable DartError error; | 1416 @observable DartError error; |
1438 @observable HeapSnapshot latestSnapshot; | |
1439 StreamController _snapshotFetch; | 1417 StreamController _snapshotFetch; |
1440 | 1418 |
1441 List<ByteData> _chunksInProgress; | 1419 List<ByteData> _chunksInProgress; |
1442 | 1420 |
1443 void _loadHeapSnapshot(ServiceEvent event) { | 1421 void _loadHeapSnapshot(ServiceEvent event) { |
1444 if (_snapshotFetch == null || _snapshotFetch.isClosed) { | 1422 if (_snapshotFetch == null || _snapshotFetch.isClosed) { |
1445 // No outstanding snapshot request. Presumably another client asked for a | 1423 // No outstanding snapshot request. Presumably another client asked for a |
1446 // snapshot. | 1424 // snapshot. |
1447 Logger.root.info("Dropping unsolicited heap snapshot chunk"); | 1425 Logger.root.info("Dropping unsolicited heap snapshot chunk"); |
1448 return; | 1426 return; |
1449 } | 1427 } |
1450 | 1428 |
1451 // Occasionally these actually arrive out of order. | 1429 // Occasionally these actually arrive out of order. |
1452 var chunkIndex = event.chunkIndex; | 1430 var chunkIndex = event.chunkIndex; |
1453 var chunkCount = event.chunkCount; | 1431 var chunkCount = event.chunkCount; |
1454 if (_chunksInProgress == null) { | 1432 if (_chunksInProgress == null) { |
1455 _chunksInProgress = new List(chunkCount); | 1433 _chunksInProgress = new List(chunkCount); |
1456 } | 1434 } |
1457 _chunksInProgress[chunkIndex] = event.data; | 1435 _chunksInProgress[chunkIndex] = event.data; |
1458 _snapshotFetch.add("Receiving snapshot chunk ${chunkIndex + 1}" | 1436 _snapshotFetch.add([chunkIndex, chunkCount]); |
1459 " of $chunkCount..."); | |
1460 | 1437 |
1461 for (var i = 0; i < chunkCount; i++) { | 1438 for (var i = 0; i < chunkCount; i++) { |
1462 if (_chunksInProgress[i] == null) return; | 1439 if (_chunksInProgress[i] == null) return; |
1463 } | 1440 } |
1464 | 1441 |
1465 var loadedChunks = _chunksInProgress; | 1442 var loadedChunks = _chunksInProgress; |
1466 _chunksInProgress = null; | 1443 _chunksInProgress = null; |
1467 | 1444 |
1468 latestSnapshot = new HeapSnapshot(this, loadedChunks, event.nodeCount); | |
1469 if (_snapshotFetch != null) { | 1445 if (_snapshotFetch != null) { |
1470 latestSnapshot.graph.process(_snapshotFetch).then((graph) { | 1446 _snapshotFetch.add( |
1471 _snapshotFetch.add(latestSnapshot); | 1447 new RawHeapSnapshot(loadedChunks, event.nodeCount)); |
1472 _snapshotFetch.close(); | 1448 _snapshotFetch.close(); |
1473 }); | |
1474 } | 1449 } |
1475 } | 1450 } |
1476 | 1451 |
1477 Stream fetchHeapSnapshot(collectGarbage) { | 1452 Stream fetchHeapSnapshot(collectGarbage) { |
1478 if (_snapshotFetch == null || _snapshotFetch.isClosed) { | 1453 if (_snapshotFetch == null || _snapshotFetch.isClosed) { |
1479 _snapshotFetch = new StreamController(); | 1454 _snapshotFetch = new StreamController.broadcast(); |
1480 // isolate.vm.streamListen('_Graph'); | 1455 // isolate.vm.streamListen('_Graph'); |
1481 isolate.invokeRpcNoUpgrade('_requestHeapSnapshot', | 1456 isolate.invokeRpcNoUpgrade('_requestHeapSnapshot', |
1482 {'collectGarbage': collectGarbage}); | 1457 {'collectGarbage': collectGarbage}); |
1483 } | 1458 } |
1484 return _snapshotFetch.stream; | 1459 return _snapshotFetch.stream; |
1485 } | 1460 } |
1486 | 1461 |
1487 void updateHeapsFromMap(ObservableMap map) { | 1462 void updateHeapsFromMap(ObservableMap map) { |
1488 newSpace.update(map['new']); | 1463 newSpace.update(map['new']); |
1489 oldSpace.update(map['old']); | 1464 oldSpace.update(map['old']); |
(...skipping 2822 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4312 var v = list[i]; | 4287 var v = list[i]; |
4313 if ((v is ObservableMap) && _isServiceMap(v)) { | 4288 if ((v is ObservableMap) && _isServiceMap(v)) { |
4314 list[i] = owner.getFromMap(v); | 4289 list[i] = owner.getFromMap(v); |
4315 } else if (v is ObservableList) { | 4290 } else if (v is ObservableList) { |
4316 _upgradeObservableList(v, owner); | 4291 _upgradeObservableList(v, owner); |
4317 } else if (v is ObservableMap) { | 4292 } else if (v is ObservableMap) { |
4318 _upgradeObservableMap(v, owner); | 4293 _upgradeObservableMap(v, owner); |
4319 } | 4294 } |
4320 } | 4295 } |
4321 } | 4296 } |
OLD | NEW |