Skip to content

Commit 80aa5fd

Browse files
rmacnak-googlecommit-bot@chromium.org
authored andcommitted
[observatory] Account for external size in the "Classes (table)" and "Classes (treemap)" views.
Mechanically, this renames shallowSize to internalSize and redefines shallowSize as internalSize + externalSize. Change-Id: I734f5714ad6dff341627e3d6e51e3bdcf26c63ad Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/125993 Reviewed-by: Ben Konyi <[email protected]> Commit-Queue: Ryan Macnak <[email protected]>
1 parent b92cd2c commit 80aa5fd

File tree

3 files changed

+47
-41
lines changed

3 files changed

+47
-41
lines changed

runtime/observatory/lib/object_graph.dart

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ abstract class SnapshotObject {
9999
String get description;
100100
SnapshotClass get klass;
101101
int get shallowSize;
102+
int get internalSize;
102103
int get externalSize;
103104
int get retainedSize;
104105
Iterable<SnapshotObject> get successors;
@@ -124,7 +125,8 @@ class _SnapshotObject implements SnapshotObject {
124125

125126
int get hashCode => _id;
126127

127-
int get shallowSize => _graph._shallowSizes[_id];
128+
int get shallowSize => internalSize + externalSize;
129+
int get internalSize => _graph._internalSizes[_id];
128130
int get externalSize => _graph._externalSizes[_id];
129131
int get retainedSize => _graph._retainedSizes[_id];
130132

@@ -199,12 +201,14 @@ class MergedObjectVertex {
199201

200202
SnapshotClass get klass => _graph._classes[_graph._cids[_id]];
201203

202-
int get shallowSize {
204+
int get shallowSize => internalSize + externalSize;
205+
206+
int get internalSize {
203207
var cids = _graph._cids;
204208
var size = 0;
205209
var sibling = _id;
206210
while (sibling != SENTINEL && cids[sibling] == cids[_id]) {
207-
size += _graph._shallowSizes[sibling];
211+
size += _graph._internalSizes[sibling];
208212
sibling = _graph._mergedDomNext[sibling];
209213
}
210214
return size;
@@ -367,8 +371,9 @@ class _InstancesIterator implements Iterator<SnapshotObject> {
367371

368372
abstract class SnapshotClass {
369373
String get name;
370-
int get externalSize;
371374
int get shallowSize;
375+
int get externalSize;
376+
int get internalSize;
372377
int get ownedSize;
373378
int get instanceCount;
374379
Iterable<SnapshotObject> get instances;
@@ -383,16 +388,17 @@ class _SnapshotClass implements SnapshotClass {
383388
final Map<int, String> fields = new Map<int, String>();
384389

385390
int totalExternalSize = 0;
386-
int totalShallowSize = 0;
391+
int totalInternalSize = 0;
387392
int totalInstanceCount = 0;
388393

389394
int ownedSize = 0;
390395

391396
int liveExternalSize = 0;
392-
int liveShallowSize = 0;
397+
int liveInternalSize = 0;
393398
int liveInstanceCount = 0;
394399

395-
int get shallowSize => liveShallowSize;
400+
int get shallowSize => internalSize + externalSize;
401+
int get internalSize => liveInternalSize;
396402
int get externalSize => liveExternalSize;
397403
int get instanceCount => liveInstanceCount;
398404

@@ -403,7 +409,7 @@ class _SnapshotClass implements SnapshotClass {
403409
}
404410

405411
abstract class SnapshotGraph {
406-
int get shallowSize;
412+
int get internalSize;
407413
int get externalSize;
408414
int get size;
409415
int get capacity;
@@ -434,8 +440,8 @@ const kUnknownFieldName = "<unknown>";
434440
class _SnapshotGraph implements SnapshotGraph {
435441
_SnapshotGraph(Uint8List encoded) : this._encoded = encoded;
436442

437-
int get size => _liveShallowSize + _liveExternalSize;
438-
int get shallowSize => _liveShallowSize;
443+
int get size => _liveInternalSize + _liveExternalSize;
444+
int get internalSize => _liveInternalSize;
439445
int get externalSize => _liveExternalSize;
440446
int get capacity => _capacity;
441447

@@ -559,9 +565,9 @@ class _SnapshotGraph implements SnapshotGraph {
559565
int _E; // References in the snapshot.
560566

561567
int _capacity;
562-
int _liveShallowSize;
568+
int _liveInternalSize;
563569
int _liveExternalSize;
564-
int _totalShallowSize;
570+
int _totalInternalSize;
565571
int _totalExternalSize;
566572

567573
List<_SnapshotClass> _classes;
@@ -570,7 +576,7 @@ class _SnapshotGraph implements SnapshotGraph {
570576
// From snapshot.
571577
List _nonReferenceData;
572578
Uint16List _cids;
573-
Uint32List _shallowSizes;
579+
Uint32List _internalSizes;
574580
Uint32List _externalSizes;
575581
Uint32List _firstSuccs;
576582
Uint32List _succs;
@@ -595,7 +601,7 @@ class _SnapshotGraph implements SnapshotGraph {
595601
stream.readUnsigned(); // Flags
596602
stream.readUtf8(); // Name
597603

598-
_totalShallowSize = stream.readUnsigned();
604+
_totalInternalSize = stream.readUnsigned();
599605
_capacity = stream.readUnsigned();
600606
_totalExternalSize = stream.readUnsigned();
601607

@@ -632,7 +638,7 @@ class _SnapshotGraph implements SnapshotGraph {
632638
_N = N;
633639
_E = E;
634640

635-
var shallowSizes = new Uint32List(N + 1);
641+
var internalSizes = new Uint32List(N + 1);
636642
var cids = new Uint16List(N + 1);
637643
var nonReferenceData = new List(N + 1);
638644
var firstSuccs = new Uint32List(N + 2);
@@ -642,8 +648,8 @@ class _SnapshotGraph implements SnapshotGraph {
642648
var cid = stream.readUnsigned();
643649
cids[oid] = cid;
644650

645-
var shallowSize = stream.readUnsigned();
646-
shallowSizes[oid] = shallowSize;
651+
var internalSize = stream.readUnsigned();
652+
internalSizes[oid] = internalSize;
647653

648654
var nonReferenceDataTag = stream.readUnsigned();
649655
switch (nonReferenceDataTag) {
@@ -702,7 +708,7 @@ class _SnapshotGraph implements SnapshotGraph {
702708

703709
assert(eid <= E);
704710
_E = eid;
705-
_shallowSizes = shallowSizes;
711+
_internalSizes = internalSizes;
706712
_cids = cids;
707713
_nonReferenceData = nonReferenceData;
708714
_firstSuccs = firstSuccs;
@@ -728,25 +734,25 @@ class _SnapshotGraph implements SnapshotGraph {
728734
var N = _N;
729735
var classes = _classes;
730736
var cids = _cids;
731-
var shallowSizes = _shallowSizes;
737+
var internalSizes = _internalSizes;
732738
var externalSizes = _externalSizes;
733-
var totalShallowSize = 0;
739+
var totalInternalSize = 0;
734740
var totalExternalSize = 0;
735741

736742
for (var oid = 1; oid <= N; oid++) {
737-
var shallowSize = shallowSizes[oid];
738-
totalShallowSize += shallowSize;
743+
var internalSize = internalSizes[oid];
744+
totalInternalSize += internalSize;
739745

740746
var externalSize = externalSizes[oid];
741747
totalExternalSize += externalSize;
742748

743749
var cls = classes[cids[oid]];
744-
cls.totalShallowSize += shallowSize;
750+
cls.totalInternalSize += internalSize;
745751
cls.totalExternalSize += externalSize;
746752
cls.totalInstanceCount++;
747753
}
748754

749-
_totalShallowSize = totalShallowSize;
755+
_totalInternalSize = totalInternalSize;
750756
_totalExternalSize = totalExternalSize;
751757
}
752758

@@ -907,7 +913,7 @@ class _SnapshotGraph implements SnapshotGraph {
907913
var kFieldCid = _kFieldCid;
908914

909915
var cids = _cids;
910-
var shallowSizes = _shallowSizes;
916+
var internalSizes = _internalSizes;
911917
var externalSizes = _externalSizes;
912918
var vertex = _vertex;
913919
var firstPreds = _firstPreds;
@@ -916,7 +922,7 @@ class _SnapshotGraph implements SnapshotGraph {
916922
var ownedSizes = new Uint32List(N + 1);
917923
for (var i = 1; i <= Nconnected; i++) {
918924
var v = vertex[i];
919-
ownedSizes[v] = shallowSizes[v] + externalSizes[v];
925+
ownedSizes[v] = internalSizes[v] + externalSizes[v];
920926
}
921927

922928
for (var i = Nconnected; i > 1; i--) {
@@ -1120,33 +1126,33 @@ class _SnapshotGraph implements SnapshotGraph {
11201126
var N = _N;
11211127
var Nconnected = _Nconnected;
11221128

1123-
var liveShallowSize = 0;
1129+
var liveInternalSize = 0;
11241130
var liveExternalSize = 0;
11251131
var classes = _classes;
11261132
var cids = _cids;
1127-
var shallowSizes = _shallowSizes;
1133+
var internalSizes = _internalSizes;
11281134
var externalSizes = _externalSizes;
11291135
var vertex = _vertex;
11301136
var doms = _doms;
11311137

11321138
// Sum internal and external sizes.
11331139
for (var i = 1; i <= Nconnected; i++) {
11341140
var v = vertex[i];
1135-
var shallowSize = shallowSizes[v];
1141+
var internalSize = internalSizes[v];
11361142
var externalSize = externalSizes[v];
1137-
liveShallowSize += shallowSize;
1143+
liveInternalSize += internalSize;
11381144
liveExternalSize += externalSize;
11391145

11401146
var cls = classes[cids[v]];
1141-
cls.liveShallowSize += shallowSize;
1147+
cls.liveInternalSize += internalSize;
11421148
cls.liveExternalSize += externalSize;
11431149
cls.liveInstanceCount++;
11441150
}
11451151

11461152
// Start with retained size as shallow size + external size.
11471153
var retainedSizes = new Uint32List(N + 1);
11481154
for (var i = 0; i < N + 1; i++) {
1149-
retainedSizes[i] = shallowSizes[i] + externalSizes[i];
1155+
retainedSizes[i] = internalSizes[i] + externalSizes[i];
11501156
}
11511157

11521158
// In post order (bottom up), add retained size to dominator's retained
@@ -1158,19 +1164,20 @@ class _SnapshotGraph implements SnapshotGraph {
11581164
}
11591165

11601166
// Root retains everything.
1161-
assert(retainedSizes[ROOT] == (liveShallowSize + liveExternalSize));
1167+
assert(retainedSizes[ROOT] == (liveInternalSize + liveExternalSize));
11621168

11631169
_retainedSizes = retainedSizes;
1164-
_liveShallowSize = liveShallowSize;
1170+
_liveInternalSize = liveInternalSize;
11651171
_liveExternalSize = liveExternalSize;
11661172

11671173
Logger.root
1168-
.info("internal-garbage: ${_totalShallowSize - _liveShallowSize}");
1174+
.info("internal-garbage: ${_totalInternalSize - _liveInternalSize}");
11691175
Logger.root
11701176
.info("external-garbage: ${_totalExternalSize - _liveExternalSize}");
1171-
Logger.root.info("fragmentation: ${_capacity - _totalShallowSize}");
1172-
assert(_liveShallowSize <= _totalShallowSize);
1173-
assert(_totalShallowSize <= _capacity);
1177+
Logger.root.info("fragmentation: ${_capacity - _totalInternalSize}");
1178+
assert(_liveInternalSize <= _totalInternalSize);
1179+
assert(_liveExternalSize <= _totalExternalSize);
1180+
assert(_totalInternalSize <= _capacity);
11741181
}
11751182

11761183
// Build linked lists of the children for each node in the dominator tree.

runtime/observatory/lib/src/elements/heap_snapshot.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -873,8 +873,7 @@ class HeapSnapshotElement extends CustomElement implements Renderable {
873873
_updateLines(element.children[1].children, depth);
874874
element.children[2].text =
875875
Utils.formatPercentNormalized(node.shallowSize * 1.0 / _snapshot.size);
876-
element.children[3].text =
877-
Utils.formatSize(node.shallowSize + node.externalSize);
876+
element.children[3].text = Utils.formatSize(node.shallowSize);
878877
element.children[4].text = node.instanceCount.toString();
879878
element.children[5].text = node.name;
880879
}

runtime/observatory/lib/src/heap_snapshot/heap_snapshot.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ part of heap_snapshot;
1111
class HeapSnapshot implements M.HeapSnapshot {
1212
SnapshotGraph graph;
1313
DateTime timestamp;
14-
int get size => graph.shallowSize + graph.externalSize;
14+
int get size => graph.internalSize + graph.externalSize;
1515
HeapSnapshotMergedDominatorNode mergedDominatorTree;
1616
List<SnapshotClass> classes;
1717
SnapshotObject get root => graph.root;

0 commit comments

Comments
 (0)