OLD | NEW |
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.size; | 12 int get size => graph.size; |
13 HeapSnapshotDominatorNode dominatorTree; | 13 HeapSnapshotDominatorNode dominatorTree; |
| 14 HeapSnapshotMergedDominatorNode mergedDominatorTree; |
14 List<MergedVertex> classReferences; | 15 List<MergedVertex> classReferences; |
15 | 16 |
16 static Future sleep([Duration duration = const Duration(microseconds: 0)]) { | 17 static Future sleep([Duration duration = const Duration(microseconds: 0)]) { |
17 final Completer completer = new Completer(); | 18 final Completer completer = new Completer(); |
18 new Timer(duration, () => completer.complete()); | 19 new Timer(duration, () => completer.complete()); |
19 return completer.future; | 20 return completer.future; |
20 } | 21 } |
21 | 22 |
22 Stream<List> loadProgress(S.Isolate isolate, S.RawHeapSnapshot raw) { | 23 Stream<List> loadProgress(S.Isolate isolate, S.RawHeapSnapshot raw) { |
23 final progress = new StreamController<List>.broadcast(); | 24 final progress = new StreamController<List>.broadcast(); |
24 progress.add(['', 0.0]); | 25 progress.add(['', 0.0]); |
25 graph = new ObjectGraph(raw.chunks, raw.count); | 26 graph = new ObjectGraph(raw.chunks, raw.count); |
26 var signal = (String description, double p) { | 27 var signal = (String description, double p) { |
27 progress.add([description, p]); | 28 progress.add([description, p]); |
28 return sleep(); | 29 return sleep(); |
29 }; | 30 }; |
30 (() async { | 31 (() async { |
31 timestamp = new DateTime.now(); | 32 timestamp = new DateTime.now(); |
32 final stream = graph.process(); | 33 final stream = graph.process(); |
33 stream.listen((status) { | 34 stream.listen((status) { |
34 status[1] /= 2.0; | 35 status[1] /= 2.0; |
35 progress.add(status); | 36 progress.add(status); |
36 }); | 37 }); |
37 await stream.last; | 38 await stream.last; |
38 dominatorTree = new HeapSnapshotDominatorNode(isolate, graph.root); | 39 dominatorTree = new HeapSnapshotDominatorNode(isolate, graph.root); |
| 40 mergedDominatorTree = |
| 41 new HeapSnapshotMergedDominatorNode(isolate, graph.mergedRoot); |
39 classReferences = await buildMergedVertices(isolate, graph, signal); | 42 classReferences = await buildMergedVertices(isolate, graph, signal); |
40 progress.close(); | 43 progress.close(); |
41 }()); | 44 }()); |
42 return progress.stream; | 45 return progress.stream; |
43 } | 46 } |
44 | 47 |
45 Future<List<MergedVertex>> buildMergedVertices( | 48 Future<List<MergedVertex>> buildMergedVertices( |
46 S.Isolate isolate, ObjectGraph graph, signal) async { | 49 S.Isolate isolate, ObjectGraph graph, signal) async { |
47 final cidToMergedVertex = {}; | 50 final cidToMergedVertex = {}; |
48 | 51 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 } | 147 } |
145 | 148 |
146 int get retainedSize => v.retainedSize; | 149 int get retainedSize => v.retainedSize; |
147 int get shallowSize => v.shallowSize; | 150 int get shallowSize => v.shallowSize; |
148 | 151 |
149 HeapSnapshotDominatorNode(S.Isolate isolate, ObjectVertex vertex) | 152 HeapSnapshotDominatorNode(S.Isolate isolate, ObjectVertex vertex) |
150 : isolate = isolate, | 153 : isolate = isolate, |
151 v = vertex; | 154 v = vertex; |
152 } | 155 } |
153 | 156 |
| 157 class HeapSnapshotMergedDominatorNode |
| 158 implements M.HeapSnapshotMergedDominatorNode { |
| 159 final MergedObjectVertex v; |
| 160 final S.Isolate isolate; |
| 161 |
| 162 Future<S.HeapObject> get klass { |
| 163 return new Future.value(isolate.getClassByCid(v.vmCid)); |
| 164 } |
| 165 |
| 166 Iterable<HeapSnapshotMergedDominatorNode> _children; |
| 167 Iterable<HeapSnapshotMergedDominatorNode> get children { |
| 168 if (_children != null) { |
| 169 return _children; |
| 170 } else { |
| 171 return _children = |
| 172 new List.unmodifiable(v.dominatorTreeChildren().map((v) { |
| 173 return new HeapSnapshotMergedDominatorNode(isolate, v); |
| 174 })); |
| 175 } |
| 176 } |
| 177 |
| 178 int get instanceCount => v.instanceCount; |
| 179 int get retainedSize => v.retainedSize; |
| 180 int get shallowSize => v.shallowSize; |
| 181 |
| 182 HeapSnapshotMergedDominatorNode(S.Isolate isolate, MergedObjectVertex vertex) |
| 183 : isolate = isolate, |
| 184 v = vertex; |
| 185 } |
| 186 |
154 class MergedEdge { | 187 class MergedEdge { |
155 final MergedVertex sourceVertex; | 188 final MergedVertex sourceVertex; |
156 final MergedVertex targetVertex; | 189 final MergedVertex targetVertex; |
157 int count = 0; | 190 int count = 0; |
158 int shallowSize = 0; | 191 int shallowSize = 0; |
159 int retainedSize = 0; | 192 int retainedSize = 0; |
160 | 193 |
161 MergedEdge(this.sourceVertex, this.targetVertex); | 194 MergedEdge(this.sourceVertex, this.targetVertex); |
162 } | 195 } |
163 | 196 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 final MergedEdge edge; | 254 final MergedEdge edge; |
222 S.Class get target => edge.sourceVertex != vertex | 255 S.Class get target => edge.sourceVertex != vertex |
223 ? edge.sourceVertex.clazz | 256 ? edge.sourceVertex.clazz |
224 : edge.targetVertex.clazz; | 257 : edge.targetVertex.clazz; |
225 int get count => edge.count; | 258 int get count => edge.count; |
226 int get shallowSize => edge.shallowSize; | 259 int get shallowSize => edge.shallowSize; |
227 int get retainedSize => edge.retainedSize; | 260 int get retainedSize => edge.retainedSize; |
228 | 261 |
229 HeapSnapshotClassOutbound(this.vertex, this.edge); | 262 HeapSnapshotClassOutbound(this.vertex, this.edge); |
230 } | 263 } |
OLD | NEW |