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

Side by Side Diff: runtime/observatory/lib/src/heap_snapshot/heap_snapshot.dart

Issue 3009743003: [observatory] Add an "ownership" analysis for the heap snapshot. (Closed)
Patch Set: . Created 3 years, 3 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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 heap_snapshot; 5 part of heap_snapshot;
6 6
7 class HeapSnapshot implements M.HeapSnapshot { 7 class HeapSnapshot implements M.HeapSnapshot {
8 ObjectGraph graph; 8 ObjectGraph graph;
9 DateTime timestamp; 9 DateTime timestamp;
10 int get objects => graph.vertexCount; 10 int get objects => graph.vertexCount;
11 int get references => graph.edgeCount; 11 int get references => graph.edgeCount;
12 int get size => graph.internalSize + graph.externalSize; 12 int get size => graph.internalSize + graph.externalSize;
13 HeapSnapshotDominatorNode dominatorTree; 13 HeapSnapshotDominatorNode dominatorTree;
14 HeapSnapshotMergedDominatorNode mergedDominatorTree; 14 HeapSnapshotMergedDominatorNode mergedDominatorTree;
15 List<MergedVertex> classReferences; 15 List<MergedVertex> classReferences;
16 List<OwnershipClass> ownershipClasses;
16 17
17 static Future sleep([Duration duration = const Duration(microseconds: 0)]) { 18 static Future sleep([Duration duration = const Duration(microseconds: 0)]) {
18 final Completer completer = new Completer(); 19 final Completer completer = new Completer();
19 new Timer(duration, () => completer.complete()); 20 new Timer(duration, () => completer.complete());
20 return completer.future; 21 return completer.future;
21 } 22 }
22 23
23 Stream<List> loadProgress(S.Isolate isolate, S.RawHeapSnapshot raw) { 24 Stream<List> loadProgress(S.Isolate isolate, S.RawHeapSnapshot raw) {
24 final progress = new StreamController<List>.broadcast(); 25 final progress = new StreamController<List>.broadcast();
25 progress.add(['', 0.0]); 26 progress.add(['', 0.0]);
26 graph = new ObjectGraph(raw.chunks, raw.count); 27 graph = new ObjectGraph(raw.chunks, raw.count);
27 var signal = (String description, double p) { 28 var signal = (String description, double p) {
28 progress.add([description, p]); 29 progress.add([description, p]);
29 return sleep(); 30 return sleep();
30 }; 31 };
31 (() async { 32 (() async {
32 timestamp = new DateTime.now(); 33 timestamp = new DateTime.now();
33 final stream = graph.process(); 34 final stream = graph.process();
34 stream.listen((status) { 35 stream.listen((status) {
35 status[1] /= 2.0; 36 status[1] /= 2.0;
36 progress.add(status); 37 progress.add(status);
37 }); 38 });
38 await stream.last; 39 await stream.last;
39 dominatorTree = new HeapSnapshotDominatorNode(isolate, graph.root); 40 dominatorTree = new HeapSnapshotDominatorNode(isolate, graph.root);
40 mergedDominatorTree = 41 mergedDominatorTree =
41 new HeapSnapshotMergedDominatorNode(isolate, graph.mergedRoot); 42 new HeapSnapshotMergedDominatorNode(isolate, graph.mergedRoot);
42 classReferences = await buildMergedVertices(isolate, graph, signal); 43 classReferences = await buildMergedVertices(isolate, graph, signal);
44 ownershipClasses = buildOwnershipClasses(isolate, graph);
43 progress.close(); 45 progress.close();
44 }()); 46 }());
45 return progress.stream; 47 return progress.stream;
46 } 48 }
47 49
48 Future<List<MergedVertex>> buildMergedVertices( 50 Future<List<MergedVertex>> buildMergedVertices(
49 S.Isolate isolate, ObjectGraph graph, signal) async { 51 S.Isolate isolate, ObjectGraph graph, signal) async {
50 final cidToMergedVertex = {}; 52 final cidToMergedVertex = {};
51 53
52 int count = 0; 54 int count = 0;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 target.incomingEdges.add(edge); 95 target.incomingEdges.add(edge);
94 } 96 }
95 edge.count++; 97 edge.count++;
96 // An over-estimate if there are multiple references to the same object. 98 // An over-estimate if there are multiple references to the same object.
97 edge.shallowSize += vertex2.shallowSize ?? 0; 99 edge.shallowSize += vertex2.shallowSize ?? 0;
98 } 100 }
99 } 101 }
100 return cidToMergedVertex.values.toList(); 102 return cidToMergedVertex.values.toList();
101 } 103 }
102 104
105 buildOwnershipClasses(S.Isolate isolate, ObjectGraph graph) {
106 var numCids = graph.numCids;
107 var classes = new List();
108 for (var cid = 0; cid < numCids; cid++) {
109 var size = graph.getOwnedByCid(cid);
110 if (size != 0) {
111 classes.add(new OwnershipClass(cid, isolate, size));
112 }
113 }
114 return classes;
115 }
116
103 List<Future<S.ServiceObject>> getMostRetained(S.Isolate isolate, 117 List<Future<S.ServiceObject>> getMostRetained(S.Isolate isolate,
104 {int classId, int limit}) { 118 {int classId, int limit}) {
105 var result = []; 119 var result = [];
106 for (ObjectVertex v 120 for (ObjectVertex v
107 in graph.getMostRetained(classId: classId, limit: limit)) { 121 in graph.getMostRetained(classId: classId, limit: limit)) {
108 result.add( 122 result.add(
109 isolate.getObjectByAddress(v.address).then((S.ServiceObject obj) { 123 isolate.getObjectByAddress(v.address).then((S.ServiceObject obj) {
110 if (obj is S.HeapObject) { 124 if (obj is S.HeapObject) {
111 obj.retainedSize = v.retainedSize; 125 obj.retainedSize = v.retainedSize;
112 } else { 126 } else {
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 final MergedEdge edge; 274 final MergedEdge edge;
261 S.Class get target => edge.sourceVertex != vertex 275 S.Class get target => edge.sourceVertex != vertex
262 ? edge.sourceVertex.clazz 276 ? edge.sourceVertex.clazz
263 : edge.targetVertex.clazz; 277 : edge.targetVertex.clazz;
264 int get count => edge.count; 278 int get count => edge.count;
265 int get shallowSize => edge.shallowSize; 279 int get shallowSize => edge.shallowSize;
266 int get retainedSize => edge.retainedSize; 280 int get retainedSize => edge.retainedSize;
267 281
268 HeapSnapshotClassOutbound(this.vertex, this.edge); 282 HeapSnapshotClassOutbound(this.vertex, this.edge);
269 } 283 }
284
285 class OwnershipClass {
cbernaschina 2017/08/29 21:07:00 ditto
rmacnak 2017/08/29 23:59:34 Done.
286 final int cid;
287 final S.Isolate isolate;
288 S.Class get clazz => isolate.getClassByCid(cid);
289 final int size;
290
291 OwnershipClass(this.cid, this.isolate, this.size);
292 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698