Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 5cb7ffd

Browse files
committed
Remove the global engine entry timestamp
The engine was using a global to store a timestamp representing the launch of the engine. This timestamp is initialized with a JNI call on Android and during shell setup on other platforms. Later the timestamp is added to a FlutterEngineMainEnter timeline event used to measure engine startup time in benchmarks. This PR removes the global and the JNI call and moves the timestamp into the settings object.
1 parent c3cd83b commit 5cb7ffd

File tree

11 files changed

+28
-84
lines changed

11 files changed

+28
-84
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,8 +559,6 @@ FILE: ../../../flutter/runtime/service_protocol.cc
559559
FILE: ../../../flutter/runtime/service_protocol.h
560560
FILE: ../../../flutter/runtime/skia_concurrent_executor.cc
561561
FILE: ../../../flutter/runtime/skia_concurrent_executor.h
562-
FILE: ../../../flutter/runtime/start_up.cc
563-
FILE: ../../../flutter/runtime/start_up.h
564562
FILE: ../../../flutter/runtime/test_font_data.cc
565563
FILE: ../../../flutter/runtime/test_font_data.h
566564
FILE: ../../../flutter/runtime/window_data.cc

common/settings.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,12 @@ struct Settings {
207207
/// https://github.com/dart-lang/sdk/blob/ca64509108b3e7219c50d6c52877c85ab6a35ff2/runtime/vm/flag_list.h#L150
208208
int64_t old_gen_heap_size = -1;
209209

210+
/// A timestamp representing when the engine started. The value is in
211+
/// microseconds based on the clock used by the Dart timeline APIs. This
212+
/// timestamp is used to log a timeline event that tracks the latency of
213+
/// engine startup.
214+
int64_t engine_start_timestamp = 0;
215+
210216
std::string ToString() const;
211217
};
212218

runtime/BUILD.gn

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ source_set("runtime") {
7070
"service_protocol.h",
7171
"skia_concurrent_executor.cc",
7272
"skia_concurrent_executor.h",
73-
"start_up.cc",
74-
"start_up.h",
7573
"window_data.cc",
7674
"window_data.h",
7775
]

runtime/dart_vm.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include "flutter/runtime/dart_isolate.h"
2626
#include "flutter/runtime/dart_service_isolate.h"
2727
#include "flutter/runtime/ptrace_ios.h"
28-
#include "flutter/runtime/start_up.h"
2928
#include "third_party/dart/runtime/include/bin/dart_io_api.h"
3029
#include "third_party/skia/include/core/SkExecutor.h"
3130
#include "third_party/tonic/converter/dart_converter.h"
@@ -426,9 +425,9 @@ DartVM::DartVM(std::shared_ptr<const DartVMData> vm_data,
426425
// the very first frame gives us a good idea about Flutter's startup time.
427426
// Use a duration event so about:tracing will consider this event when
428427
// deciding the earliest event to use as time 0.
429-
if (engine_main_enter_ts != 0) {
430-
Dart_TimelineEvent("FlutterEngineMainEnter", // label
431-
engine_main_enter_ts, // timestamp0
428+
if (settings_.engine_start_timestamp != 0) {
429+
Dart_TimelineEvent("FlutterEngineMainEnter", // label
430+
settings_.engine_start_timestamp, // timestamp0
432431
Dart_TimelineGetMicros(), // timestamp1_or_async_id
433432
Dart_Timeline_Event_Duration, // event type
434433
0, // argument_count

runtime/start_up.cc

Lines changed: 0 additions & 11 deletions
This file was deleted.

runtime/start_up.h

Lines changed: 0 additions & 24 deletions
This file was deleted.

shell/common/shell.cc

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "flutter/fml/trace_event.h"
2121
#include "flutter/fml/unique_fd.h"
2222
#include "flutter/runtime/dart_vm.h"
23-
#include "flutter/runtime/start_up.h"
2423
#include "flutter/shell/common/engine.h"
2524
#include "flutter/shell/common/persistent_cache.h"
2625
#include "flutter/shell/common/skia_event_tracer_impl.h"
@@ -175,12 +174,6 @@ std::unique_ptr<Shell> Shell::CreateShellOnPlatformThread(
175174
return shell;
176175
}
177176

178-
static void RecordStartupTimestamp() {
179-
if (engine_main_enter_ts == 0) {
180-
engine_main_enter_ts = Dart_TimelineGetMicros();
181-
}
182-
}
183-
184177
static void Tokenize(const std::string& input,
185178
std::vector<std::string>* results,
186179
char delimiter) {
@@ -197,7 +190,7 @@ static void Tokenize(const std::string& input,
197190
// TODO(chinmaygarde): The unfortunate side effect of this call is that settings
198191
// that cause shell initialization failures will still lead to some of their
199192
// settings being applied.
200-
static void PerformInitializationTasks(const Settings& settings) {
193+
static void PerformInitializationTasks(Settings& settings) {
201194
{
202195
fml::LogSettings log_settings;
203196
log_settings.min_log_level =
@@ -207,7 +200,9 @@ static void PerformInitializationTasks(const Settings& settings) {
207200

208201
static std::once_flag gShellSettingsInitialization = {};
209202
std::call_once(gShellSettingsInitialization, [&settings] {
210-
RecordStartupTimestamp();
203+
if (settings.engine_start_timestamp == 0) {
204+
settings.engine_start_timestamp = Dart_TimelineGetMicros();
205+
}
211206

212207
tonic::SetLogHandler(
213208
[](const char* message) { FML_LOG(ERROR) << message; });

shell/platform/android/flutter_main.cc

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "flutter/fml/size.h"
1919
#include "flutter/lib/ui/plugins/callback_cache.h"
2020
#include "flutter/runtime/dart_vm.h"
21-
#include "flutter/runtime/start_up.h"
2221
#include "flutter/shell/common/shell.h"
2322
#include "flutter/shell/common/switches.h"
2423
#include "third_party/dart/runtime/include/dart_tools_api.h"
@@ -62,7 +61,8 @@ void FlutterMain::Init(JNIEnv* env,
6261
jobjectArray jargs,
6362
jstring kernelPath,
6463
jstring appStoragePath,
65-
jstring engineCachesPath) {
64+
jstring engineCachesPath,
65+
jlong initTimeMillis) {
6666
std::vector<std::string> args;
6767
args.push_back("flutter");
6868
for (auto& arg : fml::jni::StringArrayToVector(env, jargs)) {
@@ -72,6 +72,9 @@ void FlutterMain::Init(JNIEnv* env,
7272

7373
auto settings = SettingsFromCommandLine(command_line);
7474

75+
int64_t init_time_micros = initTimeMillis * 1000;
76+
settings.engine_start_timestamp = Dart_TimelineGetMicros() - init_time_micros;
77+
7578
// Restore the callback cache.
7679
// TODO(chinmaygarde): Route all cache file access through FML and remove this
7780
// setter.
@@ -151,27 +154,14 @@ void FlutterMain::SetupObservatoryUriCallback(JNIEnv* env) {
151154
});
152155
}
153156

154-
static void RecordStartTimestamp(JNIEnv* env,
155-
jclass jcaller,
156-
jlong initTimeMillis) {
157-
int64_t initTimeMicros =
158-
static_cast<int64_t>(initTimeMillis) * static_cast<int64_t>(1000);
159-
flutter::engine_main_enter_ts = Dart_TimelineGetMicros() - initTimeMicros;
160-
}
161-
162157
bool FlutterMain::Register(JNIEnv* env) {
163158
static const JNINativeMethod methods[] = {
164159
{
165160
.name = "nativeInit",
166161
.signature = "(Landroid/content/Context;[Ljava/lang/String;Ljava/"
167-
"lang/String;Ljava/lang/String;Ljava/lang/String;)V",
162+
"lang/String;Ljava/lang/String;Ljava/lang/String;J)V",
168163
.fnPtr = reinterpret_cast<void*>(&Init),
169164
},
170-
{
171-
.name = "nativeRecordStartTimestamp",
172-
.signature = "(J)V",
173-
.fnPtr = reinterpret_cast<void*>(&RecordStartTimestamp),
174-
},
175165
};
176166

177167
jclass clazz = env->FindClass("io/flutter/embedding/engine/FlutterJNI");

shell/platform/android/flutter_main.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ class FlutterMain {
3535
jobjectArray jargs,
3636
jstring kernelPath,
3737
jstring appStoragePath,
38-
jstring engineCachesPath);
38+
jstring engineCachesPath,
39+
jlong initTimeMillis);
3940

4041
void SetupObservatoryUriCallback(JNIEnv* env);
4142

shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,8 @@ public static native void nativeInit(
103103
@NonNull String[] args,
104104
@Nullable String bundlePath,
105105
@NonNull String appStoragePath,
106-
@NonNull String engineCachesPath);
107-
108-
// TODO(mattcarroll): add javadocs
109-
public static native void nativeRecordStartTimestamp(long initTimeMillis);
106+
@NonNull String engineCachesPath,
107+
long initTimeMillis);
110108

111109
// TODO(mattcarroll): add javadocs
112110
@UiThread

0 commit comments

Comments
 (0)