Unverified Commit 73024eb7 authored by Zachary Anderson's avatar Zachary Anderson Committed by GitHub

[flutter_tool] Adds --enable-dart-profiling flag (#115863)

parent 6a26305d
...@@ -626,7 +626,8 @@ class AndroidDevice extends Device { ...@@ -626,7 +626,8 @@ class AndroidDevice extends Device {
'-a', 'android.intent.action.MAIN', '-a', 'android.intent.action.MAIN',
'-c', 'android.intent.category.LAUNCHER', '-c', 'android.intent.category.LAUNCHER',
'-f', '0x20000000', // FLAG_ACTIVITY_SINGLE_TOP '-f', '0x20000000', // FLAG_ACTIVITY_SINGLE_TOP
'--ez', 'enable-dart-profiling', 'true', if (debuggingOptions.enableDartProfiling)
...<String>['--ez', 'enable-dart-profiling', 'true'],
if (traceStartup) if (traceStartup)
...<String>['--ez', 'trace-startup', 'true'], ...<String>['--ez', 'trace-startup', 'true'],
if (route != null) if (route != null)
......
...@@ -135,6 +135,11 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment ...@@ -135,6 +135,11 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment
'this comma separated list of allowed prefixes.', 'this comma separated list of allowed prefixes.',
valueHelp: 'skia.gpu,skia.shaders', valueHelp: 'skia.gpu,skia.shaders',
) )
..addFlag('enable-dart-profiling',
defaultsTo: true,
help: 'Whether the Dart VM sampling CPU profiler is enabled. This flag '
'is only meaningnful in debug and profile builds.',
)
..addFlag('enable-software-rendering', ..addFlag('enable-software-rendering',
negatable: false, negatable: false,
help: 'Enable rendering using the Skia software backend. ' help: 'Enable rendering using the Skia software backend. '
...@@ -178,6 +183,7 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment ...@@ -178,6 +183,7 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment
} }
bool get traceStartup => boolArgDeprecated('trace-startup'); bool get traceStartup => boolArgDeprecated('trace-startup');
bool get enableDartProfiling => boolArgDeprecated('enable-dart-profiling');
bool get cacheSkSL => boolArgDeprecated('cache-sksl'); bool get cacheSkSL => boolArgDeprecated('cache-sksl');
bool get dumpSkpOnShaderCompilation => boolArgDeprecated('dump-skp-on-shader-compilation'); bool get dumpSkpOnShaderCompilation => boolArgDeprecated('dump-skp-on-shader-compilation');
bool get purgePersistentCache => boolArgDeprecated('purge-persistent-cache'); bool get purgePersistentCache => boolArgDeprecated('purge-persistent-cache');
...@@ -224,6 +230,7 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment ...@@ -224,6 +230,7 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment
webBrowserFlags: webBrowserFlags, webBrowserFlags: webBrowserFlags,
enableImpeller: enableImpeller, enableImpeller: enableImpeller,
uninstallFirst: uninstallFirst, uninstallFirst: uninstallFirst,
enableDartProfiling: enableDartProfiling,
); );
} else { } else {
return DebuggingOptions.enabled( return DebuggingOptions.enabled(
...@@ -270,6 +277,7 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment ...@@ -270,6 +277,7 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment
nativeNullAssertions: boolArgDeprecated('native-null-assertions'), nativeNullAssertions: boolArgDeprecated('native-null-assertions'),
enableImpeller: enableImpeller, enableImpeller: enableImpeller,
uninstallFirst: uninstallFirst, uninstallFirst: uninstallFirst,
enableDartProfiling: enableDartProfiling,
); );
} }
} }
......
...@@ -282,78 +282,50 @@ class CustomDeviceAppSession { ...@@ -282,78 +282,50 @@ class CustomDeviceAppSession {
/// For example, `_getEngineOptions(null, false, null)` will return /// For example, `_getEngineOptions(null, false, null)` will return
/// `['enable-dart-profiling=true']` /// `['enable-dart-profiling=true']`
List<String> _getEngineOptions(DebuggingOptions debuggingOptions, bool traceStartup, String? route) { List<String> _getEngineOptions(DebuggingOptions debuggingOptions, bool traceStartup, String? route) {
final List<String> options = <String>[]; final String dartVmFlags = computeDartVmFlags(debuggingOptions);
return <String>[
void addFlag(String value) { if (traceStartup)
options.add(value); 'trace-startup=true',
} if (route != null)
'route=$route',
addFlag('enable-dart-profiling=true'); if (debuggingOptions.enableDartProfiling)
'enable-dart-profiling=true',
if (traceStartup) { if (debuggingOptions.enableSoftwareRendering)
addFlag('trace-startup=true'); 'enable-software-rendering=true',
} if (debuggingOptions.skiaDeterministicRendering)
if (route != null) { 'skia-deterministic-rendering=true',
addFlag('route=$route'); if (debuggingOptions.traceSkia)
} 'trace-skia=true',
if (debuggingOptions != null) { if (debuggingOptions.traceAllowlist != null)
if (debuggingOptions.enableSoftwareRendering) { 'trace-allowlist=${debuggingOptions.traceAllowlist}',
addFlag('enable-software-rendering=true'); if (debuggingOptions.traceSystrace)
} 'trace-systrace=true',
if (debuggingOptions.skiaDeterministicRendering) { if (debuggingOptions.endlessTraceBuffer)
addFlag('skia-deterministic-rendering=true'); 'endless-trace-buffer=true',
} if (debuggingOptions.dumpSkpOnShaderCompilation)
if (debuggingOptions.traceSkia) { 'dump-skp-on-shader-compilation=true',
addFlag('trace-skia=true'); if (debuggingOptions.cacheSkSL) 'cache-sksl=true',
} if (debuggingOptions.purgePersistentCache)
if (debuggingOptions.traceAllowlist != null) { 'purge-persistent-cache=true',
addFlag('trace-allowlist=${debuggingOptions.traceAllowlist}'); if (debuggingOptions.debuggingEnabled) ...<String>[
} if (debuggingOptions.deviceVmServicePort != null)
if (debuggingOptions.traceSystrace) { 'observatory-port=${debuggingOptions.deviceVmServicePort}',
addFlag('trace-systrace=true'); if (debuggingOptions.buildInfo.isDebug) ...<String>[
} 'enable-checked-mode=true',
if (debuggingOptions.endlessTraceBuffer) { 'verify-entry-points=true',
addFlag('endless-trace-buffer=true'); ],
} if (debuggingOptions.startPaused)
if (debuggingOptions.dumpSkpOnShaderCompilation) { 'start-paused=true',
addFlag('dump-skp-on-shader-compilation=true'); if (debuggingOptions.disableServiceAuthCodes)
} 'disable-service-auth-codes=true',
if (debuggingOptions.cacheSkSL) { if (dartVmFlags.isNotEmpty)
addFlag('cache-sksl=true'); 'dart-flags=$dartVmFlags',
} if (debuggingOptions.useTestFonts)
if (debuggingOptions.purgePersistentCache) { 'use-test-fonts=true',
addFlag('purge-persistent-cache=true'); if (debuggingOptions.verboseSystemLogs)
} 'verbose-logging=true',
// Options only supported when there is a VM Service connection between the ],
// tool and the device, usually in debug or profile mode. ];
if (debuggingOptions.debuggingEnabled) {
if (debuggingOptions.deviceVmServicePort != null) {
addFlag('observatory-port=${debuggingOptions.deviceVmServicePort}');
}
if (debuggingOptions.buildInfo.isDebug) {
addFlag('enable-checked-mode=true');
addFlag('verify-entry-points=true');
}
if (debuggingOptions.startPaused) {
addFlag('start-paused=true');
}
if (debuggingOptions.disableServiceAuthCodes) {
addFlag('disable-service-auth-codes=true');
}
final String dartVmFlags = computeDartVmFlags(debuggingOptions);
if (dartVmFlags.isNotEmpty) {
addFlag('dart-flags=$dartVmFlags');
}
if (debuggingOptions.useTestFonts) {
addFlag('use-test-fonts=true');
}
if (debuggingOptions.verboseSystemLogs) {
addFlag('verbose-logging=true');
}
}
}
return options;
} }
/// Get the engine options for the given [debuggingOptions], /// Get the engine options for the given [debuggingOptions],
......
...@@ -753,6 +753,7 @@ class DebuggingOptions { ...@@ -753,6 +753,7 @@ class DebuggingOptions {
this.nativeNullAssertions = false, this.nativeNullAssertions = false,
this.enableImpeller = false, this.enableImpeller = false,
this.uninstallFirst = false, this.uninstallFirst = false,
this.enableDartProfiling = true,
}) : debuggingEnabled = true; }) : debuggingEnabled = true;
DebuggingOptions.disabled(this.buildInfo, { DebuggingOptions.disabled(this.buildInfo, {
...@@ -771,6 +772,7 @@ class DebuggingOptions { ...@@ -771,6 +772,7 @@ class DebuggingOptions {
this.traceAllowlist, this.traceAllowlist,
this.enableImpeller = false, this.enableImpeller = false,
this.uninstallFirst = false, this.uninstallFirst = false,
this.enableDartProfiling = true,
}) : debuggingEnabled = false, }) : debuggingEnabled = false,
useTestFonts = false, useTestFonts = false,
startPaused = false, startPaused = false,
...@@ -841,6 +843,7 @@ class DebuggingOptions { ...@@ -841,6 +843,7 @@ class DebuggingOptions {
required this.nativeNullAssertions, required this.nativeNullAssertions,
required this.enableImpeller, required this.enableImpeller,
required this.uninstallFirst, required this.uninstallFirst,
required this.enableDartProfiling,
}); });
final bool debuggingEnabled; final bool debuggingEnabled;
...@@ -876,6 +879,7 @@ class DebuggingOptions { ...@@ -876,6 +879,7 @@ class DebuggingOptions {
final bool webUseSseForDebugBackend; final bool webUseSseForDebugBackend;
final bool webUseSseForInjectedClient; final bool webUseSseForInjectedClient;
final bool enableImpeller; final bool enableImpeller;
final bool enableDartProfiling;
/// Whether the tool should try to uninstall a previously installed version of the app. /// Whether the tool should try to uninstall a previously installed version of the app.
/// ///
...@@ -916,7 +920,7 @@ class DebuggingOptions { ...@@ -916,7 +920,7 @@ class DebuggingOptions {
List<String> getIOSLaunchArguments(EnvironmentType environmentType, String? route, Map<String, Object?> platformArgs) { List<String> getIOSLaunchArguments(EnvironmentType environmentType, String? route, Map<String, Object?> platformArgs) {
final String dartVmFlags = computeDartVmFlags(this); final String dartVmFlags = computeDartVmFlags(this);
return <String>[ return <String>[
'--enable-dart-profiling', if (enableDartProfiling) '--enable-dart-profiling',
if (disableServiceAuthCodes) '--disable-service-auth-codes', if (disableServiceAuthCodes) '--disable-service-auth-codes',
if (disablePortPublication) '--disable-observatory-publication', if (disablePortPublication) '--disable-observatory-publication',
if (startPaused) '--start-paused', if (startPaused) '--start-paused',
...@@ -994,6 +998,7 @@ class DebuggingOptions { ...@@ -994,6 +998,7 @@ class DebuggingOptions {
'nullAssertions': nullAssertions, 'nullAssertions': nullAssertions,
'nativeNullAssertions': nativeNullAssertions, 'nativeNullAssertions': nativeNullAssertions,
'enableImpeller': enableImpeller, 'enableImpeller': enableImpeller,
'enableDartProfiling': enableDartProfiling,
}; };
static DebuggingOptions fromJson(Map<String, Object?> json, BuildInfo buildInfo) => static DebuggingOptions fromJson(Map<String, Object?> json, BuildInfo buildInfo) =>
...@@ -1040,6 +1045,7 @@ class DebuggingOptions { ...@@ -1040,6 +1045,7 @@ class DebuggingOptions {
nativeNullAssertions: (json['nativeNullAssertions'] as bool?)!, nativeNullAssertions: (json['nativeNullAssertions'] as bool?)!,
enableImpeller: (json['enableImpeller'] as bool?) ?? false, enableImpeller: (json['enableImpeller'] as bool?) ?? false,
uninstallFirst: (json['uninstallFirst'] as bool?) ?? false, uninstallFirst: (json['uninstallFirst'] as bool?) ?? false,
enableDartProfiling: (json['enableDartProfiling'] as bool?) ?? true,
); );
} }
......
...@@ -111,7 +111,8 @@ class FlutterTesterTestDevice extends TestDevice { ...@@ -111,7 +111,8 @@ class FlutterTesterTestDevice extends TestDevice {
'--verify-entry-points', '--verify-entry-points',
'--enable-software-rendering', '--enable-software-rendering',
'--skia-deterministic-rendering', '--skia-deterministic-rendering',
'--enable-dart-profiling', if (debuggingOptions.enableDartProfiling)
'--enable-dart-profiling',
'--non-interactive', '--non-interactive',
'--use-test-fonts', '--use-test-fonts',
'--disable-asset-fonts', '--disable-asset-fonts',
......
...@@ -165,7 +165,8 @@ class FlutterTesterDevice extends Device { ...@@ -165,7 +165,8 @@ class FlutterTesterDevice extends Device {
_artifacts.getArtifactPath(Artifact.flutterTester), _artifacts.getArtifactPath(Artifact.flutterTester),
'--run-forever', '--run-forever',
'--non-interactive', '--non-interactive',
'--enable-dart-profiling', if (debuggingOptions.enableDartProfiling)
'--enable-dart-profiling',
'--packages=${debuggingOptions.buildInfo.packagesPath}', '--packages=${debuggingOptions.buildInfo.packagesPath}',
'--flutter-assets-dir=${assetDirectory.path}', '--flutter-assets-dir=${assetDirectory.path}',
if (debuggingOptions.startPaused) if (debuggingOptions.startPaused)
......
...@@ -453,6 +453,7 @@ void main() { ...@@ -453,6 +453,7 @@ void main() {
dartFlags: 'c', dartFlags: 'c',
deviceVmServicePort: 1234, deviceVmServicePort: 1234,
enableImpeller: true, enableImpeller: true,
enableDartProfiling: false,
); );
final String jsonString = json.encode(original.toJson()); final String jsonString = json.encode(original.toJson());
final Map<String, dynamic> decoded = castStringKeyedMap(json.decode(jsonString))!; final Map<String, dynamic> decoded = castStringKeyedMap(json.decode(jsonString))!;
...@@ -464,6 +465,7 @@ void main() { ...@@ -464,6 +465,7 @@ void main() {
expect(deserialized.dartFlags, original.dartFlags); expect(deserialized.dartFlags, original.dartFlags);
expect(deserialized.deviceVmServicePort, original.deviceVmServicePort); expect(deserialized.deviceVmServicePort, original.deviceVmServicePort);
expect(deserialized.enableImpeller, original.enableImpeller); expect(deserialized.enableImpeller, original.enableImpeller);
expect(deserialized.enableDartProfiling, original.enableDartProfiling);
}); });
}); });
...@@ -664,6 +666,27 @@ void main() { ...@@ -664,6 +666,27 @@ void main() {
].join(' '), ].join(' '),
); );
}); });
testWithoutContext('No --enable-dart-profiling flag when option is false', () {
final DebuggingOptions original = DebuggingOptions.enabled(
BuildInfo.debug,
enableDartProfiling: false,
);
final List<String> launchArguments = original.getIOSLaunchArguments(
EnvironmentType.physical,
null,
<String, Object?>{},
);
expect(
launchArguments.join(' '),
<String>[
'--enable-checked-mode',
'--verify-entry-points',
].join(' '),
);
});
}); });
} }
......
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