Chromium Code Reviews| 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 library object_graph; | 5 library object_graph; |
| 6 | 6 |
| 7 import 'dart:typed_data'; | 7 import 'dart:typed_data'; |
| 8 | 8 |
| 9 import 'dominator_tree.dart'; | 9 import 'dominator_tree.dart'; |
| 10 | 10 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 } | 31 } |
| 32 | 32 |
| 33 static const int dataBitsPerByte = 7; | 33 static const int dataBitsPerByte = 7; |
| 34 static const int byteMask = (1 << dataBitsPerByte) - 1; | 34 static const int byteMask = (1 << dataBitsPerByte) - 1; |
| 35 static const int maxUnsignedDataPerByte = byteMask; | 35 static const int maxUnsignedDataPerByte = byteMask; |
| 36 } | 36 } |
| 37 | 37 |
| 38 class ObjectVertex { | 38 class ObjectVertex { |
| 39 // Never null. The isolate root has id 0. | 39 // Never null. The isolate root has id 0. |
| 40 final int _id; | 40 final int _id; |
| 41 // TODO(koda): Include units in object graph metadata. | |
| 42 int addressForWordSize(int bytesPerWord) => _id * 2 * bytesPerWord; | |
| 41 // null for VM-heap objects. | 43 // null for VM-heap objects. |
| 42 int _shallowSize; | 44 int _shallowSize; |
| 43 int get shallowSize => _shallowSize; | 45 int get shallowSize => _shallowSize; |
| 44 int _retainedSize; | 46 int _retainedSize; |
| 45 int get retainedSize => _retainedSize; | 47 int get retainedSize => _retainedSize; |
| 46 // null for VM-heap objects. | 48 // null for VM-heap objects. |
| 47 int _classId; | 49 int _classId; |
| 48 int get classId => _classId; | 50 int get classId => _classId; |
| 49 final List<ObjectVertex> succ = new List<ObjectVertex>(); | 51 final List<ObjectVertex> succ = new List<ObjectVertex>(); |
| 50 ObjectVertex(this._id) : _retainedSize = 0; | 52 ObjectVertex(this._id) : _retainedSize = 0; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 68 obj.succ.add(_asVertex(last)); | 70 obj.succ.add(_asVertex(last)); |
| 69 last = stream.readUnsigned(); | 71 last = stream.readUnsigned(); |
| 70 } | 72 } |
| 71 } | 73 } |
| 72 | 74 |
| 73 ObjectGraph(ReadStream reader) { | 75 ObjectGraph(ReadStream reader) { |
| 74 while (reader.pendingBytes > 0) { | 76 while (reader.pendingBytes > 0) { |
| 75 _addFrom(reader); | 77 _addFrom(reader); |
| 76 } | 78 } |
| 77 _computeRetainedSizes(); | 79 _computeRetainedSizes(); |
| 80 _mostRetained = new List<ObjectVertex>.from( | |
| 81 vertices.where((u) => u.classId != 0)); | |
|
Cutch
2015/01/07 00:25:26
Perhaps make this magic number into a const and do
koda
2015/01/09 18:46:55
Added 'isRoot' getter.
| |
| 82 _mostRetained.sort((u, v) => v.retainedSize - u.retainedSize); | |
| 78 } | 83 } |
| 79 | 84 |
| 80 Iterable<ObjectVertex> get vertices => _idToVertex.values; | 85 Iterable<ObjectVertex> get vertices => _idToVertex.values; |
| 86 List<ObjectVertex> _mostRetained; | |
| 81 | 87 |
| 82 ObjectVertex get root => _asVertex(0); | 88 ObjectVertex get root => _asVertex(0); |
| 83 | 89 |
| 90 Iterable<ObjectVertex> getMostRetained({int classId, int limit}) { | |
| 91 var result = _mostRetained; | |
| 92 if (classId != null) { | |
| 93 result = result.where((u) => u.classId == classId); | |
| 94 } | |
| 95 if (limit != null) { | |
| 96 result = result.take(limit); | |
| 97 } | |
| 98 return result; | |
| 99 } | |
| 100 | |
| 84 void _computeRetainedSizes() { | 101 void _computeRetainedSizes() { |
| 85 // The retained size for an object is the sum of the shallow sizes of | 102 // The retained size for an object is the sum of the shallow sizes of |
| 86 // all its descendants in the dominator tree (including itself). | 103 // all its descendants in the dominator tree (including itself). |
| 87 var d = new Dominator(); | 104 var d = new Dominator(); |
| 88 for (ObjectVertex u in vertices) { | 105 for (ObjectVertex u in vertices) { |
| 89 if (u.shallowSize != null) { | 106 if (u.shallowSize != null) { |
| 90 u._retainedSize = u.shallowSize; | 107 u._retainedSize = u.shallowSize; |
| 91 d.addEdges(u, u.succ.where((ObjectVertex v) => v.shallowSize != null)); | 108 d.addEdges(u, u.succ.where((ObjectVertex v) => v.shallowSize != null)); |
| 92 } | 109 } |
| 93 } | 110 } |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 111 var v = leaves.removeLast(); | 128 var v = leaves.removeLast(); |
| 112 var u = d.dominator(v); | 129 var u = d.dominator(v); |
| 113 if (u == null) continue; | 130 if (u == null) continue; |
| 114 u._retainedSize += v._retainedSize; | 131 u._retainedSize += v._retainedSize; |
| 115 if (--degree[u] == 0) { | 132 if (--degree[u] == 0) { |
| 116 leaves.add(u); | 133 leaves.add(u); |
| 117 } | 134 } |
| 118 } | 135 } |
| 119 } | 136 } |
| 120 } | 137 } |
| OLD | NEW |