Unverified Commit 820fb0bf authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] stop using throttled print for service extensions (#76022)

parent f8cd24de
...@@ -111,11 +111,13 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture ...@@ -111,11 +111,13 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture
return _forceRepaint(); return _forceRepaint();
}, },
); );
registerSignalServiceExtension( registerServiceExtension(
name: 'debugDumpLayerTree', name: 'debugDumpLayerTree',
callback: () { callback: (Map<String, String> parameters) async {
debugDumpLayerTree(); final String data = RendererBinding.instance?.renderView.debugLayer?.toStringDeep() ?? 'Layer tree unavailable.';
return debugPrintDone; return <String, Object>{
'data': data,
};
}, },
); );
return true; return true;
...@@ -123,27 +125,35 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture ...@@ -123,27 +125,35 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture
if (!kReleaseMode) { if (!kReleaseMode) {
// these service extensions work in debug or profile mode // these service extensions work in debug or profile mode
registerSignalServiceExtension( registerServiceExtension(
name: 'debugDumpRenderTree', name: 'debugDumpRenderTree',
callback: () { callback: (Map<String, String> parameters) async {
debugDumpRenderTree(); final String data = RendererBinding.instance?.renderView.toStringDeep() ?? 'Render tree unavailable.';
return debugPrintDone; return <String, Object>{
}, 'data': data,
};
}
); );
registerSignalServiceExtension( registerServiceExtension(
name: 'debugDumpSemanticsTreeInTraversalOrder', name: 'debugDumpSemanticsTreeInTraversalOrder',
callback: () { callback: (Map<String, String> parameters) async {
debugDumpSemanticsTree(DebugSemanticsDumpOrder.traversalOrder); final String data = RendererBinding.instance?.renderView.debugSemantics
return debugPrintDone; ?.toStringDeep(childOrder: DebugSemanticsDumpOrder.traversalOrder) ?? 'Semantics not collected.';
return <String, Object>{
'data': data,
};
}, },
); );
registerSignalServiceExtension( registerServiceExtension(
name: 'debugDumpSemanticsTreeInInverseHitTestOrder', name: 'debugDumpSemanticsTreeInInverseHitTestOrder',
callback: () { callback: (Map<String, String> parameters) async {
debugDumpSemanticsTree(DebugSemanticsDumpOrder.inverseHitTest); final String data = RendererBinding.instance?.renderView.debugSemantics
return debugPrintDone; ?.toStringDeep(childOrder: DebugSemanticsDumpOrder.inverseHitTest) ?? 'Semantics not collected.';
return <String, Object>{
'data': data,
};
}, },
); );
} }
......
...@@ -11,7 +11,6 @@ import 'package:flutter/semantics.dart'; ...@@ -11,7 +11,6 @@ import 'package:flutter/semantics.dart';
import 'package:vector_math/vector_math_64.dart'; import 'package:vector_math/vector_math_64.dart';
import 'binding.dart';
import 'box.dart'; import 'box.dart';
import 'layer.dart'; import 'layer.dart';
import 'layout_helper.dart'; import 'layout_helper.dart';
......
...@@ -387,11 +387,13 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB ...@@ -387,11 +387,13 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB
super.initServiceExtensions(); super.initServiceExtensions();
if (!kReleaseMode) { if (!kReleaseMode) {
registerSignalServiceExtension( registerServiceExtension(
name: 'debugDumpApp', name: 'debugDumpApp',
callback: () { callback: (Map<String, String> parameters) async {
debugDumpApp(); final String data = _debugDumpAppString();
return debugPrintDone; return <String, Object>{
'data': data,
};
}, },
); );
...@@ -1027,20 +1029,23 @@ void runApp(Widget app) { ...@@ -1027,20 +1029,23 @@ void runApp(Widget app) {
..scheduleWarmUpFrame(); ..scheduleWarmUpFrame();
} }
/// Print a string representation of the currently running app. String _debugDumpAppString() {
void debugDumpApp() {
assert(WidgetsBinding.instance != null); assert(WidgetsBinding.instance != null);
String mode = 'RELEASE MODE'; const String mode = kDebugMode ? 'DEBUG MODE' : 'PROFILE MODE';
assert(() { final StringBuffer buffer = StringBuffer();
mode = 'CHECKED MODE'; buffer.writeln('${WidgetsBinding.instance.runtimeType} - $mode');
return true;
}());
debugPrint('${WidgetsBinding.instance.runtimeType} - $mode');
if (WidgetsBinding.instance!.renderViewElement != null) { if (WidgetsBinding.instance!.renderViewElement != null) {
debugPrint(WidgetsBinding.instance!.renderViewElement!.toStringDeep()); buffer.writeln(WidgetsBinding.instance!.renderViewElement!.toStringDeep());
} else { } else {
debugPrint('<no tree currently mounted>'); buffer.writeln('<no tree currently mounted>');
} }
return buffer.toString();
}
/// Print a string representation of the currently running app.
void debugDumpApp() {
final String value = _debugDumpAppString();
debugPrint(value);
} }
/// A bridge from a [RenderObject] to an [Element] tree. /// A bridge from a [RenderObject] to an [Element] tree.
......
...@@ -226,22 +226,19 @@ void main() { ...@@ -226,22 +226,19 @@ void main() {
}); });
test('Service extensions - debugDumpApp', () async { test('Service extensions - debugDumpApp', () async {
Map<String, dynamic> result; final Map<String, dynamic> result = await binding.testExtension('debugDumpApp', <String, String>{});
result = await binding.testExtension('debugDumpApp', <String, String>{}); expect(result, <String, dynamic>{
expect(result, <String, String>{}); 'data': matches('TestServiceExtensionsBinding - DEBUG MODE\n<no tree currently mounted>'),
expect(console, <String>['TestServiceExtensionsBinding - CHECKED MODE', '<no tree currently mounted>']); });
console.clear();
}); });
test('Service extensions - debugDumpRenderTree', () async { test('Service extensions - debugDumpRenderTree', () async {
Map<String, dynamic> result;
await binding.doFrame(); await binding.doFrame();
result = await binding.testExtension('debugDumpRenderTree', <String, String>{}); final Map<String, dynamic> result = await binding.testExtension('debugDumpRenderTree', <String, String>{});
expect(result, <String, String>{});
expect(console, <Matcher>[ expect(result, <String, dynamic>{
matches( 'data': matches(
r'^' r'^'
r'RenderView#[0-9a-f]{5}\n' r'RenderView#[0-9a-f]{5}\n'
r' debug mode enabled - [a-zA-Z]+\n' r' debug mode enabled - [a-zA-Z]+\n'
...@@ -250,18 +247,15 @@ void main() { ...@@ -250,18 +247,15 @@ void main() {
r' configuration: Size\(800\.0, 600\.0\) at 3\.0x \(in logical pixels\)\n' r' configuration: Size\(800\.0, 600\.0\) at 3\.0x \(in logical pixels\)\n'
r'$' r'$'
), ),
]); });
console.clear();
}); });
test('Service extensions - debugDumpLayerTree', () async { test('Service extensions - debugDumpLayerTree', () async {
Map<String, dynamic> result;
await binding.doFrame(); await binding.doFrame();
result = await binding.testExtension('debugDumpLayerTree', <String, String>{}); final Map<String, dynamic> result = await binding.testExtension('debugDumpLayerTree', <String, String>{});
expect(result, <String, String>{});
expect(console, <Matcher>[ expect(result, <String, dynamic>{
matches( 'data': matches(
r'^' r'^'
r'TransformLayer#[0-9a-f]{5}\n' r'TransformLayer#[0-9a-f]{5}\n'
r' owner: RenderView#[0-9a-f]{5}\n' r' owner: RenderView#[0-9a-f]{5}\n'
...@@ -275,28 +269,25 @@ void main() { ...@@ -275,28 +269,25 @@ void main() {
r' \[3] 0\.0,0\.0,0\.0,1\.0\n' r' \[3] 0\.0,0\.0,0\.0,1\.0\n'
r'$' r'$'
), ),
]); });
console.clear();
}); });
test('Service extensions - debugDumpSemanticsTreeInTraversalOrder', () async { test('Service extensions - debugDumpSemanticsTreeInTraversalOrder', () async {
Map<String, dynamic> result;
await binding.doFrame(); await binding.doFrame();
result = await binding.testExtension('debugDumpSemanticsTreeInTraversalOrder', <String, String>{}); final Map<String, dynamic> result = await binding.testExtension('debugDumpSemanticsTreeInTraversalOrder', <String, String>{});
expect(result, <String, String>{});
expect(console, <String>['Semantics not collected.']); expect(result, <String, String>{
console.clear(); 'data': 'Semantics not collected.'
});
}); });
test('Service extensions - debugDumpSemanticsTreeInInverseHitTestOrder', () async { test('Service extensions - debugDumpSemanticsTreeInInverseHitTestOrder', () async {
Map<String, dynamic> result;
await binding.doFrame(); await binding.doFrame();
result = await binding.testExtension('debugDumpSemanticsTreeInInverseHitTestOrder', <String, String>{}); final Map<String, dynamic> result = await binding.testExtension('debugDumpSemanticsTreeInInverseHitTestOrder', <String, String>{});
expect(result, <String, String>{});
expect(console, <String>['Semantics not collected.']); expect(result, <String, String>{
console.clear(); 'data': 'Semantics not collected.'
});
}); });
test('Service extensions - debugPaint', () async { test('Service extensions - debugPaint', () async {
......
...@@ -400,45 +400,50 @@ class FlutterDevice { ...@@ -400,45 +400,50 @@ class FlutterDevice {
Future<void> debugDumpApp() async { Future<void> debugDumpApp() async {
final List<FlutterView> views = await vmService.getFlutterViews(); final List<FlutterView> views = await vmService.getFlutterViews();
for (final FlutterView view in views) { for (final FlutterView view in views) {
await vmService.flutterDebugDumpApp( final String data = await vmService.flutterDebugDumpApp(
isolateId: view.uiIsolate.id, isolateId: view.uiIsolate.id,
); );
globals.printStatus(data);
} }
} }
Future<void> debugDumpRenderTree() async { Future<void> debugDumpRenderTree() async {
final List<FlutterView> views = await vmService.getFlutterViews(); final List<FlutterView> views = await vmService.getFlutterViews();
for (final FlutterView view in views) { for (final FlutterView view in views) {
await vmService.flutterDebugDumpRenderTree( final String data = await vmService.flutterDebugDumpRenderTree(
isolateId: view.uiIsolate.id, isolateId: view.uiIsolate.id,
); );
globals.printStatus(data);
} }
} }
Future<void> debugDumpLayerTree() async { Future<void> debugDumpLayerTree() async {
final List<FlutterView> views = await vmService.getFlutterViews(); final List<FlutterView> views = await vmService.getFlutterViews();
for (final FlutterView view in views) { for (final FlutterView view in views) {
await vmService.flutterDebugDumpLayerTree( final String data = await vmService.flutterDebugDumpLayerTree(
isolateId: view.uiIsolate.id, isolateId: view.uiIsolate.id,
); );
globals.printStatus(data);
} }
} }
Future<void> debugDumpSemanticsTreeInTraversalOrder() async { Future<void> debugDumpSemanticsTreeInTraversalOrder() async {
final List<FlutterView> views = await vmService.getFlutterViews(); final List<FlutterView> views = await vmService.getFlutterViews();
for (final FlutterView view in views) { for (final FlutterView view in views) {
await vmService.flutterDebugDumpSemanticsTreeInTraversalOrder( final String data = await vmService.flutterDebugDumpSemanticsTreeInTraversalOrder(
isolateId: view.uiIsolate.id, isolateId: view.uiIsolate.id,
); );
globals.printStatus(data);
} }
} }
Future<void> debugDumpSemanticsTreeInInverseHitTestOrder() async { Future<void> debugDumpSemanticsTreeInInverseHitTestOrder() async {
final List<FlutterView> views = await vmService.getFlutterViews(); final List<FlutterView> views = await vmService.getFlutterViews();
for (final FlutterView view in views) { for (final FlutterView view in views) {
await vmService.flutterDebugDumpSemanticsTreeInInverseHitTestOrder( final String data = await vmService.flutterDebugDumpSemanticsTreeInInverseHitTestOrder(
isolateId: view.uiIsolate.id, isolateId: view.uiIsolate.id,
); );
globals.printStatus(data);
} }
} }
......
...@@ -515,49 +515,55 @@ extension FlutterVmService on vm_service.VmService { ...@@ -515,49 +515,55 @@ extension FlutterVmService on vm_service.VmService {
await onRunnable; await onRunnable;
} }
Future<Map<String, dynamic>> flutterDebugDumpApp({ Future<String> flutterDebugDumpApp({
@required String isolateId, @required String isolateId,
}) { }) async {
return invokeFlutterExtensionRpcRaw( final Map<String, Object> response = await invokeFlutterExtensionRpcRaw(
'ext.flutter.debugDumpApp', 'ext.flutter.debugDumpApp',
isolateId: isolateId, isolateId: isolateId,
); );
return response['data']?.toString();
} }
Future<Map<String, dynamic>> flutterDebugDumpRenderTree({ Future<String> flutterDebugDumpRenderTree({
@required String isolateId, @required String isolateId,
}) { }) async {
return invokeFlutterExtensionRpcRaw( final Map<String, Object> response = await invokeFlutterExtensionRpcRaw(
'ext.flutter.debugDumpRenderTree', 'ext.flutter.debugDumpRenderTree',
isolateId: isolateId, isolateId: isolateId,
args: <String, Object>{}
); );
return response['data']?.toString();
} }
Future<Map<String, dynamic>> flutterDebugDumpLayerTree({ Future<String> flutterDebugDumpLayerTree({
@required String isolateId, @required String isolateId,
}) { }) async {
return invokeFlutterExtensionRpcRaw( final Map<String, Object> response = await invokeFlutterExtensionRpcRaw(
'ext.flutter.debugDumpLayerTree', 'ext.flutter.debugDumpLayerTree',
isolateId: isolateId, isolateId: isolateId,
); );
return response['data']?.toString();
} }
Future<Map<String, dynamic>> flutterDebugDumpSemanticsTreeInTraversalOrder({ Future<String> flutterDebugDumpSemanticsTreeInTraversalOrder({
@required String isolateId, @required String isolateId,
}) { }) async {
return invokeFlutterExtensionRpcRaw( final Map<String, Object> response = await invokeFlutterExtensionRpcRaw(
'ext.flutter.debugDumpSemanticsTreeInTraversalOrder', 'ext.flutter.debugDumpSemanticsTreeInTraversalOrder',
isolateId: isolateId, isolateId: isolateId,
); );
return response['data']?.toString();
} }
Future<Map<String, dynamic>> flutterDebugDumpSemanticsTreeInInverseHitTestOrder({ Future<String> flutterDebugDumpSemanticsTreeInInverseHitTestOrder({
@required String isolateId, @required String isolateId,
}) { }) async {
return invokeFlutterExtensionRpcRaw( final Map<String, Object> response = await invokeFlutterExtensionRpcRaw(
'ext.flutter.debugDumpSemanticsTreeInInverseHitTestOrder', 'ext.flutter.debugDumpSemanticsTreeInInverseHitTestOrder',
isolateId: isolateId, isolateId: isolateId,
); );
return response['data']?.toString();
} }
Future<Map<String, dynamic>> _flutterToggle(String name, { Future<Map<String, dynamic>> _flutterToggle(String name, {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment