Skip to content

Commit

Permalink
[observatory] Account for external size in the "Classes (table)" and …
Browse files Browse the repository at this point in the history
…"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 <bkonyi@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
  • Loading branch information
rmacnak-google authored and commit-bot@chromium.org committed Dec 6, 2019
1 parent b92cd2c commit 80aa5fd
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 41 deletions.
83 changes: 45 additions & 38 deletions runtime/observatory/lib/object_graph.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ abstract class SnapshotObject {
String get description;
SnapshotClass get klass;
int get shallowSize;
int get internalSize;
int get externalSize;
int get retainedSize;
Iterable<SnapshotObject> get successors;
Expand All @@ -124,7 +125,8 @@ class _SnapshotObject implements SnapshotObject {

int get hashCode => _id;

int get shallowSize => _graph._shallowSizes[_id];
int get shallowSize => internalSize + externalSize;
int get internalSize => _graph._internalSizes[_id];
int get externalSize => _graph._externalSizes[_id];
int get retainedSize => _graph._retainedSizes[_id];

Expand Down Expand Up @@ -199,12 +201,14 @@ class MergedObjectVertex {

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

int get shallowSize {
int get shallowSize => internalSize + externalSize;

int get internalSize {
var cids = _graph._cids;
var size = 0;
var sibling = _id;
while (sibling != SENTINEL && cids[sibling] == cids[_id]) {
size += _graph._shallowSizes[sibling];
size += _graph._internalSizes[sibling];
sibling = _graph._mergedDomNext[sibling];
}
return size;
Expand Down Expand Up @@ -367,8 +371,9 @@ class _InstancesIterator implements Iterator<SnapshotObject> {

abstract class SnapshotClass {
String get name;
int get externalSize;
int get shallowSize;
int get externalSize;
int get internalSize;
int get ownedSize;
int get instanceCount;
Iterable<SnapshotObject> get instances;
Expand All @@ -383,16 +388,17 @@ class _SnapshotClass implements SnapshotClass {
final Map<int, String> fields = new Map<int, String>();

int totalExternalSize = 0;
int totalShallowSize = 0;
int totalInternalSize = 0;
int totalInstanceCount = 0;

int ownedSize = 0;

int liveExternalSize = 0;
int liveShallowSize = 0;
int liveInternalSize = 0;
int liveInstanceCount = 0;

int get shallowSize => liveShallowSize;
int get shallowSize => internalSize + externalSize;
int get internalSize => liveInternalSize;
int get externalSize => liveExternalSize;
int get instanceCount => liveInstanceCount;

Expand All @@ -403,7 +409,7 @@ class _SnapshotClass implements SnapshotClass {
}

abstract class SnapshotGraph {
int get shallowSize;
int get internalSize;
int get externalSize;
int get size;
int get capacity;
Expand Down Expand Up @@ -434,8 +440,8 @@ const kUnknownFieldName = "<unknown>";
class _SnapshotGraph implements SnapshotGraph {
_SnapshotGraph(Uint8List encoded) : this._encoded = encoded;

int get size => _liveShallowSize + _liveExternalSize;
int get shallowSize => _liveShallowSize;
int get size => _liveInternalSize + _liveExternalSize;
int get internalSize => _liveInternalSize;
int get externalSize => _liveExternalSize;
int get capacity => _capacity;

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

int _capacity;
int _liveShallowSize;
int _liveInternalSize;
int _liveExternalSize;
int _totalShallowSize;
int _totalInternalSize;
int _totalExternalSize;

List<_SnapshotClass> _classes;
Expand All @@ -570,7 +576,7 @@ class _SnapshotGraph implements SnapshotGraph {
// From snapshot.
List _nonReferenceData;
Uint16List _cids;
Uint32List _shallowSizes;
Uint32List _internalSizes;
Uint32List _externalSizes;
Uint32List _firstSuccs;
Uint32List _succs;
Expand All @@ -595,7 +601,7 @@ class _SnapshotGraph implements SnapshotGraph {
stream.readUnsigned(); // Flags
stream.readUtf8(); // Name

_totalShallowSize = stream.readUnsigned();
_totalInternalSize = stream.readUnsigned();
_capacity = stream.readUnsigned();
_totalExternalSize = stream.readUnsigned();

Expand Down Expand Up @@ -632,7 +638,7 @@ class _SnapshotGraph implements SnapshotGraph {
_N = N;
_E = E;

var shallowSizes = new Uint32List(N + 1);
var internalSizes = new Uint32List(N + 1);
var cids = new Uint16List(N + 1);
var nonReferenceData = new List(N + 1);
var firstSuccs = new Uint32List(N + 2);
Expand All @@ -642,8 +648,8 @@ class _SnapshotGraph implements SnapshotGraph {
var cid = stream.readUnsigned();
cids[oid] = cid;

var shallowSize = stream.readUnsigned();
shallowSizes[oid] = shallowSize;
var internalSize = stream.readUnsigned();
internalSizes[oid] = internalSize;

var nonReferenceDataTag = stream.readUnsigned();
switch (nonReferenceDataTag) {
Expand Down Expand Up @@ -702,7 +708,7 @@ class _SnapshotGraph implements SnapshotGraph {

assert(eid <= E);
_E = eid;
_shallowSizes = shallowSizes;
_internalSizes = internalSizes;
_cids = cids;
_nonReferenceData = nonReferenceData;
_firstSuccs = firstSuccs;
Expand All @@ -728,25 +734,25 @@ class _SnapshotGraph implements SnapshotGraph {
var N = _N;
var classes = _classes;
var cids = _cids;
var shallowSizes = _shallowSizes;
var internalSizes = _internalSizes;
var externalSizes = _externalSizes;
var totalShallowSize = 0;
var totalInternalSize = 0;
var totalExternalSize = 0;

for (var oid = 1; oid <= N; oid++) {
var shallowSize = shallowSizes[oid];
totalShallowSize += shallowSize;
var internalSize = internalSizes[oid];
totalInternalSize += internalSize;

var externalSize = externalSizes[oid];
totalExternalSize += externalSize;

var cls = classes[cids[oid]];
cls.totalShallowSize += shallowSize;
cls.totalInternalSize += internalSize;
cls.totalExternalSize += externalSize;
cls.totalInstanceCount++;
}

_totalShallowSize = totalShallowSize;
_totalInternalSize = totalInternalSize;
_totalExternalSize = totalExternalSize;
}

Expand Down Expand Up @@ -907,7 +913,7 @@ class _SnapshotGraph implements SnapshotGraph {
var kFieldCid = _kFieldCid;

var cids = _cids;
var shallowSizes = _shallowSizes;
var internalSizes = _internalSizes;
var externalSizes = _externalSizes;
var vertex = _vertex;
var firstPreds = _firstPreds;
Expand All @@ -916,7 +922,7 @@ class _SnapshotGraph implements SnapshotGraph {
var ownedSizes = new Uint32List(N + 1);
for (var i = 1; i <= Nconnected; i++) {
var v = vertex[i];
ownedSizes[v] = shallowSizes[v] + externalSizes[v];
ownedSizes[v] = internalSizes[v] + externalSizes[v];
}

for (var i = Nconnected; i > 1; i--) {
Expand Down Expand Up @@ -1120,33 +1126,33 @@ class _SnapshotGraph implements SnapshotGraph {
var N = _N;
var Nconnected = _Nconnected;

var liveShallowSize = 0;
var liveInternalSize = 0;
var liveExternalSize = 0;
var classes = _classes;
var cids = _cids;
var shallowSizes = _shallowSizes;
var internalSizes = _internalSizes;
var externalSizes = _externalSizes;
var vertex = _vertex;
var doms = _doms;

// Sum internal and external sizes.
for (var i = 1; i <= Nconnected; i++) {
var v = vertex[i];
var shallowSize = shallowSizes[v];
var internalSize = internalSizes[v];
var externalSize = externalSizes[v];
liveShallowSize += shallowSize;
liveInternalSize += internalSize;
liveExternalSize += externalSize;

var cls = classes[cids[v]];
cls.liveShallowSize += shallowSize;
cls.liveInternalSize += internalSize;
cls.liveExternalSize += externalSize;
cls.liveInstanceCount++;
}

// Start with retained size as shallow size + external size.
var retainedSizes = new Uint32List(N + 1);
for (var i = 0; i < N + 1; i++) {
retainedSizes[i] = shallowSizes[i] + externalSizes[i];
retainedSizes[i] = internalSizes[i] + externalSizes[i];
}

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

// Root retains everything.
assert(retainedSizes[ROOT] == (liveShallowSize + liveExternalSize));
assert(retainedSizes[ROOT] == (liveInternalSize + liveExternalSize));

_retainedSizes = retainedSizes;
_liveShallowSize = liveShallowSize;
_liveInternalSize = liveInternalSize;
_liveExternalSize = liveExternalSize;

Logger.root
.info("internal-garbage: ${_totalShallowSize - _liveShallowSize}");
.info("internal-garbage: ${_totalInternalSize - _liveInternalSize}");
Logger.root
.info("external-garbage: ${_totalExternalSize - _liveExternalSize}");
Logger.root.info("fragmentation: ${_capacity - _totalShallowSize}");
assert(_liveShallowSize <= _totalShallowSize);
assert(_totalShallowSize <= _capacity);
Logger.root.info("fragmentation: ${_capacity - _totalInternalSize}");
assert(_liveInternalSize <= _totalInternalSize);
assert(_liveExternalSize <= _totalExternalSize);
assert(_totalInternalSize <= _capacity);
}

// Build linked lists of the children for each node in the dominator tree.
Expand Down
3 changes: 1 addition & 2 deletions runtime/observatory/lib/src/elements/heap_snapshot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -873,8 +873,7 @@ class HeapSnapshotElement extends CustomElement implements Renderable {
_updateLines(element.children[1].children, depth);
element.children[2].text =
Utils.formatPercentNormalized(node.shallowSize * 1.0 / _snapshot.size);
element.children[3].text =
Utils.formatSize(node.shallowSize + node.externalSize);
element.children[3].text = Utils.formatSize(node.shallowSize);
element.children[4].text = node.instanceCount.toString();
element.children[5].text = node.name;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ part of heap_snapshot;
class HeapSnapshot implements M.HeapSnapshot {
SnapshotGraph graph;
DateTime timestamp;
int get size => graph.shallowSize + graph.externalSize;
int get size => graph.internalSize + graph.externalSize;
HeapSnapshotMergedDominatorNode mergedDominatorTree;
List<SnapshotClass> classes;
SnapshotObject get root => graph.root;
Expand Down

0 comments on commit 80aa5fd

Please sign in to comment.