From ac334e5c2cc2b0fdce91700e54bcf31b3cfcc761 Mon Sep 17 00:00:00 2001 From: schectman Date: Tue, 23 Aug 2022 17:12:11 -0400 Subject: [PATCH 1/5] Engine startup event timed after VM initializes --- runtime/dart_vm.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/runtime/dart_vm.cc b/runtime/dart_vm.cc index fc5dded31462f..42f28955dcefc 100644 --- a/runtime/dart_vm.cc +++ b/runtime/dart_vm.cc @@ -470,11 +470,12 @@ DartVM::DartVM(std::shared_ptr vm_data, // Use a duration event so about:tracing will consider this event when // deciding the earliest event to use as time 0. if (settings_.engine_start_timestamp.count()) { + int64_t micros = Dart_TimelineGetMicros(); Dart_TimelineEvent( "FlutterEngineMainEnter", // label - settings_.engine_start_timestamp.count(), // timestamp0 - Dart_TimelineGetMicros(), // timestamp1_or_async_id - Dart_Timeline_Event_Duration, // event type + micros, // timestamp0 + micros, // timestamp1_or_async_id + Dart_Timeline_Event_Instant, // event type 0, // argument_count nullptr, // argument_names nullptr // argument_values From e2d0691b971a8f3760a854ed8ab641f114242d98 Mon Sep 17 00:00:00 2001 From: schectman Date: Thu, 25 Aug 2022 17:01:23 -0400 Subject: [PATCH 2/5] Formatting --- runtime/dart_vm.cc | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/runtime/dart_vm.cc b/runtime/dart_vm.cc index 42f28955dcefc..76e964751fea4 100644 --- a/runtime/dart_vm.cc +++ b/runtime/dart_vm.cc @@ -471,14 +471,13 @@ DartVM::DartVM(std::shared_ptr vm_data, // deciding the earliest event to use as time 0. if (settings_.engine_start_timestamp.count()) { int64_t micros = Dart_TimelineGetMicros(); - Dart_TimelineEvent( - "FlutterEngineMainEnter", // label - micros, // timestamp0 - micros, // timestamp1_or_async_id - Dart_Timeline_Event_Instant, // event type - 0, // argument_count - nullptr, // argument_names - nullptr // argument_values + Dart_TimelineEvent("FlutterEngineMainEnter", // label + micros, // timestamp0 + micros, // timestamp1_or_async_id + Dart_Timeline_Event_Instant, // event type + 0, // argument_count + nullptr, // argument_names + nullptr // argument_values ); } } From a4f0dc8a78ba6a1febf14040965f26da9f1189a4 Mon Sep 17 00:00:00 2001 From: yaakovschectman <109111084+yaakovschectman@users.noreply.github.com> Date: Fri, 26 Aug 2022 09:49:45 -0400 Subject: [PATCH 3/5] Update FlutterEngineMainEnter event comment --- runtime/dart_vm.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/runtime/dart_vm.cc b/runtime/dart_vm.cc index 76e964751fea4..0f98ce947d964 100644 --- a/runtime/dart_vm.cc +++ b/runtime/dart_vm.cc @@ -467,8 +467,10 @@ DartVM::DartVM(std::shared_ptr vm_data, // Send the earliest available timestamp in the application lifecycle to // timeline. The difference between this timestamp and the time we render // the very first frame gives us a good idea about Flutter's startup time. - // Use a duration event so about:tracing will consider this event when - // deciding the earliest event to use as time 0. + // Use an instant event because the call to Dart_TimelineGetMicros + // may behave differently before and after the Dart VM is initialized. + // As this call is immediately after initialization of the Dart VM, + // we are interested in only one timestamp. if (settings_.engine_start_timestamp.count()) { int64_t micros = Dart_TimelineGetMicros(); Dart_TimelineEvent("FlutterEngineMainEnter", // label From a11e0a4d6ffa2deead8de1d1e4637b18a55be6ee Mon Sep 17 00:00:00 2001 From: schectman Date: Tue, 30 Aug 2022 09:21:12 -0400 Subject: [PATCH 4/5] Remove engine_start_time --- common/settings.h | 5 ----- runtime/dart_vm.cc | 20 +++++++++----------- shell/common/shell.cc | 5 ----- shell/platform/android/flutter_main.cc | 2 -- 4 files changed, 9 insertions(+), 23 deletions(-) diff --git a/common/settings.h b/common/settings.h index 8a12ebb98f055..39017dbc1cd40 100644 --- a/common/settings.h +++ b/common/settings.h @@ -301,11 +301,6 @@ struct Settings { // Max bytes threshold of resource cache, or 0 for unlimited. size_t resource_cache_max_bytes_threshold = 0; - /// A timestamp representing when the engine started. The value is based - /// on the clock used by the Dart timeline APIs. This timestamp is used - /// to log a timeline event that tracks the latency of engine startup. - std::chrono::microseconds engine_start_timestamp = {}; - /// The minimum number of samples to require in multipsampled anti-aliasing. /// /// Setting this value to 0 or 1 disables MSAA. diff --git a/runtime/dart_vm.cc b/runtime/dart_vm.cc index 0f98ce947d964..7eed4ed81dd21 100644 --- a/runtime/dart_vm.cc +++ b/runtime/dart_vm.cc @@ -471,17 +471,15 @@ DartVM::DartVM(std::shared_ptr vm_data, // may behave differently before and after the Dart VM is initialized. // As this call is immediately after initialization of the Dart VM, // we are interested in only one timestamp. - if (settings_.engine_start_timestamp.count()) { - int64_t micros = Dart_TimelineGetMicros(); - Dart_TimelineEvent("FlutterEngineMainEnter", // label - micros, // timestamp0 - micros, // timestamp1_or_async_id - Dart_Timeline_Event_Instant, // event type - 0, // argument_count - nullptr, // argument_names - nullptr // argument_values - ); - } + int64_t micros = Dart_TimelineGetMicros(); + Dart_TimelineEvent("FlutterEngineMainEnter", // label + micros, // timestamp0 + micros, // timestamp1_or_async_id + Dart_Timeline_Event_Instant, // event type + 0, // argument_count + nullptr, // argument_names + nullptr // argument_values + ); } Dart_SetFileModifiedCallback(&DartFileModifiedCallback); diff --git a/shell/common/shell.cc b/shell/common/shell.cc index 25ad7d7f94332..50f81d8d57b92 100644 --- a/shell/common/shell.cc +++ b/shell/common/shell.cc @@ -84,11 +84,6 @@ void PerformInitializationTasks(Settings& settings) { static std::once_flag gShellSettingsInitialization = {}; std::call_once(gShellSettingsInitialization, [&settings] { - if (settings.engine_start_timestamp.count() == 0) { - settings.engine_start_timestamp = - std::chrono::microseconds(Dart_TimelineGetMicros()); - } - tonic::SetLogHandler( [](const char* message) { FML_LOG(ERROR) << message; }); diff --git a/shell/platform/android/flutter_main.cc b/shell/platform/android/flutter_main.cc index 929b00fdab7c9..c76cea8c3ce2e 100644 --- a/shell/platform/android/flutter_main.cc +++ b/shell/platform/android/flutter_main.cc @@ -112,8 +112,6 @@ void FlutterMain::Init(JNIEnv* env, #endif // FLUTTER_RELEASE int64_t init_time_micros = initTimeMillis * 1000; - settings.engine_start_timestamp = - std::chrono::microseconds(Dart_TimelineGetMicros() - init_time_micros); // Restore the callback cache. // TODO(chinmaygarde): Route all cache file access through FML and remove this From f53100c2c778f332860c66bbc4d8a736f9f9d336 Mon Sep 17 00:00:00 2001 From: schectman Date: Tue, 30 Aug 2022 10:18:00 -0400 Subject: [PATCH 5/5] Remove unused variable --- runtime/dart_vm.cc | 12 ++++++------ shell/platform/android/flutter_main.cc | 2 -- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/runtime/dart_vm.cc b/runtime/dart_vm.cc index 7eed4ed81dd21..829e4be21f26f 100644 --- a/runtime/dart_vm.cc +++ b/runtime/dart_vm.cc @@ -473,12 +473,12 @@ DartVM::DartVM(std::shared_ptr vm_data, // we are interested in only one timestamp. int64_t micros = Dart_TimelineGetMicros(); Dart_TimelineEvent("FlutterEngineMainEnter", // label - micros, // timestamp0 - micros, // timestamp1_or_async_id - Dart_Timeline_Event_Instant, // event type - 0, // argument_count - nullptr, // argument_names - nullptr // argument_values + micros, // timestamp0 + micros, // timestamp1_or_async_id + Dart_Timeline_Event_Instant, // event type + 0, // argument_count + nullptr, // argument_names + nullptr // argument_values ); } diff --git a/shell/platform/android/flutter_main.cc b/shell/platform/android/flutter_main.cc index c76cea8c3ce2e..99c7d052df26d 100644 --- a/shell/platform/android/flutter_main.cc +++ b/shell/platform/android/flutter_main.cc @@ -111,8 +111,6 @@ void FlutterMain::Init(JNIEnv* env, settings.enable_timeline_event_handler = settings.trace_systrace; #endif // FLUTTER_RELEASE - int64_t init_time_micros = initTimeMillis * 1000; - // Restore the callback cache. // TODO(chinmaygarde): Route all cache file access through FML and remove this // setter.