Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
polina-c committed Apr 27, 2024
1 parent e91c289 commit 983fa7b
Show file tree
Hide file tree
Showing 14 changed files with 84 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ class OfflineMemoryData {
Map<String, dynamic> toJson() {
return {
_Json.selectedTab: selectedTab,
_Json.diffData: diff.toJson(),
_Json.profileData: profile.toJson(),
_Json.chartData: chart.toJson(),
_Json.classFilter: profile.classFilter.value.toJson(),
_Json.diffData: diff,
_Json.profileData: profile,
_Json.chartData: chart,
_Json.classFilter: profile.classFilter.value,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class ChartData {
Map<String, dynamic> toJson() {
return {
_Json.isDeviceAndroid: isDeviceAndroid ?? false,
_Json.timeline: timeline.toJson(),
_Json.timeline: timeline,
_Json.interval: displayInterval.name,
_Json.isLegendVisible: isLegendVisible.value,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,50 @@ import '../data/csv.dart';
import '../data/heap_diff_data.dart';
import '../data/heap_diff_store.dart';
import 'class_data.dart';
import 'item_controller.dart';
import 'snapshot_item.dart';

class _Json {
static const snapshots = 'snapshots';
static const diffWith = 'diffWith';
}

class DiffPaneController extends DisposableController {
DiffPaneController({required this.loader});
DiffPaneController({
required this.loader,
List<SnapshotDataItem>? snapshots,
}) {
if (snapshots != null) {
core._snapshots.value.addAll(snapshots);
}
derived._updateValues();
}

factory DiffPaneController.fromJson(Map<String, dynamic> json) {
// TODO(polina-c): implement, https://github.com/flutter/devtools/issues/6972
return DiffPaneController(loader: null);
final snapshots = (json[_Json.snapshots] as List)
.map((e) => SnapshotDataItem.fromJson(e))
.toList();
return DiffPaneController(
loader: null,
//snapshots: snapshots,
);
}

Map<String, dynamic> toJson() {
// TODO(polina-c): implement, https://github.com/flutter/devtools/issues/6972
return {};
final snapshots =
core.snapshots.value.whereType<SnapshotDataItem>().toList();

final snapshotToIndex =
snapshots.asMap().map((index, item) => MapEntry(item, index));

final diffsWith = snapshots.map((item) {
final diffWith = item.diffWith.value;
return diffWith == null ? null : snapshotToIndex[diffWith];
}).toList();

return {
_Json.snapshots: snapshots,
_Json.diffWith: diffsWith,
};
}

final HeapGraphLoader? loader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ class SnapshotDocItem extends SnapshotItem {
bool get hasData => false;
}

class _Json {
static const defaultName = 'defaultName';
static const displayNumber = 'displayNumber';
static const snapshot = 'snapshot';
static const nameOverride = 'nameOverride';
static const diffWith = 'diffWith';
}

class SnapshotDataItem extends SnapshotItem implements RenamableItem {
SnapshotDataItem({
this.displayNumber,
Expand All @@ -41,6 +49,14 @@ class SnapshotDataItem extends SnapshotItem implements RenamableItem {
_isProcessing.value = true;
}

factory SnapshotDataItem.fromJson(Map<String, dynamic> json) {
throw UnimplementedError();
}

Map<String, dynamic> toJson() {
return {};
}

HeapData? get heap => _heap;
HeapData? _heap;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import '../../../../shared/globals.dart';
import '../../../../shared/primitives/simple_items.dart';
import '../../shared/widgets/shared_memory_widgets.dart';
import 'controller/diff_pane_controller.dart';
import 'controller/item_controller.dart';
import 'controller/snapshot_item.dart';
import 'widgets/snapshot_control_pane.dart';
import 'widgets/snapshot_list.dart';
import 'widgets/snapshot_view.dart';
Expand Down Expand Up @@ -154,9 +154,9 @@ Find unexpected memory usage by comparing two heap snapshots:
2. Use one of the following ways to get a **heap snapshot**:
a. To view current memory allocation click the ● button
a. To take snapshot of the connected application click the ● button
b. To import a snapshot taken with
b. To import a snapshot exported from DevTools or taken with
[auto-snapshotting](https://github.com/dart-lang/leak_tracker/blob/main/doc/USAGE.md) or
[writeHeapSnapshotToFile](https://api.flutter.dev/flutter/dart-developer/NativeRuntime/writeHeapSnapshotToFile.html)
click the ![import]($uploadImageUrl) button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import '../../../../../shared/memory/simple_items.dart';
import '../../../../../shared/primitives/byte_utils.dart';
import '../../../shared/primitives/simple_elements.dart';
import '../controller/diff_pane_controller.dart';
import '../controller/item_controller.dart';
import '../controller/snapshot_item.dart';

class SnapshotControlPane extends StatelessWidget {
const SnapshotControlPane({super.key, required this.controller});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import '../../../../../shared/dialogs.dart';
import '../../../../../shared/primitives/byte_utils.dart';
import '../../../../../shared/primitives/utils.dart';
import '../controller/diff_pane_controller.dart';
import '../controller/item_controller.dart';
import '../controller/snapshot_item.dart';

final _log = Logger('snapshot_list');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import '../../../../../shared/common_widgets.dart';
import '../../../../../shared/memory/classes.dart';
import '../../../../../shared/primitives/utils.dart';
import '../controller/diff_pane_controller.dart';
import '../controller/item_controller.dart';
import '../controller/snapshot_item.dart';
import '../data/classes_diff.dart';
import 'class_details/class_details.dart';
import 'classes_table_diff.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ class AdaptedProfile {

Map<String, dynamic> toJson() {
return {
_ProfileJson.total: _total.toJson(),
_ProfileJson.items: _items.map((e) => e.toJson()).toList(),
_ProfileJson.newGC: newSpaceGCStats.toJson(),
_ProfileJson.oldGC: oldSpaceGCStats.toJson(),
_ProfileJson.totalGC: totalGCStats.toJson(),
_ProfileJson.total: _total,
_ProfileJson.items: _items,
_ProfileJson.newGC: newSpaceGCStats,
_ProfileJson.oldGC: oldSpaceGCStats,
_ProfileJson.totalGC: totalGCStats,
};
}

Expand Down Expand Up @@ -221,7 +221,7 @@ class ProfileRecord with PinnableListEntry {
Map<String, dynamic> toJson() {
return {
_RecordJson.isTotal: isTotal,
_RecordJson.heapClass: heapClass.toJson(),
_RecordJson.heapClass: heapClass,
_RecordJson.totalInstances: totalInstances,
_RecordJson.totalSize: totalSize,
_RecordJson.totalDartHeapSize: totalDartHeapSize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ProfilePaneController extends DisposableController

Map<String, dynamic> toJson() {
return {
_jsonProfile: _currentAllocationProfile.value?.toJson(),
_jsonProfile: _currentAllocationProfile.value,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class MemoryTimeline {

Map<String, dynamic> toJson() {
return {
_jsonData: data.map((e) => e.toJson()).toList(),
_jsonData: data,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:devtools_app/src/screens/memory/panes/diff/controller/item_controller.dart';
import 'package:devtools_app/src/screens/memory/panes/diff/controller/snapshot_item.dart';
import 'package:devtools_app/src/screens/memory/panes/diff/diff_pane.dart';
import 'package:devtools_app/src/screens/memory/shared/heap/class_filter.dart';
import 'package:devtools_app/src/screens/memory/shared/widgets/class_filter.dart';
Expand Down
16 changes: 8 additions & 8 deletions packages/devtools_shared/lib/src/memory/event_sample.dart
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,6 @@ class ExtensionEvents {
return ExtensionEvents(events);
}

final theEvents = <ExtensionEvent>[];

bool get isEmpty => theEvents.isEmpty;

bool get isNotEmpty => theEvents.isNotEmpty;

void clear() => theEvents.clear();

Map<String, dynamic> toJson() {
final eventsAsJson = <String, dynamic>{};
var index = 0;
Expand All @@ -148,6 +140,14 @@ class ExtensionEvents {
return eventsAsJson;
}

final theEvents = <ExtensionEvent>[];

bool get isEmpty => theEvents.isEmpty;

bool get isNotEmpty => theEvents.isNotEmpty;

void clear() => theEvents.clear();

@override
String toString() => '[ExtensionEvents = '
'${const JsonEncoder.withIndent(' ').convert(toJson())}]';
Expand Down
6 changes: 3 additions & 3 deletions packages/devtools_shared/lib/src/memory/heap_sample.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ class HeapSample {
'used': used,
'external': external,
'gc': isGC,
'adb_memoryInfo': adbMemoryInfo.toJson(),
'memory_eventInfo': memoryEventInfo.toJson(),
'raster_cache': rasterCache.toJson(),
'adb_memoryInfo': adbMemoryInfo,
'memory_eventInfo': memoryEventInfo,
'raster_cache': rasterCache,
};

/// Version of HeapSample JSON payload.
Expand Down

0 comments on commit 983fa7b

Please sign in to comment.