diff --git a/engine/src/flutter/common/settings.h b/engine/src/flutter/common/settings.h index 7fe3f9b8bd3..5f6805f1ee9 100644 --- a/engine/src/flutter/common/settings.h +++ b/engine/src/flutter/common/settings.h @@ -20,6 +20,7 @@ struct Settings { bool start_paused = false; bool trace_startup = false; bool endless_trace_buffer = false; + bool enable_dart_profiling = false; std::string aot_snapshot_path; std::string aot_isolate_snapshot_file_name; std::string aot_vm_isolate_snapshot_file_name; diff --git a/engine/src/flutter/runtime/dart_init.cc b/engine/src/flutter/runtime/dart_init.cc index f277b692545..3d68a60794f 100644 --- a/engine/src/flutter/runtime/dart_init.cc +++ b/engine/src/flutter/runtime/dart_init.cc @@ -78,24 +78,6 @@ const char kSnapshotAssetKey[] = "snapshot_blob.bin"; namespace { -static const char* kDartProfilingArgs[] = { - // Dart assumes ARM devices are insufficiently powerful and sets the - // default profile period to 100Hz. This number is suitable for older - // Raspberry Pi devices but quite low for current smartphones. - "--profile_period=1000", - // Disable Dart's built in profiler when building a debug build. This - // works around a race condition that would sometimes stop a crash's - // stack trace from being printed on Android. -#ifndef NDEBUG - "--no-profiler", -#endif -#if (WTF_OS_IOS || WTF_OS_MACOSX) - // On platforms where LLDB is the primary debugger, SIGPROF signals - // overwhelm LLDB. - "--no-profiler", -#endif -}; - static const char* kDartMirrorsArgs[] = { "--enable_mirrors=false", }; @@ -555,6 +537,30 @@ static void EmbedderTimelineStopRecording() { g_tracing_callbacks->stop_tracing_callback(); } +static std::vector ProfilingFlags(bool enable_profiling) { +// Disable Dart's built in profiler when building a debug build. This +// works around a race condition that would sometimes stop a crash's +// stack trace from being printed on Android. +#ifndef NDEBUG + enable_profiling = false; +#endif + + // We want to disable profiling by default because it overwhelms LLDB. But + // the VM enables the same by default. In either case, we have some profiling + // flags. + if (enable_profiling) { + return { + // Dart assumes ARM devices are insufficiently powerful and sets the + // default profile period to 100Hz. This number is suitable for older + // Raspberry Pi devices but quite low for current smartphones. + "--profile_period=1000", + // This is the default. But just be explicit. + "--profiler"}; + } else { + return {"--no-profiler"}; + } +} + void SetServiceIsolateHook(ServiceIsolateHook hook) { FTL_CHECK(!g_service_isolate_initialized); g_service_isolate_hook = hook; @@ -596,7 +602,11 @@ void InitDartVM() { // it does not recognize, it exits immediately. args.push_back("--ignore-unrecognized-flags"); - PushBackAll(&args, kDartProfilingArgs, arraysize(kDartProfilingArgs)); + for (const auto& profiler_flag : + ProfilingFlags(settings.enable_dart_profiling)) { + args.push_back(profiler_flag); + } + PushBackAll(&args, kDartMirrorsArgs, arraysize(kDartMirrorsArgs)); PushBackAll(&args, kDartBackgroundCompilationArgs, arraysize(kDartBackgroundCompilationArgs)); diff --git a/engine/src/flutter/shell/common/shell.cc b/engine/src/flutter/shell/common/shell.cc index 9c76f0bcb86..889dca26c5b 100644 --- a/engine/src/flutter/shell/common/shell.cc +++ b/engine/src/flutter/shell/common/shell.cc @@ -144,6 +144,8 @@ void Shell::InitStandalone(std::string icu_data_path) { } } settings.start_paused = command_line.HasSwitch(switches::kStartPaused); + settings.enable_dart_profiling = + command_line.HasSwitch(switches::kEnableDartProfiling); settings.endless_trace_buffer = command_line.HasSwitch(switches::kEndlessTraceBuffer); settings.trace_startup = command_line.HasSwitch(switches::kTraceStartup); diff --git a/engine/src/flutter/shell/common/switches.cc b/engine/src/flutter/shell/common/switches.cc index 7e1e207f90f..42cde82d796 100644 --- a/engine/src/flutter/shell/common/switches.cc +++ b/engine/src/flutter/shell/common/switches.cc @@ -18,6 +18,7 @@ const char kCacheDirPath[] = "cache-dir-path"; const char kDartFlags[] = "dart-flags"; const char kDeviceObservatoryPort[] = "observatory-port"; const char kDisableObservatory[] = "disable-observatory"; +const char kEnableDartProfiling[] = "enable-dart-profiling"; const char kEndlessTraceBuffer[] = "endless-trace-buffer"; const char kFLX[] = "flx"; const char kHelp[] = "help"; diff --git a/engine/src/flutter/shell/common/switches.h b/engine/src/flutter/shell/common/switches.h index 0f7c15a0cbb..d27a1d1f7fb 100644 --- a/engine/src/flutter/shell/common/switches.h +++ b/engine/src/flutter/shell/common/switches.h @@ -19,6 +19,7 @@ extern const char kCacheDirPath[]; extern const char kDartFlags[]; extern const char kDeviceObservatoryPort[]; extern const char kDisableObservatory[]; +extern const char kEnableDartProfiling[]; extern const char kEndlessTraceBuffer[]; extern const char kFLX[]; extern const char kHelp[];