Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -559,8 +559,6 @@ FILE: ../../../flutter/runtime/service_protocol.cc
FILE: ../../../flutter/runtime/service_protocol.h
FILE: ../../../flutter/runtime/skia_concurrent_executor.cc
FILE: ../../../flutter/runtime/skia_concurrent_executor.h
FILE: ../../../flutter/runtime/start_up.cc
FILE: ../../../flutter/runtime/start_up.h
FILE: ../../../flutter/runtime/test_font_data.cc
FILE: ../../../flutter/runtime/test_font_data.h
FILE: ../../../flutter/runtime/window_data.cc
Expand Down
6 changes: 6 additions & 0 deletions common/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <fcntl.h>
#include <stdint.h>

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

/// 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 = {};

std::string ToString() const;
};

Expand Down
2 changes: 0 additions & 2 deletions runtime/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ source_set("runtime") {
"service_protocol.h",
"skia_concurrent_executor.cc",
"skia_concurrent_executor.h",
"start_up.cc",
"start_up.h",
"window_data.cc",
"window_data.h",
]
Expand Down
18 changes: 9 additions & 9 deletions runtime/dart_vm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include "flutter/runtime/dart_isolate.h"
#include "flutter/runtime/dart_service_isolate.h"
#include "flutter/runtime/ptrace_ios.h"
#include "flutter/runtime/start_up.h"
#include "third_party/dart/runtime/include/bin/dart_io_api.h"
#include "third_party/skia/include/core/SkExecutor.h"
#include "third_party/tonic/converter/dart_converter.h"
Expand Down Expand Up @@ -426,14 +425,15 @@ DartVM::DartVM(std::shared_ptr<const DartVMData> vm_data,
// 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.
if (engine_main_enter_ts != 0) {
Dart_TimelineEvent("FlutterEngineMainEnter", // label
engine_main_enter_ts, // timestamp0
Dart_TimelineGetMicros(), // timestamp1_or_async_id
Dart_Timeline_Event_Duration, // event type
0, // argument_count
nullptr, // argument_names
nullptr // argument_values
if (settings_.engine_start_timestamp.count()) {
Dart_TimelineEvent(
"FlutterEngineMainEnter", // label
settings_.engine_start_timestamp.count(), // timestamp0
Dart_TimelineGetMicros(), // timestamp1_or_async_id
Dart_Timeline_Event_Duration, // event type
0, // argument_count
nullptr, // argument_names
nullptr // argument_values
);
}
}
Expand Down
11 changes: 0 additions & 11 deletions runtime/start_up.cc

This file was deleted.

24 changes: 0 additions & 24 deletions runtime/start_up.h

This file was deleted.

14 changes: 5 additions & 9 deletions shell/common/shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "flutter/fml/trace_event.h"
#include "flutter/fml/unique_fd.h"
#include "flutter/runtime/dart_vm.h"
#include "flutter/runtime/start_up.h"
#include "flutter/shell/common/engine.h"
#include "flutter/shell/common/persistent_cache.h"
#include "flutter/shell/common/skia_event_tracer_impl.h"
Expand Down Expand Up @@ -175,12 +174,6 @@ std::unique_ptr<Shell> Shell::CreateShellOnPlatformThread(
return shell;
}

static void RecordStartupTimestamp() {
if (engine_main_enter_ts == 0) {
engine_main_enter_ts = Dart_TimelineGetMicros();
}
}

static void Tokenize(const std::string& input,
std::vector<std::string>* results,
char delimiter) {
Expand All @@ -197,7 +190,7 @@ static void Tokenize(const std::string& input,
// TODO(chinmaygarde): The unfortunate side effect of this call is that settings
// that cause shell initialization failures will still lead to some of their
// settings being applied.
static void PerformInitializationTasks(const Settings& settings) {
static void PerformInitializationTasks(Settings& settings) {
{
fml::LogSettings log_settings;
log_settings.min_log_level =
Expand All @@ -207,7 +200,10 @@ static void PerformInitializationTasks(const Settings& settings) {

static std::once_flag gShellSettingsInitialization = {};
std::call_once(gShellSettingsInitialization, [&settings] {
RecordStartupTimestamp();
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; });
Expand Down
23 changes: 7 additions & 16 deletions shell/platform/android/flutter_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "flutter/fml/size.h"
#include "flutter/lib/ui/plugins/callback_cache.h"
#include "flutter/runtime/dart_vm.h"
#include "flutter/runtime/start_up.h"
#include "flutter/shell/common/shell.h"
#include "flutter/shell/common/switches.h"
#include "third_party/dart/runtime/include/dart_tools_api.h"
Expand Down Expand Up @@ -62,7 +61,8 @@ void FlutterMain::Init(JNIEnv* env,
jobjectArray jargs,
jstring kernelPath,
jstring appStoragePath,
jstring engineCachesPath) {
jstring engineCachesPath,
jlong initTimeMillis) {
std::vector<std::string> args;
args.push_back("flutter");
for (auto& arg : fml::jni::StringArrayToVector(env, jargs)) {
Expand All @@ -72,6 +72,10 @@ void FlutterMain::Init(JNIEnv* env,

auto settings = SettingsFromCommandLine(command_line);

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
// setter.
Expand Down Expand Up @@ -151,27 +155,14 @@ void FlutterMain::SetupObservatoryUriCallback(JNIEnv* env) {
});
}

static void RecordStartTimestamp(JNIEnv* env,
jclass jcaller,
jlong initTimeMillis) {
int64_t initTimeMicros =
static_cast<int64_t>(initTimeMillis) * static_cast<int64_t>(1000);
flutter::engine_main_enter_ts = Dart_TimelineGetMicros() - initTimeMicros;
}

bool FlutterMain::Register(JNIEnv* env) {
static const JNINativeMethod methods[] = {
{
.name = "nativeInit",
.signature = "(Landroid/content/Context;[Ljava/lang/String;Ljava/"
"lang/String;Ljava/lang/String;Ljava/lang/String;)V",
"lang/String;Ljava/lang/String;Ljava/lang/String;J)V",
.fnPtr = reinterpret_cast<void*>(&Init),
},
{
.name = "nativeRecordStartTimestamp",
.signature = "(J)V",
.fnPtr = reinterpret_cast<void*>(&RecordStartTimestamp),
},
};

jclass clazz = env->FindClass("io/flutter/embedding/engine/FlutterJNI");
Expand Down
3 changes: 2 additions & 1 deletion shell/platform/android/flutter_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class FlutterMain {
jobjectArray jargs,
jstring kernelPath,
jstring appStoragePath,
jstring engineCachesPath);
jstring engineCachesPath,
jlong initTimeMillis);

void SetupObservatoryUriCallback(JNIEnv* env);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,8 @@ public static native void nativeInit(
@NonNull String[] args,
@Nullable String bundlePath,
@NonNull String appStoragePath,
@NonNull String engineCachesPath);

// TODO(mattcarroll): add javadocs
public static native void nativeRecordStartTimestamp(long initTimeMillis);
@NonNull String engineCachesPath,
long initTimeMillis);

// TODO(mattcarroll): add javadocs
@UiThread
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public static FlutterLoader getInstance() {
private boolean initialized = false;
@Nullable private ResourceExtractor resourceExtractor;
@Nullable private Settings settings;
private long initStartTimestampMillis;

/**
* Starts initialization of the native system.
Expand Down Expand Up @@ -113,23 +114,14 @@ public void startInitialization(@NonNull Context applicationContext, @NonNull Se

this.settings = settings;

long initStartTimestampMillis = SystemClock.uptimeMillis();
initConfig(applicationContext);
initStartTimestampMillis = SystemClock.uptimeMillis();
initResources(applicationContext);

System.loadLibrary("flutter");

VsyncWaiter.getInstance(
(WindowManager) applicationContext.getSystemService(Context.WINDOW_SERVICE))
.init();

// We record the initialization time using SystemClock because at the start of the
// initialization we have not yet loaded the native library to call into dart_tools_api.h.
// To get Timeline timestamp of the start of initialization we simply subtract the delta
// from the Timeline timestamp at the current moment (the assumption is that the overhead
// of the JNI call is negligible).
long initTimeMillis = SystemClock.uptimeMillis() - initStartTimestampMillis;
FlutterJNI.nativeRecordStartTimestamp(initTimeMillis);
}

/**
Expand Down Expand Up @@ -202,12 +194,14 @@ public void ensureInitializationComplete(

String appStoragePath = PathUtils.getFilesDir(applicationContext);
String engineCachesPath = PathUtils.getCacheDirectory(applicationContext);
long initTimeMillis = SystemClock.uptimeMillis() - initStartTimestampMillis;
FlutterJNI.nativeInit(
applicationContext,
shellArgs.toArray(new String[0]),
kernelPath,
appStoragePath,
engineCachesPath);
engineCachesPath,
initTimeMillis);

initialized = true;
} catch (Exception e) {
Expand Down