diff --git a/packages/devtools_app/lib/src/screens/memory/panes/chart/controller/charts/vm_chart_controller.dart b/packages/devtools_app/lib/src/screens/memory/panes/chart/controller/charts/vm_chart_controller.dart index 62f8c2bd632..0ce1471e1de 100644 --- a/packages/devtools_app/lib/src/screens/memory/panes/chart/controller/charts/vm_chart_controller.dart +++ b/packages/devtools_app/lib/src/screens/memory/panes/chart/controller/charts/vm_chart_controller.dart @@ -4,9 +4,12 @@ import 'package:devtools_shared/devtools_shared.dart'; import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; import '../../../../../../shared/charts/chart_controller.dart'; import '../../../../../../shared/charts/chart_trace.dart' as chart_trace; +import '../../../../../../shared/charts/chart_trace.dart' + show ChartType, ChartSymbol; import '../../../../shared/primitives/memory_timeline.dart'; import '../../data/charts.dart'; @@ -77,4 +80,148 @@ class VMChartController extends ChartController { chart_trace.Data(timestamp, rasterPictureValue), ); } + + // TODO(terry): Move colors to theme? + static final capacityColor = Colors.grey[400]!; + static const usedColor = Color(0xff33b5e5); + static const externalColor = Color(0xff4ddeff); + // TODO(terry): UX review of raster colors see https://github.com/flutter/devtools/issues/2616 + final rasterLayerColor = Colors.greenAccent.shade400; + static const rasterPictureColor = Color(0xffff4444); + final rssColor = Colors.orange.shade700; + + void setupTraces() { + if (traces.isNotEmpty) { + assert(traces.length == VmTraceName.values.length); + + final externalIndex = VmTraceName.external.index; + assert( + trace(externalIndex).name == + VmTraceName.values[externalIndex].toString(), + ); + + final usedIndex = VmTraceName.used.index; + assert( + trace(usedIndex).name == VmTraceName.values[usedIndex].toString(), + ); + + final capacityIndex = VmTraceName.capacity.index; + assert( + trace(capacityIndex).name == + VmTraceName.values[capacityIndex].toString(), + ); + + final rSSIndex = VmTraceName.rSS.index; + assert( + trace(rSSIndex).name == VmTraceName.values[rSSIndex].toString(), + ); + + final rasterLayerIndex = VmTraceName.rasterLayer.index; + assert( + trace(rasterLayerIndex).name == + VmTraceName.values[rasterLayerIndex].toString(), + ); + + final rasterPictureIndex = VmTraceName.rasterPicture.index; + assert( + trace(rasterPictureIndex).name == + VmTraceName.values[rasterPictureIndex].toString(), + ); + + return; + } + + final externalIndex = createTrace( + ChartType.line, + chart_trace.PaintCharacteristics( + color: externalColor, + symbol: chart_trace.ChartSymbol.disc, + diameter: 1.5, + ), + stacked: true, + name: VmTraceName.external.toString(), + ); + assert(externalIndex == VmTraceName.external.index); + assert( + trace(externalIndex).name == VmTraceName.values[externalIndex].toString(), + ); + + // Used Heap + final usedIndex = createTrace( + ChartType.line, + chart_trace.PaintCharacteristics( + color: usedColor, + symbol: chart_trace.ChartSymbol.disc, + diameter: 1.5, + ), + stacked: true, + name: VmTraceName.used.toString(), + ); + assert(usedIndex == VmTraceName.used.index); + assert( + trace(usedIndex).name == VmTraceName.values[usedIndex].toString(), + ); + + // Heap Capacity + final capacityIndex = createTrace( + ChartType.line, + chart_trace.PaintCharacteristics( + color: capacityColor, + diameter: 0.0, + symbol: ChartSymbol.dashedLine, + ), + name: VmTraceName.capacity.toString(), + ); + assert(capacityIndex == VmTraceName.capacity.index); + assert( + trace(capacityIndex).name == VmTraceName.values[capacityIndex].toString(), + ); + + // RSS + final rSSIndex = createTrace( + ChartType.line, + chart_trace.PaintCharacteristics( + color: rssColor, + symbol: ChartSymbol.dashedLine, + strokeWidth: 2, + ), + name: VmTraceName.rSS.toString(), + ); + assert(rSSIndex == VmTraceName.rSS.index); + assert( + trace(rSSIndex).name == VmTraceName.values[rSSIndex].toString(), + ); + + final rasterLayerIndex = createTrace( + chart_trace.ChartType.line, + chart_trace.PaintCharacteristics( + color: rasterLayerColor, + symbol: chart_trace.ChartSymbol.dashedLine, + strokeWidth: 2, + ), + name: VmTraceName.rasterLayer.toString(), + ); + assert(rasterLayerIndex == VmTraceName.rasterLayer.index); + assert( + trace(rasterLayerIndex).name == + VmTraceName.values[rasterLayerIndex].toString(), + ); + + final rasterPictureIndex = createTrace( + chart_trace.ChartType.line, + chart_trace.PaintCharacteristics( + color: rasterPictureColor, + symbol: chart_trace.ChartSymbol.dashedLine, + strokeWidth: 2, + ), + name: VmTraceName.rasterPicture.toString(), + ); + assert(rasterPictureIndex == VmTraceName.rasterPicture.index); + assert( + trace(rasterPictureIndex).name == + VmTraceName.values[rasterPictureIndex].toString(), + ); + + assert(traces.length == VmTraceName.values.length); + } } diff --git a/packages/devtools_app/lib/src/screens/memory/panes/chart/widgets/charts/vm_chart.dart b/packages/devtools_app/lib/src/screens/memory/panes/chart/widgets/charts/vm_chart.dart index a65de90521a..6360c5d0462 100644 --- a/packages/devtools_app/lib/src/screens/memory/panes/chart/widgets/charts/vm_chart.dart +++ b/packages/devtools_app/lib/src/screens/memory/panes/chart/widgets/charts/vm_chart.dart @@ -8,12 +8,8 @@ import 'package:devtools_shared/devtools_shared.dart'; import 'package:flutter/material.dart'; import '../../../../../../shared/charts/chart.dart'; -import '../../../../../../shared/charts/chart_trace.dart' as trace; -import '../../../../../../shared/charts/chart_trace.dart' - show ChartType, ChartSymbol; import '../../../../shared/primitives/memory_timeline.dart'; import '../../controller/charts/vm_chart_controller.dart'; -import '../../data/charts.dart'; class MemoryVMChart extends StatefulWidget { const MemoryVMChart(this.chart, {super.key}); @@ -40,7 +36,7 @@ class MemoryVMChartState extends State with AutoDisposeMixin { void _init() { cancelListeners(); - setupTraces(); + widget.chart.setupTraces(); _chartController.setupData(); addAutoDisposeListener(_memoryTimeline.sampleAddedNotifier, () { @@ -71,156 +67,6 @@ class MemoryVMChartState extends State with AutoDisposeMixin { return const SizedBox(width: denseSpacing); } - // TODO(terry): Move colors to theme? - static final capacityColor = Colors.grey[400]!; - static const usedColor = Color(0xff33b5e5); - static const externalColor = Color(0xff4ddeff); - // TODO(terry): UX review of raster colors see https://github.com/flutter/devtools/issues/2616 - final rasterLayerColor = Colors.greenAccent.shade400; - static const rasterPictureColor = Color(0xffff4444); - final rssColor = Colors.orange.shade700; - - void setupTraces() { - if (_chartController.traces.isNotEmpty) { - assert(_chartController.traces.length == VmTraceName.values.length); - - final externalIndex = VmTraceName.external.index; - assert( - _chartController.trace(externalIndex).name == - VmTraceName.values[externalIndex].toString(), - ); - - final usedIndex = VmTraceName.used.index; - assert( - _chartController.trace(usedIndex).name == - VmTraceName.values[usedIndex].toString(), - ); - - final capacityIndex = VmTraceName.capacity.index; - assert( - _chartController.trace(capacityIndex).name == - VmTraceName.values[capacityIndex].toString(), - ); - - final rSSIndex = VmTraceName.rSS.index; - assert( - _chartController.trace(rSSIndex).name == - VmTraceName.values[rSSIndex].toString(), - ); - - final rasterLayerIndex = VmTraceName.rasterLayer.index; - assert( - _chartController.trace(rasterLayerIndex).name == - VmTraceName.values[rasterLayerIndex].toString(), - ); - - final rasterPictureIndex = VmTraceName.rasterPicture.index; - assert( - _chartController.trace(rasterPictureIndex).name == - VmTraceName.values[rasterPictureIndex].toString(), - ); - - return; - } - - final externalIndex = _chartController.createTrace( - ChartType.line, - trace.PaintCharacteristics( - color: externalColor, - symbol: trace.ChartSymbol.disc, - diameter: 1.5, - ), - stacked: true, - name: VmTraceName.external.toString(), - ); - assert(externalIndex == VmTraceName.external.index); - assert( - _chartController.trace(externalIndex).name == - VmTraceName.values[externalIndex].toString(), - ); - - // Used Heap - final usedIndex = _chartController.createTrace( - ChartType.line, - trace.PaintCharacteristics( - color: usedColor, - symbol: trace.ChartSymbol.disc, - diameter: 1.5, - ), - stacked: true, - name: VmTraceName.used.toString(), - ); - assert(usedIndex == VmTraceName.used.index); - assert( - _chartController.trace(usedIndex).name == - VmTraceName.values[usedIndex].toString(), - ); - - // Heap Capacity - final capacityIndex = _chartController.createTrace( - ChartType.line, - trace.PaintCharacteristics( - color: capacityColor, - diameter: 0.0, - symbol: ChartSymbol.dashedLine, - ), - name: VmTraceName.capacity.toString(), - ); - assert(capacityIndex == VmTraceName.capacity.index); - assert( - _chartController.trace(capacityIndex).name == - VmTraceName.values[capacityIndex].toString(), - ); - - // RSS - final rSSIndex = _chartController.createTrace( - ChartType.line, - trace.PaintCharacteristics( - color: rssColor, - symbol: ChartSymbol.dashedLine, - strokeWidth: 2, - ), - name: VmTraceName.rSS.toString(), - ); - assert(rSSIndex == VmTraceName.rSS.index); - assert( - _chartController.trace(rSSIndex).name == - VmTraceName.values[rSSIndex].toString(), - ); - - final rasterLayerIndex = _chartController.createTrace( - trace.ChartType.line, - trace.PaintCharacteristics( - color: rasterLayerColor, - symbol: trace.ChartSymbol.dashedLine, - strokeWidth: 2, - ), - name: VmTraceName.rasterLayer.toString(), - ); - assert(rasterLayerIndex == VmTraceName.rasterLayer.index); - assert( - _chartController.trace(rasterLayerIndex).name == - VmTraceName.values[rasterLayerIndex].toString(), - ); - - final rasterPictureIndex = _chartController.createTrace( - trace.ChartType.line, - trace.PaintCharacteristics( - color: rasterPictureColor, - symbol: trace.ChartSymbol.dashedLine, - strokeWidth: 2, - ), - name: VmTraceName.rasterPicture.toString(), - ); - assert(rasterPictureIndex == VmTraceName.rasterPicture.index); - assert( - _chartController.trace(rasterPictureIndex).name == - VmTraceName.values[rasterPictureIndex].toString(), - ); - - assert(_chartController.traces.length == VmTraceName.values.length); - } - /// Loads all heap samples (live data or offline). void _processHeapSample(HeapSample sample) { // If paused don't update the chart (data is still collected). diff --git a/packages/devtools_app/macos/Runner/AppDelegate.swift b/packages/devtools_app/macos/Runner/AppDelegate.swift index d53ef643772..8e02df28883 100644 --- a/packages/devtools_app/macos/Runner/AppDelegate.swift +++ b/packages/devtools_app/macos/Runner/AppDelegate.swift @@ -1,7 +1,7 @@ import Cocoa import FlutterMacOS -@NSApplicationMain +@main class AppDelegate: FlutterAppDelegate { override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { return true