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

Commit 9ec68bd

Browse files
authored
Revert "Remove the global engine entry timestamp (#18182)"
This reverts commit 88b9d42.
1 parent e9f1efa commit 9ec68bd

File tree

11 files changed

+89
-36
lines changed

11 files changed

+89
-36
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,8 @@ 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
562564
FILE: ../../../flutter/runtime/test_font_data.cc
563565
FILE: ../../../flutter/runtime/test_font_data.h
564566
FILE: ../../../flutter/runtime/window_data.cc

common/settings.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <fcntl.h>
99
#include <stdint.h>
1010

11-
#include <chrono>
1211
#include <memory>
1312
#include <string>
1413
#include <vector>
@@ -208,11 +207,6 @@ struct Settings {
208207
/// https://github.com/dart-lang/sdk/blob/ca64509108b3e7219c50d6c52877c85ab6a35ff2/runtime/vm/flag_list.h#L150
209208
int64_t old_gen_heap_size = -1;
210209

211-
/// A timestamp representing when the engine started. The value is based
212-
/// on the clock used by the Dart timeline APIs. This timestamp is used
213-
/// to log a timeline event that tracks the latency of engine startup.
214-
std::chrono::microseconds engine_start_timestamp = {};
215-
216210
std::string ToString() const;
217211
};
218212

runtime/BUILD.gn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ 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",
7375
"window_data.cc",
7476
"window_data.h",
7577
]

runtime/dart_vm.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
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"
2829
#include "third_party/dart/runtime/include/bin/dart_io_api.h"
2930
#include "third_party/skia/include/core/SkExecutor.h"
3031
#include "third_party/tonic/converter/dart_converter.h"
@@ -425,15 +426,14 @@ DartVM::DartVM(std::shared_ptr<const DartVMData> vm_data,
425426
// the very first frame gives us a good idea about Flutter's startup time.
426427
// Use a duration event so about:tracing will consider this event when
427428
// deciding the earliest event to use as time 0.
428-
if (settings_.engine_start_timestamp.count()) {
429-
Dart_TimelineEvent(
430-
"FlutterEngineMainEnter", // label
431-
settings_.engine_start_timestamp.count(), // timestamp0
432-
Dart_TimelineGetMicros(), // timestamp1_or_async_id
433-
Dart_Timeline_Event_Duration, // event type
434-
0, // argument_count
435-
nullptr, // argument_names
436-
nullptr // argument_values
429+
if (engine_main_enter_ts != 0) {
430+
Dart_TimelineEvent("FlutterEngineMainEnter", // label
431+
engine_main_enter_ts, // timestamp0
432+
Dart_TimelineGetMicros(), // timestamp1_or_async_id
433+
Dart_Timeline_Event_Duration, // event type
434+
0, // argument_count
435+
nullptr, // argument_names
436+
nullptr // argument_values
437437
);
438438
}
439439
}

runtime/start_up.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "flutter/runtime/start_up.h"
6+
7+
namespace flutter {
8+
9+
int64_t engine_main_enter_ts = 0;
10+
11+
} // namespace flutter

runtime/start_up.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#ifndef FLUTTER_RUNTIME_START_UP_H_
6+
#define FLUTTER_RUNTIME_START_UP_H_
7+
8+
#include <stdint.h>
9+
10+
namespace flutter {
11+
12+
// The earliest available timestamp in the application's lifecycle. The
13+
// difference between this timestamp and the time we render the very first
14+
// frame gives us a good idea about Flutter's startup time.
15+
//
16+
// This timestamp only covers Flutter's own startup. In an upside-down model
17+
// it is possible that the first Flutter view is not initialized until some
18+
// time later. In this case the timestamp may not cover the time spent in the
19+
// user code prior to initializing Flutter.
20+
extern int64_t engine_main_enter_ts;
21+
22+
} // namespace flutter
23+
24+
#endif // FLUTTER_RUNTIME_START_UP_H_

shell/common/shell.cc

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
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"
2324
#include "flutter/shell/common/engine.h"
2425
#include "flutter/shell/common/persistent_cache.h"
2526
#include "flutter/shell/common/skia_event_tracer_impl.h"
@@ -174,6 +175,12 @@ std::unique_ptr<Shell> Shell::CreateShellOnPlatformThread(
174175
return shell;
175176
}
176177

178+
static void RecordStartupTimestamp() {
179+
if (engine_main_enter_ts == 0) {
180+
engine_main_enter_ts = Dart_TimelineGetMicros();
181+
}
182+
}
183+
177184
static void Tokenize(const std::string& input,
178185
std::vector<std::string>* results,
179186
char delimiter) {
@@ -190,7 +197,7 @@ static void Tokenize(const std::string& input,
190197
// TODO(chinmaygarde): The unfortunate side effect of this call is that settings
191198
// that cause shell initialization failures will still lead to some of their
192199
// settings being applied.
193-
static void PerformInitializationTasks(Settings& settings) {
200+
static void PerformInitializationTasks(const Settings& settings) {
194201
{
195202
fml::LogSettings log_settings;
196203
log_settings.min_log_level =
@@ -200,10 +207,7 @@ static void PerformInitializationTasks(Settings& settings) {
200207

201208
static std::once_flag gShellSettingsInitialization = {};
202209
std::call_once(gShellSettingsInitialization, [&settings] {
203-
if (settings.engine_start_timestamp.count() == 0) {
204-
settings.engine_start_timestamp =
205-
std::chrono::microseconds(Dart_TimelineGetMicros());
206-
}
210+
RecordStartupTimestamp();
207211

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

shell/platform/android/flutter_main.cc

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
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"
2122
#include "flutter/shell/common/shell.h"
2223
#include "flutter/shell/common/switches.h"
2324
#include "third_party/dart/runtime/include/dart_tools_api.h"
@@ -61,8 +62,7 @@ void FlutterMain::Init(JNIEnv* env,
6162
jobjectArray jargs,
6263
jstring kernelPath,
6364
jstring appStoragePath,
64-
jstring engineCachesPath,
65-
jlong initTimeMillis) {
65+
jstring engineCachesPath) {
6666
std::vector<std::string> args;
6767
args.push_back("flutter");
6868
for (auto& arg : fml::jni::StringArrayToVector(env, jargs)) {
@@ -72,10 +72,6 @@ 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 =
77-
std::chrono::microseconds(Dart_TimelineGetMicros() - init_time_micros);
78-
7975
// Restore the callback cache.
8076
// TODO(chinmaygarde): Route all cache file access through FML and remove this
8177
// setter.
@@ -155,14 +151,27 @@ void FlutterMain::SetupObservatoryUriCallback(JNIEnv* env) {
155151
});
156152
}
157153

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+
158162
bool FlutterMain::Register(JNIEnv* env) {
159163
static const JNINativeMethod methods[] = {
160164
{
161165
.name = "nativeInit",
162166
.signature = "(Landroid/content/Context;[Ljava/lang/String;Ljava/"
163-
"lang/String;Ljava/lang/String;Ljava/lang/String;J)V",
167+
"lang/String;Ljava/lang/String;Ljava/lang/String;)V",
164168
.fnPtr = reinterpret_cast<void*>(&Init),
165169
},
170+
{
171+
.name = "nativeRecordStartTimestamp",
172+
.signature = "(J)V",
173+
.fnPtr = reinterpret_cast<void*>(&RecordStartTimestamp),
174+
},
166175
};
167176

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

shell/platform/android/flutter_main.h

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

4140
void SetupObservatoryUriCallback(JNIEnv* env);
4241

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

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

109111
// TODO(mattcarroll): add javadocs
110112
@UiThread

0 commit comments

Comments
 (0)