Skip to content

Commit

Permalink
Add timeline event on snapshot. (#6530)
Browse files Browse the repository at this point in the history
  • Loading branch information
polina-c authored Oct 19, 2023
1 parent f0ee3c2 commit f31dd27
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,28 @@ class MemoryFeatureControllers {
DiffPaneController? diffPaneController,
ProfilePaneController? profilePaneController,
) {
diff = diffPaneController ?? DiffPaneController(SnapshotTaker());
memoryTimeline = MemoryTimeline();
diff =
diffPaneController ?? DiffPaneController(SnapshotTaker(memoryTimeline));
profile = profilePaneController ?? ProfilePaneController();
}

late DiffPaneController diff;
late ProfilePaneController profile;
late MemoryTimeline memoryTimeline;
TracingPaneController tracing = TracingPaneController();

void reset() {
diff.dispose();
diff = DiffPaneController(SnapshotTaker());
diff = DiffPaneController(SnapshotTaker(memoryTimeline));

profile.dispose();
profile = ProfilePaneController();

tracing.dispose();
tracing = TracingPaneController();

memoryTimeline.reset();
}

void dispose() {
Expand All @@ -65,8 +70,6 @@ class MemoryController extends DisposableController
DiffPaneController? diffPaneController,
ProfilePaneController? profilePaneController,
}) {
memoryTimeline = MemoryTimeline();

controllers = MemoryFeatureControllers(
diffPaneController,
profilePaneController,
Expand All @@ -87,8 +90,6 @@ class MemoryController extends DisposableController
final _shouldShowLeaksTab = ValueNotifier<bool>(false);
ValueListenable<bool> get shouldShowLeaksTab => _shouldShowLeaksTab;

late MemoryTimeline memoryTimeline;

HeapSample? _selectedDartSample;

HeapSample? _selectedAndroidSample;
Expand Down Expand Up @@ -198,14 +199,14 @@ class MemoryController extends DisposableController
// TODO(terry): Display events enabled in a settings page for now only these events.
switch (extensionEventKind) {
case 'Flutter.ImageSizesForFrame':
memoryTimeline.addExtensionEvent(
controllers.memoryTimeline.addExtensionEvent(
event.timestamp,
event.extensionKind,
jsonData,
);
break;
case MemoryTimeline.devToolsExtensionEvent:
memoryTimeline.addExtensionEvent(
controllers.memoryTimeline.addExtensionEvent(
event.timestamp,
MemoryTimeline.customDevToolsEvent,
jsonData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class MemoryTracker {
// Removes any isolate that is a sentinel.
isolateHeaps.removeWhere((key, value) => keysToRemove.contains(key));

final memoryTimeline = memoryController.memoryTimeline;
final memoryTimeline = memoryController.controllers.memoryTimeline;

int time = DateTime.now().millisecondsSinceEpoch;
if (memoryTimeline.data.isNotEmpty) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class _ChartControlPaneState extends State<ChartControlPane>
void _clearTimeline() {
ga.select(gac.memory, gac.clear);

controller.memoryTimeline.reset();
controller.controllers.memoryTimeline.reset();

// Remove history of all plotted data in all charts.
widget.chartController.resetAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ class AndroidChartController extends ChartController {
// have been toggled to be displayed - yet.
if (traces.isNotEmpty) {
final chartDataLength = timestampsLength;
final dataLength = _memoryController.memoryTimeline.data.length;
final dataLength =
_memoryController.controllers.memoryTimeline.data.length;

final dataRange = _memoryController.memoryTimeline.data.getRange(
final dataRange =
_memoryController.controllers.memoryTimeline.data.getRange(
chartDataLength,
dataLength,
);
Expand Down Expand Up @@ -143,7 +145,7 @@ class MemoryAndroidChartState extends State<MemoryAndroidChart>
/// Controller attached to the chart.
AndroidChartController get _chartController => widget.chartController;

MemoryTimeline get _memoryTimeline => controller.memoryTimeline;
MemoryTimeline get _memoryTimeline => controller.controllers.memoryTimeline;

@override
void initState() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ class ChartsValues {

void _getEventData(Map<String, Object> results) {
// Use the detailed extension events data stored in the memoryTimeline.
final eventInfo = controller.memoryTimeline.data[index].memoryEventInfo;
final eventInfo =
controller.controllers.memoryTimeline.data[index].memoryEventInfo;

if (eventInfo.isEmpty) return;

Expand Down Expand Up @@ -221,7 +222,8 @@ class ChartsValues {
}

void _getVMData(Map<String, Object> results) {
final HeapSample heapSample = controller.memoryTimeline.data[index];
final HeapSample heapSample =
controller.controllers.memoryTimeline.data[index];

results[rssJsonName] = heapSample.rss;
results[capacityJsonName] = heapSample.capacity;
Expand All @@ -234,7 +236,7 @@ class ChartsValues {

void _getAndroidData(Map<String, Object> results) {
final AdbMemoryInfo androidData =
controller.memoryTimeline.data[index].adbMemoryInfo;
controller.controllers.memoryTimeline.data[index].adbMemoryInfo;

results[adbTotalJsonName] = androidData.total;
results[adbOtherJsonName] = androidData.other;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ class EventChartController extends ChartController {
@override
void setupData() {
final chartDataLength = timestampsLength;
final dataLength = _memoryController.memoryTimeline.data.length;
final dataLength = _memoryController.controllers.memoryTimeline.data.length;

final dataRange = _memoryController.memoryTimeline.data.getRange(
final dataRange =
_memoryController.controllers.memoryTimeline.data.getRange(
chartDataLength,
dataLength,
);
Expand Down Expand Up @@ -184,7 +185,7 @@ class MemoryEventsPaneState extends State<MemoryEventsPane>
/// VM's GCs are displayed in a smaller glyph and closer to the heap graph.
static const visibleVmEvent = 0.4;

MemoryTimeline get _memoryTimeline => controller.memoryTimeline;
MemoryTimeline get _memoryTimeline => controller.controllers.memoryTimeline;

@override
void initState() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ class VMChartController extends ChartController {
@override
void setupData() {
final chartDataLength = timestampsLength;
final dataLength = _memoryController.memoryTimeline.data.length;
final dataLength = _memoryController.controllers.memoryTimeline.data.length;

final dataRange = _memoryController.memoryTimeline.data.getRange(
final dataRange =
_memoryController.controllers.memoryTimeline.data.getRange(
chartDataLength,
dataLength,
);
Expand Down Expand Up @@ -107,7 +108,7 @@ class MemoryVMChartState extends State<MemoryVMChart>
/// Controller attached to the chart.
VMChartController get _chartController => widget.chartController;

MemoryTimeline get _memoryTimeline => controller.memoryTimeline;
MemoryTimeline get _memoryTimeline => controller.controllers.memoryTimeline;

@override
void initState() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class SecondaryControls extends StatelessWidget {
}

Future<void> _gc() async {
controller.memoryTimeline.addGCEvent();
controller.controllers.memoryTimeline.addGCEvent();
await controller.gc();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import '../../../../shared/analytics/metrics.dart';
import '../../../../shared/memory/adapted_heap_data.dart';
import '../../../../shared/memory/class_name.dart';
import '../../../../shared/primitives/utils.dart';
import '../primitives/memory_timeline.dart';
import '../primitives/memory_utils.dart';

/// Heap path represented by classes only, without object details.
Expand Down Expand Up @@ -106,8 +107,13 @@ class ClassOnlyHeapPath {

/// This class is needed to make the snapshot taking operation mockable.
class SnapshotTaker {
SnapshotTaker(this._timeline);

final MemoryTimeline? _timeline;

Future<AdaptedHeapData?> take() async {
final snapshot = await snapshotMemoryInSelectedIsolate();
_timeline?.addSnapshotEvent();
if (snapshot == null) return null;
final result =
await _adaptSnapshotGaWrapper(snapshot, isolateId: selectedIsolateId!);
Expand Down
10 changes: 8 additions & 2 deletions packages/devtools_app/test/memory/memory_screen_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,14 @@ void main() {

expect(find.byType(MemoryVMChart), findsOneWidget);

expect(controller.memoryTimeline.liveData.isEmpty, isTrue);
expect(controller.memoryTimeline.offlineData.isEmpty, isTrue);
expect(
controller.controllers.memoryTimeline.liveData.isEmpty,
isTrue,
);
expect(
controller.controllers.memoryTimeline.offlineData.isEmpty,
isTrue,
);
},
);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/devtools_app/test/memory/memory_service_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void main() {
// VM Service connection has stopped - unexpected.
fail('VM Service connection stoped unexpectantly.');
} else {
validateHeapInfo(memoryController.memoryTimeline);
validateHeapInfo(memoryController.controllers.memoryTimeline);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ class MemoryDefaultScene extends Scene {
profilePaneController: profileController,
)
..offline = true
..memoryTimeline.offlineData.clear()
..memoryTimeline.offlineData.addAll(memoryJson.data);
..controllers.memoryTimeline.offlineData.clear()
..controllers.memoryTimeline.offlineData.addAll(memoryJson.data);
}

@override
Expand Down

0 comments on commit f31dd27

Please sign in to comment.