Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
polina-c committed Mar 18, 2024
1 parent 2833fba commit 0f598e2
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 47 deletions.
81 changes: 44 additions & 37 deletions packages/devtools_app/test/memory/shared/heap/heap_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,25 @@ final _classA = HeapClassName.fromPath(className: 'A', library: 'l');
final _classB = HeapClassName.fromPath(className: 'B', library: 'l');

final _classSizeTests = <_ClassSizeTest>[
// _ClassSizeTest(
// name: 'separate',
// heap: HeapSnapshotGraphFake()
// ..setObjects(
// {
// 1: [2, 3, 4],
// 2: [],
// 3: [],
// 4: [],
// },
// classes: {
// 1: _root,
// 2: _classA,
// 3: _classA,
// 4: _classA,
// },
// ),
// expectedClassARetainedSize: 3,
// ),
_ClassSizeTest(
name: 'separate',
heap: HeapSnapshotGraphFake()
..setObjects(
{
1: [2, 3, 4],
2: [],
3: [],
4: [],
},
classes: {
1: _root,
2: _classA,
3: _classA,
4: _classA,
},
),
expectedClassARetainedSize: 3,
),
_ClassSizeTest(
name: 'linked',
heap: HeapSnapshotGraphFake()
Expand All @@ -64,19 +64,25 @@ final _classSizeTests = <_ClassSizeTest>[
),
expectedClassARetainedSize: 3,
),
// _ClassSizeTest(
// name: 'full graph',
// heap: AdaptedHeapData(
// [
// _createOneByteObject(0, [1], _root),
// _createOneByteObject(1, [2, 3], _classA),
// _createOneByteObject(2, [3, 1], _classA),
// _createOneByteObject(3, [1, 2], _classA),
// ],
// rootIndex: 0,
// ),
// expectedClassARetainedSize: 3,
// ),
_ClassSizeTest(
name: 'full graph',
heap: HeapSnapshotGraphFake()
..setObjects(
{
1: [2],
2: [3, 4],
3: [2, 4],
4: [2, 3],
},
classes: {
1: _root,
2: _classA,
3: _classA,
4: _classA,
},
),
expectedClassARetainedSize: 3,
),
// _ClassSizeTest(
// name: 'with global B',
// heap: AdaptedHeapData(
Expand All @@ -94,9 +100,10 @@ final _classSizeTests = <_ClassSizeTest>[
];

void main() {
test('$SingleClassData does not double-count self-referenced classes.',
() async {
for (final t in _classSizeTests) {
for (final t in _classSizeTests) {
test(
'$SingleClassData does not double-count self-referenced classes, ${t.name}.',
() async {
final heapData = await HeapData.calculate(t.heap, DateTime.now());

final classes = heapData.classes!;
Expand All @@ -107,6 +114,6 @@ void main() {
t.expectedClassARetainedSize,
reason: t.name,
);
}
});
});
}
}
41 changes: 31 additions & 10 deletions packages/devtools_app/test/shared/memory/retaining_path_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ void main() {
expect(path1, isNot(path3));
});

test('$PathFromRoot construction', () async {
group('$PathFromRoot construction', () {
final root = HeapClassName.fromPath(className: 'Root', library: 'l');
final classA = HeapClassName.fromPath(className: 'A', library: 'l');
final classB = HeapClassName.fromPath(className: 'B', library: 'l');
final classC = HeapClassName.fromPath(className: 'C', library: 'l');

final graph = HeapSnapshotGraphFake()
..setObjects(
Expand All @@ -43,18 +45,37 @@ void main() {
classes: {
1: root,
2: classA,
3: classA,
4: classA,
3: classB,
4: classC,
},
);
final shortestRetainers = const [0, 0, 1, 2, 3];

final path = PathFromRoot.forObject(
graph,
shortestRetainers: const [0, 0, 1, 2, 3],
index: 3,
);
PathFromRoot objectPath(int index) => PathFromRoot.forObject(
graph,
shortestRetainers: shortestRetainers,
index: index,
);

expect(path.path, hasLength(1));
expect(path.path[0], classA);
test('directly to root', () async {
final path = objectPath(2);

expect(path.path, hasLength(0));
});

test('one step', () async {
final path = objectPath(3);

expect(path.path, hasLength(1));
expect(path.path[0], classA);
});

test('two steps', () async {
final path = objectPath(4);

expect(path.path, hasLength(2));
expect(path.path[0], classB);
expect(path.path[1], classA);
});
});
}

0 comments on commit 0f598e2

Please sign in to comment.