Skip to content

Commit 2f4301e

Browse files
Do not await service extension call in the performance screen (#9162)
1 parent 4b7eda1 commit 2f4301e

File tree

4 files changed

+56
-34
lines changed

4 files changed

+56
-34
lines changed

packages/devtools_app/lib/src/screens/performance/panes/flutter_frames/flutter_frames_chart.dart

+37-26
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'dart:math' as math;
77

88
import 'package:devtools_app_shared/ui.dart';
99
import 'package:devtools_app_shared/utils.dart';
10+
import 'package:flutter/foundation.dart';
1011
import 'package:flutter/material.dart';
1112

1213
import '../../../../shared/analytics/analytics.dart' as ga;
@@ -39,7 +40,7 @@ class FlutterFramesChart extends StatelessWidget {
3940

4041
final bool showingOfflineData;
4142

42-
final bool impellerEnabled;
43+
final ValueListenable<bool> impellerEnabled;
4344

4445
@override
4546
Widget build(BuildContext context) {
@@ -86,7 +87,7 @@ class _FlutterFramesChart extends StatefulWidget {
8687

8788
final bool showingOfflineData;
8889

89-
final bool impellerEnabled;
90+
final ValueListenable<bool> impellerEnabled;
9091

9192
static double get frameNumberSectionHeight => scaleByFontFactor(20.0);
9293

@@ -203,7 +204,7 @@ class FramesChart extends StatefulWidget {
203204

204205
final BoxConstraints constraints;
205206

206-
final bool impellerEnabled;
207+
final ValueListenable<bool> impellerEnabled;
207208

208209
@override
209210
State<FramesChart> createState() => _FramesChartState();
@@ -346,13 +347,18 @@ class _FramesChartState extends State<FramesChart> with AutoDisposeMixin {
346347
chartAxisPainter,
347348
Padding(padding: EdgeInsets.only(left: _yAxisUnitsSpace), child: chart),
348349
fpsLinePainter,
349-
Positioned(
350-
right: denseSpacing,
351-
top: densePadding,
352-
child: Text(
353-
'Engine: ${widget.impellerEnabled ? 'Impeller' : 'Skia'}',
354-
style: themeData.subtleChartTextStyle,
355-
),
350+
ValueListenableBuilder(
351+
valueListenable: widget.impellerEnabled,
352+
builder: (context, impellerEnabled, child) {
353+
return Positioned(
354+
right: denseSpacing,
355+
top: densePadding,
356+
child: Text(
357+
'Engine: ${impellerEnabled ? 'Impeller' : 'Skia'}',
358+
style: themeData.subtleChartTextStyle,
359+
),
360+
);
361+
},
356362
),
357363
],
358364
);
@@ -382,7 +388,7 @@ class FramesChartControls extends StatelessWidget {
382388

383389
final bool showingOfflineData;
384390

385-
final bool impellerEnabled;
391+
final ValueListenable<bool> impellerEnabled;
386392

387393
@override
388394
Widget build(BuildContext context) {
@@ -408,21 +414,26 @@ class FramesChartControls extends StatelessWidget {
408414
);
409415
},
410416
),
411-
Legend(
412-
dense: true,
413-
entries: [
414-
LegendEntry(terse ? 'UI' : 'Frame Time (UI)', mainUiColor),
415-
LegendEntry(
416-
terse ? 'Raster' : 'Frame Time (Raster)',
417-
mainRasterColor,
418-
),
419-
LegendEntry(terse ? 'Jank' : 'Jank (slow frame)', uiJankColor),
420-
if (!impellerEnabled)
421-
LegendEntry(
422-
'Shader Compilation',
423-
shaderCompilationColor.background,
424-
),
425-
],
417+
ValueListenableBuilder(
418+
valueListenable: impellerEnabled,
419+
builder: (context, impellerEnabled, child) {
420+
return Legend(
421+
dense: true,
422+
entries: [
423+
LegendEntry(terse ? 'UI' : 'Frame Time (UI)', mainUiColor),
424+
LegendEntry(
425+
terse ? 'Raster' : 'Frame Time (Raster)',
426+
mainRasterColor,
427+
),
428+
LegendEntry(terse ? 'Jank' : 'Jank (slow frame)', uiJankColor),
429+
if (!impellerEnabled)
430+
LegendEntry(
431+
'Shader Compilation',
432+
shaderCompilationColor.background,
433+
),
434+
],
435+
);
436+
},
426437
),
427438
AverageFPS(
428439
frames: frames,

packages/devtools_app/lib/src/screens/performance/performance_controller.dart

+16-6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'dart:async';
99

1010
import 'package:devtools_app_shared/service.dart';
1111
import 'package:devtools_app_shared/utils.dart';
12+
import 'package:flutter/foundation.dart';
1213
import 'package:vm_service/vm_service.dart';
1314

1415
import '../../service/service_registrations.dart' as registrations;
@@ -83,8 +84,8 @@ class PerformanceController extends DevToolsScreenController
8384
/// any selection modifications that occur while the data is displayed.
8485
OfflinePerformanceData? offlinePerformanceData;
8586

86-
bool get impellerEnabled => _impellerEnabled;
87-
bool _impellerEnabled = false;
87+
ValueListenable<bool> get impellerEnabled => _impellerEnabled;
88+
final _impellerEnabled = ValueNotifier<bool>(false);
8889

8990
Future<void> get initialized => _initialized.future;
9091
final _initialized = Completer<void>();
@@ -124,11 +125,19 @@ class PerformanceController extends DevToolsScreenController
124125

125126
if (serviceConnection.serviceManager.connectedApp?.isFlutterAppNow ??
126127
false) {
127-
final impellerEnabledResponse = await serviceConnection.serviceManager
128-
.callServiceExtensionOnMainIsolate(registrations.isImpellerEnabled);
129-
_impellerEnabled = impellerEnabledResponse.json?['enabled'] == true;
128+
// Do not await this future because this will hang if the app is paused
129+
// upon connection.
130+
unawaited(
131+
serviceConnection.serviceManager
132+
.callServiceExtensionOnMainIsolate(
133+
registrations.isImpellerEnabled,
134+
)
135+
.then((response) {
136+
_impellerEnabled.value = response.json?['enabled'] == true;
137+
}),
138+
);
130139
} else {
131-
_impellerEnabled = false;
140+
_impellerEnabled.value = false;
132141
}
133142

134143
enhanceTracingController.init();
@@ -264,6 +273,7 @@ class PerformanceController extends DevToolsScreenController
264273
_applyToFeatureControllers((c) => c.dispose());
265274
enhanceTracingController.dispose();
266275
rebuildCountModel.dispose();
276+
_impellerEnabled.dispose();
267277
super.dispose();
268278
}
269279

packages/devtools_app/release_notes/NEXT_RELEASE_NOTES.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ TODO: Remove this section if there are not any general updates.
2525

2626
## Performance updates
2727

28-
TODO: Remove this section if there are not any general updates.
28+
- Fixes a bug where the Performance page would hang when connected to a paused
29+
Flutter app. - [#9162](https://github.com/flutter/devtools/pull/9162)
2930

3031
## CPU profiler updates
3132

packages/devtools_app/test/screens/performance/flutter_frames/flutter_frames_chart_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void main() {
2929
FlutterFramesChart(
3030
framesController,
3131
showingOfflineData: showingOfflineData,
32-
impellerEnabled: impellerEnabled,
32+
impellerEnabled: FixedValueListenable(impellerEnabled),
3333
),
3434
),
3535
);

0 commit comments

Comments
 (0)