Unverified Commit 406c4dbf authored by Derek Xu's avatar Derek Xu Committed by GitHub

Add `--trace-to-file` option to `flutter run` (#135713)

parent 9751fe64
...@@ -625,6 +625,7 @@ class AndroidDevice extends Device { ...@@ -625,6 +625,7 @@ class AndroidDevice extends Device {
final String dartVmFlags = computeDartVmFlags(debuggingOptions); final String dartVmFlags = computeDartVmFlags(debuggingOptions);
final String? traceAllowlist = debuggingOptions.traceAllowlist; final String? traceAllowlist = debuggingOptions.traceAllowlist;
final String? traceSkiaAllowlist = debuggingOptions.traceSkiaAllowlist; final String? traceSkiaAllowlist = debuggingOptions.traceSkiaAllowlist;
final String? traceToFile = debuggingOptions.traceToFile;
final List<String> cmd = <String>[ final List<String> cmd = <String>[
'shell', 'am', 'start', 'shell', 'am', 'start',
'-a', 'android.intent.action.MAIN', '-a', 'android.intent.action.MAIN',
...@@ -648,6 +649,8 @@ class AndroidDevice extends Device { ...@@ -648,6 +649,8 @@ class AndroidDevice extends Device {
...<String>['--es', 'trace-skia-allowlist', traceSkiaAllowlist], ...<String>['--es', 'trace-skia-allowlist', traceSkiaAllowlist],
if (debuggingOptions.traceSystrace) if (debuggingOptions.traceSystrace)
...<String>['--ez', 'trace-systrace', 'true'], ...<String>['--ez', 'trace-systrace', 'true'],
if (traceToFile != null)
...<String>['--es', 'trace-to-file', traceToFile],
if (debuggingOptions.endlessTraceBuffer) if (debuggingOptions.endlessTraceBuffer)
...<String>['--ez', 'endless-trace-buffer', 'true'], ...<String>['--ez', 'endless-trace-buffer', 'true'],
if (debuggingOptions.dumpSkpOnShaderCompilation) if (debuggingOptions.dumpSkpOnShaderCompilation)
......
...@@ -119,6 +119,12 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment ...@@ -119,6 +119,12 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment
'platforms where such a tracer is available (Android, iOS, ' 'platforms where such a tracer is available (Android, iOS, '
'macOS and Fuchsia).', 'macOS and Fuchsia).',
) )
..addOption('trace-to-file',
help: 'Write the timeline trace to a file at the specified path. The '
"file will be in Perfetto's proto format; it will be possible to "
"load the file into Perfetto's trace viewer.",
valueHelp: 'path/to/trace.binpb',
)
..addFlag('trace-skia', ..addFlag('trace-skia',
negatable: false, negatable: false,
help: 'Enable tracing of Skia code. This is useful when debugging ' help: 'Enable tracing of Skia code. This is useful when debugging '
...@@ -270,6 +276,7 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment ...@@ -270,6 +276,7 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment
traceAllowlist: traceAllowlist, traceAllowlist: traceAllowlist,
traceSkiaAllowlist: stringArg('trace-skia-allowlist'), traceSkiaAllowlist: stringArg('trace-skia-allowlist'),
traceSystrace: boolArg('trace-systrace'), traceSystrace: boolArg('trace-systrace'),
traceToFile: stringArg('trace-to-file'),
endlessTraceBuffer: boolArg('endless-trace-buffer'), endlessTraceBuffer: boolArg('endless-trace-buffer'),
dumpSkpOnShaderCompilation: dumpSkpOnShaderCompilation, dumpSkpOnShaderCompilation: dumpSkpOnShaderCompilation,
cacheSkSL: cacheSkSL, cacheSkSL: cacheSkSL,
......
...@@ -300,6 +300,8 @@ class CustomDeviceAppSession { ...@@ -300,6 +300,8 @@ class CustomDeviceAppSession {
'trace-allowlist=${debuggingOptions.traceAllowlist}', 'trace-allowlist=${debuggingOptions.traceAllowlist}',
if (debuggingOptions.traceSystrace) if (debuggingOptions.traceSystrace)
'trace-systrace=true', 'trace-systrace=true',
if (debuggingOptions.traceToFile != null)
'trace-to-file=${debuggingOptions.traceToFile}',
if (debuggingOptions.endlessTraceBuffer) if (debuggingOptions.endlessTraceBuffer)
'endless-trace-buffer=true', 'endless-trace-buffer=true',
if (debuggingOptions.dumpSkpOnShaderCompilation) if (debuggingOptions.dumpSkpOnShaderCompilation)
......
...@@ -254,6 +254,9 @@ abstract class DesktopDevice extends Device { ...@@ -254,6 +254,9 @@ abstract class DesktopDevice extends Device {
if (debuggingOptions.traceSystrace) { if (debuggingOptions.traceSystrace) {
addFlag('trace-systrace=true'); addFlag('trace-systrace=true');
} }
if (debuggingOptions.traceToFile != null) {
addFlag('trace-to-file=${debuggingOptions.traceToFile}');
}
if (debuggingOptions.endlessTraceBuffer) { if (debuggingOptions.endlessTraceBuffer) {
addFlag('endless-trace-buffer=true'); addFlag('endless-trace-buffer=true');
} }
......
...@@ -937,6 +937,7 @@ class DebuggingOptions { ...@@ -937,6 +937,7 @@ class DebuggingOptions {
this.traceAllowlist, this.traceAllowlist,
this.traceSkiaAllowlist, this.traceSkiaAllowlist,
this.traceSystrace = false, this.traceSystrace = false,
this.traceToFile,
this.endlessTraceBuffer = false, this.endlessTraceBuffer = false,
this.dumpSkpOnShaderCompilation = false, this.dumpSkpOnShaderCompilation = false,
this.cacheSkSL = false, this.cacheSkSL = false,
...@@ -1006,6 +1007,7 @@ class DebuggingOptions { ...@@ -1006,6 +1007,7 @@ class DebuggingOptions {
traceSkia = false, traceSkia = false,
traceSkiaAllowlist = null, traceSkiaAllowlist = null,
traceSystrace = false, traceSystrace = false,
traceToFile = null,
endlessTraceBuffer = false, endlessTraceBuffer = false,
dumpSkpOnShaderCompilation = false, dumpSkpOnShaderCompilation = false,
purgePersistentCache = false, purgePersistentCache = false,
...@@ -1037,6 +1039,7 @@ class DebuggingOptions { ...@@ -1037,6 +1039,7 @@ class DebuggingOptions {
required this.traceAllowlist, required this.traceAllowlist,
required this.traceSkiaAllowlist, required this.traceSkiaAllowlist,
required this.traceSystrace, required this.traceSystrace,
required this.traceToFile,
required this.endlessTraceBuffer, required this.endlessTraceBuffer,
required this.dumpSkpOnShaderCompilation, required this.dumpSkpOnShaderCompilation,
required this.cacheSkSL, required this.cacheSkSL,
...@@ -1088,6 +1091,7 @@ class DebuggingOptions { ...@@ -1088,6 +1091,7 @@ class DebuggingOptions {
final String? traceAllowlist; final String? traceAllowlist;
final String? traceSkiaAllowlist; final String? traceSkiaAllowlist;
final bool traceSystrace; final bool traceSystrace;
final String? traceToFile;
final bool endlessTraceBuffer; final bool endlessTraceBuffer;
final bool dumpSkpOnShaderCompilation; final bool dumpSkpOnShaderCompilation;
final bool cacheSkSL; final bool cacheSkSL;
...@@ -1178,6 +1182,7 @@ class DebuggingOptions { ...@@ -1178,6 +1182,7 @@ class DebuggingOptions {
], ],
if (enableSoftwareRendering) '--enable-software-rendering', if (enableSoftwareRendering) '--enable-software-rendering',
if (traceSystrace) '--trace-systrace', if (traceSystrace) '--trace-systrace',
if (traceToFile != null) '--trace-to-file="$traceToFile"',
if (skiaDeterministicRendering) '--skia-deterministic-rendering', if (skiaDeterministicRendering) '--skia-deterministic-rendering',
if (traceSkia) '--trace-skia', if (traceSkia) '--trace-skia',
if (traceAllowlist != null) '--trace-allowlist="$traceAllowlist"', if (traceAllowlist != null) '--trace-allowlist="$traceAllowlist"',
...@@ -1218,6 +1223,7 @@ class DebuggingOptions { ...@@ -1218,6 +1223,7 @@ class DebuggingOptions {
'traceAllowlist': traceAllowlist, 'traceAllowlist': traceAllowlist,
'traceSkiaAllowlist': traceSkiaAllowlist, 'traceSkiaAllowlist': traceSkiaAllowlist,
'traceSystrace': traceSystrace, 'traceSystrace': traceSystrace,
'traceToFile': traceToFile,
'endlessTraceBuffer': endlessTraceBuffer, 'endlessTraceBuffer': endlessTraceBuffer,
'dumpSkpOnShaderCompilation': dumpSkpOnShaderCompilation, 'dumpSkpOnShaderCompilation': dumpSkpOnShaderCompilation,
'cacheSkSL': cacheSkSL, 'cacheSkSL': cacheSkSL,
...@@ -1269,6 +1275,7 @@ class DebuggingOptions { ...@@ -1269,6 +1275,7 @@ class DebuggingOptions {
traceAllowlist: json['traceAllowlist'] as String?, traceAllowlist: json['traceAllowlist'] as String?,
traceSkiaAllowlist: json['traceSkiaAllowlist'] as String?, traceSkiaAllowlist: json['traceSkiaAllowlist'] as String?,
traceSystrace: json['traceSystrace']! as bool, traceSystrace: json['traceSystrace']! as bool,
traceToFile: json['traceToFile'] as String?,
endlessTraceBuffer: json['endlessTraceBuffer']! as bool, endlessTraceBuffer: json['endlessTraceBuffer']! as bool,
dumpSkpOnShaderCompilation: json['dumpSkpOnShaderCompilation']! as bool, dumpSkpOnShaderCompilation: json['dumpSkpOnShaderCompilation']! as bool,
cacheSkSL: json['cacheSkSL']! as bool, cacheSkSL: json['cacheSkSL']! as bool,
......
...@@ -417,6 +417,7 @@ void main() { ...@@ -417,6 +417,7 @@ void main() {
'--disable-service-auth-codes', '--disable-service-auth-codes',
'--trace-skia', '--trace-skia',
'--trace-systrace', '--trace-systrace',
'--trace-to-file=path/to/trace.binpb',
'--verbose-system-logs', '--verbose-system-logs',
'--null-assertions', '--null-assertions',
'--native-null-assertions', '--native-null-assertions',
...@@ -434,6 +435,7 @@ void main() { ...@@ -434,6 +435,7 @@ void main() {
expect(options.disableServiceAuthCodes, true); expect(options.disableServiceAuthCodes, true);
expect(options.traceSkia, true); expect(options.traceSkia, true);
expect(options.traceSystrace, true); expect(options.traceSystrace, true);
expect(options.traceToFile, 'path/to/trace.binpb');
expect(options.verboseSystemLogs, true); expect(options.verboseSystemLogs, true);
expect(options.nullAssertions, true); expect(options.nullAssertions, true);
expect(options.nativeNullAssertions, true); expect(options.nativeNullAssertions, true);
......
...@@ -1086,6 +1086,7 @@ void main() { ...@@ -1086,6 +1086,7 @@ void main() {
'--use-test-fonts', '--use-test-fonts',
'--trace-skia', '--trace-skia',
'--trace-systrace', '--trace-systrace',
'--trace-to-file=path/to/trace.binpb',
'--verbose-system-logs', '--verbose-system-logs',
'--null-assertions', '--null-assertions',
'--native-null-assertions', '--native-null-assertions',
...@@ -1106,6 +1107,7 @@ void main() { ...@@ -1106,6 +1107,7 @@ void main() {
expect(options.useTestFonts, true); expect(options.useTestFonts, true);
expect(options.traceSkia, true); expect(options.traceSkia, true);
expect(options.traceSystrace, true); expect(options.traceSystrace, true);
expect(options.traceToFile, 'path/to/trace.binpb');
expect(options.verboseSystemLogs, true); expect(options.verboseSystemLogs, true);
expect(options.nullAssertions, true); expect(options.nullAssertions, true);
expect(options.nativeNullAssertions, true); expect(options.nativeNullAssertions, true);
......
...@@ -240,6 +240,7 @@ void main() { ...@@ -240,6 +240,7 @@ void main() {
'--es', 'trace-allowlist', 'bar,baz', '--es', 'trace-allowlist', 'bar,baz',
'--es', 'trace-skia-allowlist', 'skia.a,skia.b', '--es', 'trace-skia-allowlist', 'skia.a,skia.b',
'--ez', 'trace-systrace', 'true', '--ez', 'trace-systrace', 'true',
'--es', 'trace-to-file', 'path/to/trace.binpb',
'--ez', 'endless-trace-buffer', 'true', '--ez', 'endless-trace-buffer', 'true',
'--ez', 'dump-skp-on-shader-compilation', 'true', '--ez', 'dump-skp-on-shader-compilation', 'true',
'--ez', 'cache-sksl', 'true', '--ez', 'cache-sksl', 'true',
...@@ -271,6 +272,7 @@ void main() { ...@@ -271,6 +272,7 @@ void main() {
traceAllowlist: 'bar,baz', traceAllowlist: 'bar,baz',
traceSkiaAllowlist: 'skia.a,skia.b', traceSkiaAllowlist: 'skia.a,skia.b',
traceSystrace: true, traceSystrace: true,
traceToFile: 'path/to/trace.binpb',
endlessTraceBuffer: true, endlessTraceBuffer: true,
dumpSkpOnShaderCompilation: true, dumpSkpOnShaderCompilation: true,
cacheSkSL: true, cacheSkSL: true,
......
...@@ -151,19 +151,20 @@ void main() { ...@@ -151,19 +151,20 @@ void main() {
'FLUTTER_ENGINE_SWITCH_6': 'trace-allowlist=foo,bar', 'FLUTTER_ENGINE_SWITCH_6': 'trace-allowlist=foo,bar',
'FLUTTER_ENGINE_SWITCH_7': 'trace-skia-allowlist=skia.a,skia.b', 'FLUTTER_ENGINE_SWITCH_7': 'trace-skia-allowlist=skia.a,skia.b',
'FLUTTER_ENGINE_SWITCH_8': 'trace-systrace=true', 'FLUTTER_ENGINE_SWITCH_8': 'trace-systrace=true',
'FLUTTER_ENGINE_SWITCH_9': 'endless-trace-buffer=true', 'FLUTTER_ENGINE_SWITCH_9': 'trace-to-file=path/to/trace.binpb',
'FLUTTER_ENGINE_SWITCH_10': 'dump-skp-on-shader-compilation=true', 'FLUTTER_ENGINE_SWITCH_10': 'endless-trace-buffer=true',
'FLUTTER_ENGINE_SWITCH_11': 'cache-sksl=true', 'FLUTTER_ENGINE_SWITCH_11': 'dump-skp-on-shader-compilation=true',
'FLUTTER_ENGINE_SWITCH_12': 'purge-persistent-cache=true', 'FLUTTER_ENGINE_SWITCH_12': 'cache-sksl=true',
'FLUTTER_ENGINE_SWITCH_13': 'enable-impeller=false', 'FLUTTER_ENGINE_SWITCH_13': 'purge-persistent-cache=true',
'FLUTTER_ENGINE_SWITCH_14': 'enable-checked-mode=true', 'FLUTTER_ENGINE_SWITCH_14': 'enable-impeller=false',
'FLUTTER_ENGINE_SWITCH_15': 'verify-entry-points=true', 'FLUTTER_ENGINE_SWITCH_15': 'enable-checked-mode=true',
'FLUTTER_ENGINE_SWITCH_16': 'start-paused=true', 'FLUTTER_ENGINE_SWITCH_16': 'verify-entry-points=true',
'FLUTTER_ENGINE_SWITCH_17': 'disable-service-auth-codes=true', 'FLUTTER_ENGINE_SWITCH_17': 'start-paused=true',
'FLUTTER_ENGINE_SWITCH_18': 'dart-flags=--null_assertions', 'FLUTTER_ENGINE_SWITCH_18': 'disable-service-auth-codes=true',
'FLUTTER_ENGINE_SWITCH_19': 'use-test-fonts=true', 'FLUTTER_ENGINE_SWITCH_19': 'dart-flags=--null_assertions',
'FLUTTER_ENGINE_SWITCH_20': 'verbose-logging=true', 'FLUTTER_ENGINE_SWITCH_20': 'use-test-fonts=true',
'FLUTTER_ENGINE_SWITCHES': '20', 'FLUTTER_ENGINE_SWITCH_21': 'verbose-logging=true',
'FLUTTER_ENGINE_SWITCHES': '21',
} }
), ),
]); ]);
...@@ -185,6 +186,7 @@ void main() { ...@@ -185,6 +186,7 @@ void main() {
traceAllowlist: 'foo,bar', traceAllowlist: 'foo,bar',
traceSkiaAllowlist: 'skia.a,skia.b', traceSkiaAllowlist: 'skia.a,skia.b',
traceSystrace: true, traceSystrace: true,
traceToFile: 'path/to/trace.binpb',
endlessTraceBuffer: true, endlessTraceBuffer: true,
dumpSkpOnShaderCompilation: true, dumpSkpOnShaderCompilation: true,
cacheSkSL: true, cacheSkSL: true,
......
...@@ -814,6 +814,7 @@ void main() { ...@@ -814,6 +814,7 @@ void main() {
traceAllowlist: 'foo', traceAllowlist: 'foo',
traceSkiaAllowlist: 'skia.a,skia.b', traceSkiaAllowlist: 'skia.a,skia.b',
traceSystrace: true, traceSystrace: true,
traceToFile: 'path/to/trace.binpb',
endlessTraceBuffer: true, endlessTraceBuffer: true,
dumpSkpOnShaderCompilation: true, dumpSkpOnShaderCompilation: true,
cacheSkSL: true, cacheSkSL: true,
...@@ -846,6 +847,7 @@ void main() { ...@@ -846,6 +847,7 @@ void main() {
'--verify-entry-points', '--verify-entry-points',
'--enable-software-rendering', '--enable-software-rendering',
'--trace-systrace', '--trace-systrace',
'--trace-to-file="path/to/trace.binpb"',
'--skia-deterministic-rendering', '--skia-deterministic-rendering',
'--trace-skia', '--trace-skia',
'--trace-allowlist="foo"', '--trace-allowlist="foo"',
...@@ -994,6 +996,7 @@ void main() { ...@@ -994,6 +996,7 @@ void main() {
traceAllowlist: 'foo', traceAllowlist: 'foo',
traceSkiaAllowlist: 'skia.a,skia.b', traceSkiaAllowlist: 'skia.a,skia.b',
traceSystrace: true, traceSystrace: true,
traceToFile: 'path/to/trace.binpb',
endlessTraceBuffer: true, endlessTraceBuffer: true,
dumpSkpOnShaderCompilation: true, dumpSkpOnShaderCompilation: true,
cacheSkSL: true, cacheSkSL: true,
...@@ -1026,6 +1029,7 @@ void main() { ...@@ -1026,6 +1029,7 @@ void main() {
'--verify-entry-points', '--verify-entry-points',
'--enable-software-rendering', '--enable-software-rendering',
'--trace-systrace', '--trace-systrace',
'--trace-to-file="path/to/trace.binpb"',
'--skia-deterministic-rendering', '--skia-deterministic-rendering',
'--trace-skia', '--trace-skia',
'--trace-allowlist="foo"', '--trace-allowlist="foo"',
......
...@@ -485,6 +485,7 @@ void main() { ...@@ -485,6 +485,7 @@ void main() {
'--verify-entry-points', '--verify-entry-points',
'--enable-software-rendering', '--enable-software-rendering',
'--trace-systrace', '--trace-systrace',
'--trace-to-file="path/to/trace.binpb"',
'--skia-deterministic-rendering', '--skia-deterministic-rendering',
'--trace-skia', '--trace-skia',
'--trace-allowlist="foo"', '--trace-allowlist="foo"',
...@@ -541,6 +542,7 @@ void main() { ...@@ -541,6 +542,7 @@ void main() {
traceAllowlist: 'foo', traceAllowlist: 'foo',
traceSkiaAllowlist: 'skia.a,skia.b', traceSkiaAllowlist: 'skia.a,skia.b',
traceSystrace: true, traceSystrace: true,
traceToFile: 'path/to/trace.binpb',
endlessTraceBuffer: true, endlessTraceBuffer: true,
dumpSkpOnShaderCompilation: true, dumpSkpOnShaderCompilation: true,
cacheSkSL: true, cacheSkSL: true,
......
...@@ -1184,6 +1184,7 @@ Dec 20 17:04:32 md32-11-vm1 Another App[88374]: Ignore this text''' ...@@ -1184,6 +1184,7 @@ Dec 20 17:04:32 md32-11-vm1 Another App[88374]: Ignore this text'''
mockInfo, mockInfo,
enableSoftwareRendering: true, enableSoftwareRendering: true,
traceSystrace: true, traceSystrace: true,
traceToFile: 'path/to/trace.binpb',
startPaused: true, startPaused: true,
disableServiceAuthCodes: true, disableServiceAuthCodes: true,
skiaDeterministicRendering: true, skiaDeterministicRendering: true,
...@@ -1209,6 +1210,7 @@ Dec 20 17:04:32 md32-11-vm1 Another App[88374]: Ignore this text''' ...@@ -1209,6 +1210,7 @@ Dec 20 17:04:32 md32-11-vm1 Another App[88374]: Ignore this text'''
'--verify-entry-points', '--verify-entry-points',
'--enable-software-rendering', '--enable-software-rendering',
'--trace-systrace', '--trace-systrace',
'--trace-to-file="path/to/trace.binpb"',
'--start-paused', '--start-paused',
'--disable-service-auth-codes', '--disable-service-auth-codes',
'--skia-deterministic-rendering', '--skia-deterministic-rendering',
......
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