Skip to content

Commit 73024eb

Browse files
authored
[flutter_tool] Adds --enable-dart-profiling flag (#115863)
1 parent 6a26305 commit 73024eb

File tree

7 files changed

+88
-76
lines changed

7 files changed

+88
-76
lines changed

packages/flutter_tools/lib/src/android/android_device.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,8 @@ class AndroidDevice extends Device {
626626
'-a', 'android.intent.action.MAIN',
627627
'-c', 'android.intent.category.LAUNCHER',
628628
'-f', '0x20000000', // FLAG_ACTIVITY_SINGLE_TOP
629-
'--ez', 'enable-dart-profiling', 'true',
629+
if (debuggingOptions.enableDartProfiling)
630+
...<String>['--ez', 'enable-dart-profiling', 'true'],
630631
if (traceStartup)
631632
...<String>['--ez', 'trace-startup', 'true'],
632633
if (route != null)

packages/flutter_tools/lib/src/commands/run.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment
135135
'this comma separated list of allowed prefixes.',
136136
valueHelp: 'skia.gpu,skia.shaders',
137137
)
138+
..addFlag('enable-dart-profiling',
139+
defaultsTo: true,
140+
help: 'Whether the Dart VM sampling CPU profiler is enabled. This flag '
141+
'is only meaningnful in debug and profile builds.',
142+
)
138143
..addFlag('enable-software-rendering',
139144
negatable: false,
140145
help: 'Enable rendering using the Skia software backend. '
@@ -178,6 +183,7 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment
178183
}
179184

180185
bool get traceStartup => boolArgDeprecated('trace-startup');
186+
bool get enableDartProfiling => boolArgDeprecated('enable-dart-profiling');
181187
bool get cacheSkSL => boolArgDeprecated('cache-sksl');
182188
bool get dumpSkpOnShaderCompilation => boolArgDeprecated('dump-skp-on-shader-compilation');
183189
bool get purgePersistentCache => boolArgDeprecated('purge-persistent-cache');
@@ -224,6 +230,7 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment
224230
webBrowserFlags: webBrowserFlags,
225231
enableImpeller: enableImpeller,
226232
uninstallFirst: uninstallFirst,
233+
enableDartProfiling: enableDartProfiling,
227234
);
228235
} else {
229236
return DebuggingOptions.enabled(
@@ -270,6 +277,7 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment
270277
nativeNullAssertions: boolArgDeprecated('native-null-assertions'),
271278
enableImpeller: enableImpeller,
272279
uninstallFirst: uninstallFirst,
280+
enableDartProfiling: enableDartProfiling,
273281
);
274282
}
275283
}

packages/flutter_tools/lib/src/custom_devices/custom_device.dart

Lines changed: 44 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -282,78 +282,50 @@ class CustomDeviceAppSession {
282282
/// For example, `_getEngineOptions(null, false, null)` will return
283283
/// `['enable-dart-profiling=true']`
284284
List<String> _getEngineOptions(DebuggingOptions debuggingOptions, bool traceStartup, String? route) {
285-
final List<String> options = <String>[];
286-
287-
void addFlag(String value) {
288-
options.add(value);
289-
}
290-
291-
addFlag('enable-dart-profiling=true');
292-
293-
if (traceStartup) {
294-
addFlag('trace-startup=true');
295-
}
296-
if (route != null) {
297-
addFlag('route=$route');
298-
}
299-
if (debuggingOptions != null) {
300-
if (debuggingOptions.enableSoftwareRendering) {
301-
addFlag('enable-software-rendering=true');
302-
}
303-
if (debuggingOptions.skiaDeterministicRendering) {
304-
addFlag('skia-deterministic-rendering=true');
305-
}
306-
if (debuggingOptions.traceSkia) {
307-
addFlag('trace-skia=true');
308-
}
309-
if (debuggingOptions.traceAllowlist != null) {
310-
addFlag('trace-allowlist=${debuggingOptions.traceAllowlist}');
311-
}
312-
if (debuggingOptions.traceSystrace) {
313-
addFlag('trace-systrace=true');
314-
}
315-
if (debuggingOptions.endlessTraceBuffer) {
316-
addFlag('endless-trace-buffer=true');
317-
}
318-
if (debuggingOptions.dumpSkpOnShaderCompilation) {
319-
addFlag('dump-skp-on-shader-compilation=true');
320-
}
321-
if (debuggingOptions.cacheSkSL) {
322-
addFlag('cache-sksl=true');
323-
}
324-
if (debuggingOptions.purgePersistentCache) {
325-
addFlag('purge-persistent-cache=true');
326-
}
327-
// Options only supported when there is a VM Service connection between the
328-
// tool and the device, usually in debug or profile mode.
329-
if (debuggingOptions.debuggingEnabled) {
330-
if (debuggingOptions.deviceVmServicePort != null) {
331-
addFlag('observatory-port=${debuggingOptions.deviceVmServicePort}');
332-
}
333-
if (debuggingOptions.buildInfo.isDebug) {
334-
addFlag('enable-checked-mode=true');
335-
addFlag('verify-entry-points=true');
336-
}
337-
if (debuggingOptions.startPaused) {
338-
addFlag('start-paused=true');
339-
}
340-
if (debuggingOptions.disableServiceAuthCodes) {
341-
addFlag('disable-service-auth-codes=true');
342-
}
343-
final String dartVmFlags = computeDartVmFlags(debuggingOptions);
344-
if (dartVmFlags.isNotEmpty) {
345-
addFlag('dart-flags=$dartVmFlags');
346-
}
347-
if (debuggingOptions.useTestFonts) {
348-
addFlag('use-test-fonts=true');
349-
}
350-
if (debuggingOptions.verboseSystemLogs) {
351-
addFlag('verbose-logging=true');
352-
}
353-
}
354-
}
355-
356-
return options;
285+
final String dartVmFlags = computeDartVmFlags(debuggingOptions);
286+
return <String>[
287+
if (traceStartup)
288+
'trace-startup=true',
289+
if (route != null)
290+
'route=$route',
291+
if (debuggingOptions.enableDartProfiling)
292+
'enable-dart-profiling=true',
293+
if (debuggingOptions.enableSoftwareRendering)
294+
'enable-software-rendering=true',
295+
if (debuggingOptions.skiaDeterministicRendering)
296+
'skia-deterministic-rendering=true',
297+
if (debuggingOptions.traceSkia)
298+
'trace-skia=true',
299+
if (debuggingOptions.traceAllowlist != null)
300+
'trace-allowlist=${debuggingOptions.traceAllowlist}',
301+
if (debuggingOptions.traceSystrace)
302+
'trace-systrace=true',
303+
if (debuggingOptions.endlessTraceBuffer)
304+
'endless-trace-buffer=true',
305+
if (debuggingOptions.dumpSkpOnShaderCompilation)
306+
'dump-skp-on-shader-compilation=true',
307+
if (debuggingOptions.cacheSkSL) 'cache-sksl=true',
308+
if (debuggingOptions.purgePersistentCache)
309+
'purge-persistent-cache=true',
310+
if (debuggingOptions.debuggingEnabled) ...<String>[
311+
if (debuggingOptions.deviceVmServicePort != null)
312+
'observatory-port=${debuggingOptions.deviceVmServicePort}',
313+
if (debuggingOptions.buildInfo.isDebug) ...<String>[
314+
'enable-checked-mode=true',
315+
'verify-entry-points=true',
316+
],
317+
if (debuggingOptions.startPaused)
318+
'start-paused=true',
319+
if (debuggingOptions.disableServiceAuthCodes)
320+
'disable-service-auth-codes=true',
321+
if (dartVmFlags.isNotEmpty)
322+
'dart-flags=$dartVmFlags',
323+
if (debuggingOptions.useTestFonts)
324+
'use-test-fonts=true',
325+
if (debuggingOptions.verboseSystemLogs)
326+
'verbose-logging=true',
327+
],
328+
];
357329
}
358330

359331
/// Get the engine options for the given [debuggingOptions],

packages/flutter_tools/lib/src/device.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,7 @@ class DebuggingOptions {
753753
this.nativeNullAssertions = false,
754754
this.enableImpeller = false,
755755
this.uninstallFirst = false,
756+
this.enableDartProfiling = true,
756757
}) : debuggingEnabled = true;
757758

758759
DebuggingOptions.disabled(this.buildInfo, {
@@ -771,6 +772,7 @@ class DebuggingOptions {
771772
this.traceAllowlist,
772773
this.enableImpeller = false,
773774
this.uninstallFirst = false,
775+
this.enableDartProfiling = true,
774776
}) : debuggingEnabled = false,
775777
useTestFonts = false,
776778
startPaused = false,
@@ -841,6 +843,7 @@ class DebuggingOptions {
841843
required this.nativeNullAssertions,
842844
required this.enableImpeller,
843845
required this.uninstallFirst,
846+
required this.enableDartProfiling,
844847
});
845848

846849
final bool debuggingEnabled;
@@ -876,6 +879,7 @@ class DebuggingOptions {
876879
final bool webUseSseForDebugBackend;
877880
final bool webUseSseForInjectedClient;
878881
final bool enableImpeller;
882+
final bool enableDartProfiling;
879883

880884
/// Whether the tool should try to uninstall a previously installed version of the app.
881885
///
@@ -916,7 +920,7 @@ class DebuggingOptions {
916920
List<String> getIOSLaunchArguments(EnvironmentType environmentType, String? route, Map<String, Object?> platformArgs) {
917921
final String dartVmFlags = computeDartVmFlags(this);
918922
return <String>[
919-
'--enable-dart-profiling',
923+
if (enableDartProfiling) '--enable-dart-profiling',
920924
if (disableServiceAuthCodes) '--disable-service-auth-codes',
921925
if (disablePortPublication) '--disable-observatory-publication',
922926
if (startPaused) '--start-paused',
@@ -994,6 +998,7 @@ class DebuggingOptions {
994998
'nullAssertions': nullAssertions,
995999
'nativeNullAssertions': nativeNullAssertions,
9961000
'enableImpeller': enableImpeller,
1001+
'enableDartProfiling': enableDartProfiling,
9971002
};
9981003

9991004
static DebuggingOptions fromJson(Map<String, Object?> json, BuildInfo buildInfo) =>
@@ -1040,6 +1045,7 @@ class DebuggingOptions {
10401045
nativeNullAssertions: (json['nativeNullAssertions'] as bool?)!,
10411046
enableImpeller: (json['enableImpeller'] as bool?) ?? false,
10421047
uninstallFirst: (json['uninstallFirst'] as bool?) ?? false,
1048+
enableDartProfiling: (json['enableDartProfiling'] as bool?) ?? true,
10431049
);
10441050
}
10451051

packages/flutter_tools/lib/src/test/flutter_tester_device.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ class FlutterTesterTestDevice extends TestDevice {
111111
'--verify-entry-points',
112112
'--enable-software-rendering',
113113
'--skia-deterministic-rendering',
114-
'--enable-dart-profiling',
114+
if (debuggingOptions.enableDartProfiling)
115+
'--enable-dart-profiling',
115116
'--non-interactive',
116117
'--use-test-fonts',
117118
'--disable-asset-fonts',

packages/flutter_tools/lib/src/tester/flutter_tester.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ class FlutterTesterDevice extends Device {
165165
_artifacts.getArtifactPath(Artifact.flutterTester),
166166
'--run-forever',
167167
'--non-interactive',
168-
'--enable-dart-profiling',
168+
if (debuggingOptions.enableDartProfiling)
169+
'--enable-dart-profiling',
169170
'--packages=${debuggingOptions.buildInfo.packagesPath}',
170171
'--flutter-assets-dir=${assetDirectory.path}',
171172
if (debuggingOptions.startPaused)

packages/flutter_tools/test/general.shard/device_test.dart

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ void main() {
453453
dartFlags: 'c',
454454
deviceVmServicePort: 1234,
455455
enableImpeller: true,
456+
enableDartProfiling: false,
456457
);
457458
final String jsonString = json.encode(original.toJson());
458459
final Map<String, dynamic> decoded = castStringKeyedMap(json.decode(jsonString))!;
@@ -464,6 +465,7 @@ void main() {
464465
expect(deserialized.dartFlags, original.dartFlags);
465466
expect(deserialized.deviceVmServicePort, original.deviceVmServicePort);
466467
expect(deserialized.enableImpeller, original.enableImpeller);
468+
expect(deserialized.enableDartProfiling, original.enableDartProfiling);
467469
});
468470
});
469471

@@ -664,6 +666,27 @@ void main() {
664666
].join(' '),
665667
);
666668
});
669+
670+
testWithoutContext('No --enable-dart-profiling flag when option is false', () {
671+
final DebuggingOptions original = DebuggingOptions.enabled(
672+
BuildInfo.debug,
673+
enableDartProfiling: false,
674+
);
675+
676+
final List<String> launchArguments = original.getIOSLaunchArguments(
677+
EnvironmentType.physical,
678+
null,
679+
<String, Object?>{},
680+
);
681+
682+
expect(
683+
launchArguments.join(' '),
684+
<String>[
685+
'--enable-checked-mode',
686+
'--verify-entry-points',
687+
].join(' '),
688+
);
689+
});
667690
});
668691
}
669692

0 commit comments

Comments
 (0)