From e361547b05d3bd85d616163e2c7bde3c253cad7c Mon Sep 17 00:00:00 2001 From: Chinmay Garde Date: Mon, 28 Jan 2019 17:39:31 -0800 Subject: [PATCH] Allow the engine to redirect traces to systrace via settings. (flutter/engine#7617) --- engine/src/flutter/common/settings.h | 1 + engine/src/flutter/runtime/dart_vm.cc | 14 ++++++++++++++ engine/src/flutter/shell/common/switches.cc | 2 ++ engine/src/flutter/shell/common/switches.h | 6 ++++++ .../io/flutter/app/FlutterActivityDelegate.java | 3 +++ 5 files changed, 26 insertions(+) diff --git a/engine/src/flutter/common/settings.h b/engine/src/flutter/common/settings.h index e6a79b6e06..d131695f4b 100644 --- a/engine/src/flutter/common/settings.h +++ b/engine/src/flutter/common/settings.h @@ -59,6 +59,7 @@ struct Settings { bool start_paused = false; bool trace_skia = false; bool trace_startup = false; + bool trace_systrace = false; bool endless_trace_buffer = false; bool enable_dart_profiling = false; bool disable_dart_asserts = false; diff --git a/engine/src/flutter/runtime/dart_vm.cc b/engine/src/flutter/runtime/dart_vm.cc index 795a424bb9..382ab05c34 100644 --- a/engine/src/flutter/runtime/dart_vm.cc +++ b/engine/src/flutter/runtime/dart_vm.cc @@ -90,8 +90,15 @@ static const char* kDartEndlessTraceBufferArgs[]{ "--timeline_recorder=endless", }; +static const char* kDartSystraceTraceBufferArgs[]{ + "--timeline_recorder=systrace", +}; + static const char* kDartFuchsiaTraceArgs[] FML_ALLOW_UNUSED_TYPE = { "--systrace_timeline", +}; + +static const char* kDartTraceStreamsArgs[] = { "--timeline_streams=Compiler,Dart,Debugger,Embedder,GC,Isolate,VM", }; @@ -361,12 +368,19 @@ DartVM::DartVM(const Settings& settings, arraysize(kDartEndlessTraceBufferArgs)); } + if (settings.trace_systrace) { + PushBackAll(&args, kDartSystraceTraceBufferArgs, + arraysize(kDartSystraceTraceBufferArgs)); + PushBackAll(&args, kDartTraceStreamsArgs, arraysize(kDartTraceStreamsArgs)); + } + if (settings.trace_startup) { PushBackAll(&args, kDartTraceStartupArgs, arraysize(kDartTraceStartupArgs)); } #if defined(OS_FUCHSIA) PushBackAll(&args, kDartFuchsiaTraceArgs, arraysize(kDartFuchsiaTraceArgs)); + PushBackAll(&args, kDartTraceStreamsArgs, arraysize(kDartTraceStreamsArgs)); #endif for (size_t i = 0; i < settings.dart_flags.size(); i++) diff --git a/engine/src/flutter/shell/common/switches.cc b/engine/src/flutter/shell/common/switches.cc index 8b17a01729..295118bfec 100644 --- a/engine/src/flutter/shell/common/switches.cc +++ b/engine/src/flutter/shell/common/switches.cc @@ -231,6 +231,8 @@ blink::Settings SettingsFromCommandLine(const fml::CommandLine& command_line) { FLUTTER_RUNTIME_MODE != FLUTTER_RUNTIME_MODE_DYNAMIC_RELEASE settings.trace_skia = command_line.HasOption(FlagForSwitch(Switch::TraceSkia)); + settings.trace_systrace = + command_line.HasOption(FlagForSwitch(Switch::TraceSystrace)); #endif return settings; diff --git a/engine/src/flutter/shell/common/switches.h b/engine/src/flutter/shell/common/switches.h index 829ae9c04f..b278e32d6f 100644 --- a/engine/src/flutter/shell/common/switches.h +++ b/engine/src/flutter/shell/common/switches.h @@ -104,6 +104,12 @@ DEF_SWITCH(TraceSkia, "Trace Skia calls. This is useful when debugging the GPU threed." "By default, Skia tracing is not enable to reduce the number of " "traced events") +DEF_SWITCH( + TraceSystrace, + "trace-systrace", + "Trace to the system tracer (instead of the timeline) on platforms where " + "such a tracer is available. Currently only supported on Android and " + "Fuchsia.") DEF_SWITCH(UseTestFonts, "use-test-fonts", "Running tests that layout and measure text will not yield " diff --git a/engine/src/flutter/shell/platform/android/io/flutter/app/FlutterActivityDelegate.java b/engine/src/flutter/shell/platform/android/io/flutter/app/FlutterActivityDelegate.java index ea44ae4ba5..5f56699360 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/app/FlutterActivityDelegate.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/app/FlutterActivityDelegate.java @@ -312,6 +312,9 @@ public final class FlutterActivityDelegate if (intent.getBooleanExtra("trace-skia", false)) { args.add("--trace-skia"); } + if (intent.getBooleanExtra("trace-systrace", false)) { + args.add("--trace-systrace"); + } if (intent.getBooleanExtra("verbose-logging", false)) { args.add("--verbose-logging"); }