Skip to content

Diff heap statistics. #4501

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 171 commits into from
Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
171 commits
Select commit Hold shift + click to select a range
88e3c0d
r
polina-c Sep 9, 2022
40f96b4
-
polina-c Sep 9, 2022
4f35c1b
-
polina-c Sep 9, 2022
87794ef
Merge branch 'master' of github.com:flutter/devtools into size
polina-c Sep 9, 2022
070f797
Update model.dart
polina-c Sep 9, 2022
54a36a1
Update model.dart
polina-c Sep 9, 2022
bd4949c
Update model.dart
polina-c Sep 9, 2022
98f58ef
Merge branch 'master' of github.com:flutter/devtools into retained
polina-c Sep 9, 2022
19a7c37
-
polina-c Sep 9, 2022
86700a3
-
polina-c Sep 10, 2022
ef2d558
-
polina-c Sep 10, 2022
9991886
-
polina-c Sep 11, 2022
fd89707
-
polina-c Sep 11, 2022
4e3f5a0
Update heap_analyzer_test.dart
polina-c Sep 11, 2022
472625b
-
polina-c Sep 11, 2022
1931fea
-
polina-c Sep 11, 2022
0bab199
-
polina-c Sep 11, 2022
e51cd2a
-
polina-c Sep 11, 2022
78d65f6
-
polina-c Sep 11, 2022
9e2e970
-
polina-c Sep 11, 2022
93900af
Merge branch 'stager' into size2
polina-c Sep 11, 2022
5afdbfb
Update diff_pane_test.dart
polina-c Sep 11, 2022
da0c005
-
polina-c Sep 11, 2022
e57318c
-
polina-c Sep 11, 2022
f1d9623
Update diff_pane_test.dart
polina-c Sep 11, 2022
4115819
Update diff_pane_test.dart
polina-c Sep 11, 2022
ce85cdd
-
polina-c Sep 12, 2022
d489a31
-
polina-c Sep 12, 2022
7f7bae1
-
polina-c Sep 12, 2022
3df81f8
-
polina-c Sep 12, 2022
e470e4c
Merge branch 'size1' into size2
polina-c Sep 12, 2022
7a85608
-
polina-c Sep 12, 2022
13d2756
Update memory_hover_card.png
polina-c Sep 12, 2022
fbc3a6e
-
polina-c Sep 12, 2022
64b20f1
Update memory_diff_empty.png
polina-c Sep 12, 2022
362dd29
-
polina-c Sep 12, 2022
34d6f11
Update model.dart
polina-c Sep 12, 2022
a00e502
-
polina-c Sep 12, 2022
07eb2fe
Update mocks.dart
polina-c Sep 12, 2022
41a7553
Update pubspec.yaml
polina-c Sep 12, 2022
380be7f
Update generate_code.sh
polina-c Sep 12, 2022
45dc0e1
Update refresh.sh
polina-c Sep 12, 2022
002d7d5
Update bots.sh
polina-c Sep 12, 2022
6238161
Merge branch 'stager' into size1
polina-c Sep 13, 2022
15fe292
Merge branch 'size1' into size2
polina-c Sep 13, 2022
37230b1
Update diff_pane_test.dart
polina-c Sep 13, 2022
5f1186b
Update common_widgets.dart
polina-c Sep 13, 2022
f028530
-
polina-c Sep 13, 2022
91ca15d
-
polina-c Sep 13, 2022
688ba9b
-
polina-c Sep 13, 2022
dce7eb7
Merge branch 'master' of github.com:flutter/devtools into size2
polina-c Sep 13, 2022
b83af3c
-
polina-c Sep 13, 2022
5966ba6
-
polina-c Sep 13, 2022
97ba965
-
polina-c Sep 13, 2022
5478c00
-
polina-c Sep 13, 2022
25fb537
Update snapshot_view.dart
polina-c Sep 13, 2022
e50bf91
-
polina-c Sep 14, 2022
1ee043a
-
polina-c Sep 14, 2022
65dd972
-
polina-c Sep 14, 2022
087043b
-
polina-c Sep 14, 2022
94cbbf8
-
polina-c Sep 14, 2022
1ea913d
-
polina-c Sep 14, 2022
dc4e915
Update snapshot_view.dart
polina-c Sep 14, 2022
4fea4a7
-
polina-c Sep 14, 2022
57d8f5f
Update snapshot_control.dart
polina-c Sep 14, 2022
9e7ff13
Merge branch 'master' of github.com:flutter/devtools into size2
polina-c Sep 15, 2022
0f6ce0f
Update diff_pane.dart
polina-c Sep 15, 2022
8671ab4
-
polina-c Sep 15, 2022
5d14a5a
Merge branch 'size2' into diff3
polina-c Sep 15, 2022
95b5878
-
polina-c Sep 15, 2022
e6412a5
Update snapshot_control_pane.dart
polina-c Sep 15, 2022
9ab7569
Update model.dart
polina-c Sep 15, 2022
e4949de
Merge branch 'master' of github.com:flutter/devtools into size2
polina-c Sep 15, 2022
4c16c17
-
polina-c Sep 15, 2022
cd91650
Update diff_pane_controller.dart
polina-c Sep 15, 2022
f7fc09e
Update memory_controller.dart
polina-c Sep 15, 2022
a6e6743
Merge branch 'size2' into diff3
polina-c Sep 15, 2022
63dc0eb
Update model.dart
polina-c Sep 15, 2022
73d7096
-
polina-c Sep 15, 2022
75d3423
Merge branch 'refactor35' into diff3
polina-c Sep 15, 2022
3d1eda5
-
polina-c Sep 15, 2022
fc4dd57
-
polina-c Sep 15, 2022
16237aa
-
polina-c Sep 15, 2022
828970a
Update feature_flags.dart
polina-c Sep 15, 2022
ab3ec0a
Update feature_flags.dart
polina-c Sep 15, 2022
f357350
Merge branch 'feature_flags' into size2
polina-c Sep 15, 2022
e27a0d8
-
polina-c Sep 15, 2022
f7c70b3
Update snapshot_view.dart
polina-c Sep 16, 2022
9bb8a87
-
polina-c Sep 19, 2022
7ef3213
-
polina-c Sep 19, 2022
1961b34
-
polina-c Sep 19, 2022
afc095e
-
polina-c Sep 19, 2022
def70a3
-
polina-c Sep 19, 2022
7fd6469
Merge branch 'master' of github.com:flutter/devtools into size2
polina-c Sep 19, 2022
7ddb3a9
Update offline.dart
polina-c Sep 19, 2022
992008b
Delete offline.dart
polina-c Sep 19, 2022
600b508
Update feature_flags.dart
polina-c Sep 19, 2022
8b4a10f
Merge branch 'size2' into diff3
polina-c Sep 19, 2022
82eec49
-
polina-c Sep 19, 2022
4dbb5b7
Update table_test.dart
polina-c Sep 19, 2022
466c9b2
-
polina-c Sep 19, 2022
c3237db
-
polina-c Sep 19, 2022
a3f683a
Update common_widgets.dart
polina-c Sep 19, 2022
4a8c2e8
Update memory_diff_three_snapshots.png
polina-c Sep 19, 2022
8740e12
Merge branch 'size2' into diff3
polina-c Sep 19, 2022
6cffd19
Update memory_diff_three_snapshots.png
polina-c Sep 19, 2022
b7aca0c
Update memory_diff_three_snapshots.png
polina-c Sep 19, 2022
47d0bc7
Merge branch 'size2' into refactor25
polina-c Sep 19, 2022
ad372be
-
polina-c Sep 19, 2022
fe6f4e9
-
polina-c Sep 19, 2022
cd6d092
-
polina-c Sep 19, 2022
06ea6ba
-
polina-c Sep 19, 2022
4f87f3e
-
polina-c Sep 19, 2022
daa54c4
Update snapshot_view.dart
polina-c Sep 19, 2022
03b1888
-
polina-c Sep 19, 2022
6152a03
-
polina-c Sep 19, 2022
eadab87
Update snapshot_list.dart
polina-c Sep 19, 2022
de6b323
Update snapshot_list.dart
polina-c Sep 19, 2022
9303d1d
Update snapshot_list.dart
polina-c Sep 19, 2022
627fee3
Update snapshot_list.dart
polina-c Sep 19, 2022
203577a
Update memory_controller.dart
polina-c Sep 19, 2022
b715b69
Update diff_pane.dart
polina-c Sep 19, 2022
0eb648b
Update snapshot_list.dart
polina-c Sep 19, 2022
d932e1d
Update snapshot_list.dart
polina-c Sep 19, 2022
ffa4eb1
Update auto_dispose_mixin.dart
polina-c Sep 19, 2022
1d3fbbd
Update snapshot_list.dart
polina-c Sep 20, 2022
a7a7819
Update snapshot_list.dart
polina-c Sep 20, 2022
ba4d20a
-
polina-c Sep 20, 2022
e481ac8
-
polina-c Sep 20, 2022
2961a48
Merge branch 'size2' into refactor25
polina-c Sep 20, 2022
099e4e9
Merge branch 'refactor25' into diff3
polina-c Sep 20, 2022
17b7a4e
-
polina-c Sep 20, 2022
49c4c5c
-
polina-c Sep 20, 2022
75e1017
Merge branch 'master' of github.com:flutter/devtools into refactor25
polina-c Sep 20, 2022
d994ca7
-
polina-c Sep 20, 2022
befc361
Update model.dart
polina-c Sep 20, 2022
8753246
Merge branch 'refactor25' into diff3
polina-c Sep 20, 2022
af05352
-
polina-c Sep 20, 2022
c70a2ea
-
polina-c Sep 20, 2022
ec57489
-
polina-c Sep 20, 2022
3c26ddf
-
polina-c Sep 20, 2022
d7adc73
Merge branch 'refactor25' into diff3
polina-c Sep 20, 2022
fbc2334
Update model_test.dart
polina-c Sep 20, 2022
1bc7da9
-
polina-c Sep 20, 2022
66702a5
-
polina-c Sep 21, 2022
8d20b1a
-
polina-c Sep 21, 2022
bce22a6
-
polina-c Sep 21, 2022
94a652f
Merge branch 'refactor25' into diff3
polina-c Sep 21, 2022
ff510c0
-
polina-c Sep 21, 2022
f735e65
-
polina-c Sep 21, 2022
f598998
Update snapshot_view.dart
polina-c Sep 21, 2022
94f4b04
-
polina-c Sep 21, 2022
2b75990
Merge branch 'refactor25' into diff3
polina-c Sep 21, 2022
3647fdf
Merge branch 'diff3' into details4
polina-c Sep 21, 2022
c6a81a2
Update stats_table.dart
polina-c Sep 21, 2022
6b29f53
Merge branch 'master' of github.com:flutter/devtools into diff3
polina-c Sep 21, 2022
5163358
Merge branch 'diff3' into details4
polina-c Sep 21, 2022
86393ef
to-controller1
polina-c Sep 21, 2022
9ee2f4b
-
polina-c Sep 21, 2022
e64236a
Update table_test.dart
polina-c Sep 21, 2022
48dd684
-
polina-c Sep 21, 2022
60d024d
-
polina-c Sep 22, 2022
ee60ec8
Merge branch 'master' of github.com:flutter/devtools into details4
polina-c Sep 22, 2022
1b1b019
Update diff_pane_controller.dart
polina-c Sep 22, 2022
7f54c00
-
polina-c Sep 22, 2022
a704f48
Update model.dart
polina-c Sep 22, 2022
3ffb431
-
polina-c Sep 22, 2022
9739f90
-
polina-c Sep 22, 2022
63cf573
-
polina-c Sep 22, 2022
47e569f
-
polina-c Sep 22, 2022
7a1f04b
Update snapshot_control_pane.dart
polina-c Sep 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ import 'package:flutter/foundation.dart';
import '../../../../../primitives/utils.dart';
import '../../../primitives/memory_utils.dart';
import '../../../shared/heap/model.dart';
import 'model.dart';
import 'heap_diff.dart';
import 'item_controller.dart';

class DiffPaneController {
DiffPaneController(this.snapshotTaker);

final SnapshotTaker snapshotTaker;

final diffStore = HeapDiffStore();

/// The list contains one item that show information and all others
/// are snapshots.
ValueListenable<List<DiffListItem>> get snapshots => _snapshots;
Expand All @@ -29,7 +32,12 @@ class DiffPaneController {
ValueListenable<bool> get isProcessing => _isProcessing;
final _isProcessing = ValueNotifier<bool>(false);

DiffListItem get selected => snapshots.value[selectedIndex.value];
DiffListItem get selectedItem => snapshots.value[selectedIndex.value];

/// Full name for the selected class.
ValueListenable<String?> get selectedClass => _selectedClass;
final _selectedClass = ValueNotifier<String?>(null);
void setSelectedClass(String? value) => _selectedClass.value = value;

/// True, if the list contains snapshots, i.e. items beyond the first
/// informational item.
Expand All @@ -43,6 +51,8 @@ class DiffPaneController {
future,
_nextDisplayNumber(),
currentIsolateName ?? '<isolate-not-detected>',
diffStore,
selectedClass,
),
);
await future;
Expand All @@ -52,6 +62,9 @@ class DiffPaneController {
}

Future<void> clearSnapshots() async {
for (var i = 1; i < snapshots.value.length; i++) {
snapshots.value[i].dispose();
}
_snapshots.removeRange(1, snapshots.value.length);
_selectedIndex.value = 0;
}
Expand All @@ -63,7 +76,8 @@ class DiffPaneController {
}

void deleteCurrentSnapshot() {
assert(selected is SnapshotListItem);
assert(selectedItem is SnapshotListItem);
selectedItem.dispose();
_snapshots.removeRange(selectedIndex.value, selectedIndex.value + 1);
// We must change the selectedIndex, because otherwise the content will
// not be re-rendered.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// Copyright 2022 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/foundation.dart';

import '../../../shared/heap/heap.dart';
import '../../../shared/heap/model.dart';

/// Stores already calculated comparisons for heap couples.
class HeapDiffStore {
final _store = <_HeapCouple, HeapComparison>{};

HeapComparison compare(AdaptedHeap heap1, AdaptedHeap heap2) {
final couple = _HeapCouple(heap1, heap2);
return _store.putIfAbsent(couple, () => HeapComparison(couple));
}
}

@immutable
class _HeapCouple {
_HeapCouple(AdaptedHeap heap1, AdaptedHeap heap2) {
older = _older(heap1, heap2);
younger = older == heap1 ? heap2 : heap1;
}

late final AdaptedHeap older;
late final AdaptedHeap younger;

/// Finds most deterministic way to declare earliest heap.
///
/// If earliest heap cannot be identified, returns first argument.
static AdaptedHeap _older(AdaptedHeap heap1, AdaptedHeap heap2) {
assert(heap1.data != heap2.data);
if (heap1.data.created.isBefore(heap2.data.created)) return heap1;
if (heap2.data.created.isBefore(heap1.data.created)) return heap2;
if (identityHashCode(heap1) < identityHashCode(heap2)) return heap1;
if (identityHashCode(heap2) < identityHashCode(heap1)) return heap2;
if (identityHashCode(heap1.data) < identityHashCode(heap2.data))
return heap1;
if (identityHashCode(heap2.data) < identityHashCode(heap1.data))
return heap2;
return heap1;
}

@override
bool operator ==(Object other) {
if (other.runtimeType != runtimeType) {
return false;
}
Comment on lines +48 to +50
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be captured by the other is _HeapCouple check

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copied it from https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#common-boilerplates-for-operator--and-hashcode.
I would stay with the standard.
Maybe is is more expensive and we want to exit early?

return other is _HeapCouple &&
other.older == older &&
other.younger == younger;
}

@override
int get hashCode => Object.hash(older, younger);
}

class HeapComparison {
HeapComparison(this.heapCouple);

late final HeapStatistics stats = _stats();

final _HeapCouple heapCouple;

HeapStatistics _stats() {
final result = <String, HeapStatsRecord>{};

final older = heapCouple.older.stats.recordsByClass;
final younger = heapCouple.younger.stats.recordsByClass;

final unionOfKeys = older.keys.toSet().union(younger.keys.toSet());

for (var key in unionOfKeys) {
final olderRecord = older[key];
final youngerRecord = younger[key];

if (olderRecord != null && youngerRecord != null) {
final diff = _diffStatsRecords(olderRecord, youngerRecord);
if (!diff.isZero) result[key] = diff;
} else if (youngerRecord != null) {
result[key] = youngerRecord;
} else {
result[key] = olderRecord!.negative();
}
}

return HeapStatistics(result);
}

static HeapStatsRecord _diffStatsRecords(
HeapStatsRecord older,
HeapStatsRecord younger,
) {
assert(older.heapClass.fullName == younger.heapClass.fullName);
return HeapStatsRecord(older.heapClass)
..instanceCount = younger.instanceCount - older.instanceCount
..shallowSize = younger.shallowSize - older.shallowSize
..retainedSize = younger.retainedSize - older.retainedSize;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// Copyright 2022 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/foundation.dart';

import '../../../../../primitives/auto_dispose.dart';
import '../../../../../primitives/utils.dart';
import '../../../shared/heap/heap.dart';
import '../../../shared/heap/model.dart';
import 'heap_diff.dart';

abstract class DiffListItem extends DisposableController {
/// Number, that if shown in name, should be unique in the list.
///
/// If the number is not expected to be shown in UI, it should be 0.
int get displayNumber;

ValueListenable<bool> get isProcessing => _isProcessing;
final _isProcessing = ValueNotifier<bool>(false);

/// If true, the item contains data, that can be compared and analyzed.
bool get hasData;
}

class InformationListItem extends DiffListItem {
@override
int get displayNumber => 0;

@override
bool get hasData => false;
}

class SnapshotListItem extends DiffListItem with AutoDisposeControllerMixin {
SnapshotListItem(
Future<AdaptedHeapData?> receiver,
this.displayNumber,
this._isolateName,
this.diffStore,
this.selectedClassName,
) {
_isProcessing.value = true;
receiver.whenComplete(() async {
final data = await receiver;
if (data != null) {
heap = AdaptedHeap(data);
updateSelectedRecord();
addAutoDisposeListener(selectedClassName, () => updateSelectedRecord());
}
_isProcessing.value = false;
});
}

final String _isolateName;

final HeapDiffStore diffStore;

AdaptedHeap? heap;

@override
final int displayNumber;

String get name => '$_isolateName-$displayNumber';

var sorting = ColumnSorting();

ValueListenable<SnapshotListItem?> get diffWith => _diffWith;
final _diffWith = ValueNotifier<SnapshotListItem?>(null);
void setDiffWith(SnapshotListItem? value) {
_diffWith.value = value;
updateSelectedRecord();
}

final ValueListenable<String?> selectedClassName;

ValueListenable<HeapStatsRecord?> get selectedRecord => _selectedRecord;
final _selectedRecord = ValueNotifier<HeapStatsRecord?>(null);

@override
bool get hasData => heap != null;

HeapStatistics get statsToShow {
final theHeap = heap!;
final itemToDiffWith = diffWith.value;
if (itemToDiffWith == null) return theHeap.stats;
return diffStore.compare(theHeap, itemToDiffWith.heap!).stats;
}

void updateSelectedRecord() => _selectedRecord.value =
statsToShow.recordsByClass[selectedClassName.value];
}

class ColumnSorting {
bool initialized = false;
SortDirection direction = SortDirection.ascending;
int columnIndex = 0;
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import 'package:flutter/material.dart';

import '../../../../shared/common_widgets.dart';
import '../../../../shared/split.dart';
import '../../../../shared/theme.dart';
import 'controller/diff_pane_controller.dart';
import 'controller/model.dart';
import 'controller/item_controller.dart';
import 'widgets/snapshot_control_pane.dart';
import 'widgets/snapshot_list.dart';
import 'widgets/snapshot_view.dart';
Expand All @@ -22,7 +23,7 @@ class DiffPane extends StatelessWidget {
final Widget itemContent = ValueListenableBuilder<int>(
valueListenable: controller.selectedIndex,
builder: (_, index, __) {
final item = controller.selected;
final item = controller.selectedItem;

if (item is InformationListItem) {
return const _SnapshotDoc();
Expand Down Expand Up @@ -68,7 +69,7 @@ class _SnapshotDoc extends StatelessWidget {

class _SnapshotContent extends StatelessWidget {
_SnapshotContent({Key? key, required this.item, required this.controller})
: assert(controller.selected == item),
: assert(controller.selectedItem == item),
super(key: key);

final SnapshotListItem item;
Expand All @@ -78,9 +79,11 @@ class _SnapshotContent extends StatelessWidget {
Widget build(BuildContext context) {
return Column(
children: [
const SizedBox(height: denseRowSpacing),
SnapshotControlPane(controller: controller),
const SizedBox(height: denseRowSpacing),
Expanded(
child: SnapshotView(item: item),
child: SnapshotView(controller: controller),
),
],
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2022 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/widgets.dart';

import '../../../shared/heap/model.dart';

class HeapClassDetails extends StatelessWidget {
const HeapClassDetails({Key? key, required this.heapClass}) : super(key: key);

final HeapClass? heapClass;

@override
Widget build(BuildContext context) {
final theClass = heapClass;
if (theClass == null) {
return const Center(
child: Text('Select class to see details here.'),
);
}
return Center(child: Text('Details for ${theClass.fullName} will be here'));
}
}
Loading