Skip to content

Commit

Permalink
record startup timestamp in Android; pass it to Dart timeline (flutte…
Browse files Browse the repository at this point in the history
  • Loading branch information
yjbanov committed Apr 22, 2016
1 parent 24adf9d commit 7a919c0
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 0 deletions.
2 changes: 2 additions & 0 deletions sky/engine/core/core.gni
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ sky_core_output_dir = "$root_gen_dir/sky/core"
sky_core_files = [
"Init.cpp",
"Init.h",
"start_up.h",
"start_up.cc",
"compositing/Scene.cpp",
"compositing/Scene.h",
"compositing/SceneBuilder.cpp",
Expand Down
16 changes: 16 additions & 0 deletions sky/engine/core/script/dart_init.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "sky/engine/tonic/dart_wrappable.h"
#include "sky/engine/tonic/uint8_list.h"
#include "sky/engine/wtf/MakeUnique.h"
#include "sky/engine/core/start_up.h"

#ifdef OS_ANDROID
#include "sky/engine/bindings/jni/dart_jni.h"
Expand Down Expand Up @@ -104,6 +105,7 @@ static const char* kDartStartPausedArgs[]{

static const char* kDartTraceStartupArgs[]{
"--timeline_streams=Compiler,Dart,Embedder,GC",
"--timeline_recorder=endless",
};

const char kFileUriPrefix[] = "file://";
Expand Down Expand Up @@ -460,6 +462,20 @@ void InitDartVM() {
nullptr,
// VM service assets archive
GetVMServiceAssetsArchiveCallback) == nullptr);

// 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.
if (blink::engine_main_enter_ts != 0) {
Dart_TimelineEvent("FlutterEngineMainEnter", // label
blink::engine_main_enter_ts, // timestamp0
0, // timestamp1_or_async_id
Dart_Timeline_Event_Instant, // event type
0, // argument_count
nullptr, // argument_names
nullptr // argument_values
);
}
}

// Allow streaming of stdout and stderr by the Dart vm.
Expand Down
11 changes: 11 additions & 0 deletions sky/engine/core/start_up.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "sky/engine/core/start_up.h"

namespace blink {

int64_t engine_main_enter_ts = 0;

} // namespace blink
24 changes: 24 additions & 0 deletions sky/engine/core/start_up.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef SKY_ENGINE_CORE_START_UP_H_
#define SKY_ENGINE_CORE_START_UP_H_

#include <stdint.h>

namespace blink {

// The earliest available timestamp in the application's lifecycle. The
// difference between this timestamp and the time we render the very first
// frame gives us a good idea about Flutter's startup time.
//
// This timestamp only covers Flutter's own startup. In an upside-down model
// it is possible that the first Flutter view is not initialized until some
// time later. In this case the timestamp may not cover the time spent in the
// user code prior to initializing Flutter.
extern int64_t engine_main_enter_ts;

} // namespace blink

#endif // SKY_ENGINE_CORE_START_UP_H_
8 changes: 8 additions & 0 deletions sky/shell/platform/android/flutter_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
#include "mojo/edk/embedder/embedder.h"
#include "mojo/edk/embedder/simple_platform_support.h"
#include "sky/shell/shell.h"
#include "sky/engine/core/start_up.h"
#include "ui/gl/gl_surface.h"
#include "dart/runtime/include/dart_tools_api.h"

using base::LazyInstance;

Expand Down Expand Up @@ -84,6 +86,12 @@ static void Init(JNIEnv* env,
InitializeTracing();
}

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

bool RegisterFlutterMain(JNIEnv* env) {
return RegisterNativesImpl(env);
}
Expand Down
12 changes: 12 additions & 0 deletions sky/shell/platform/android/io/flutter/view/FlutterMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.content.Context;
import android.util.Log;
import android.content.res.AssetManager;
import android.os.SystemClock;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;
Expand Down Expand Up @@ -63,9 +64,19 @@ public class FlutterMain {
* Starts initialization of the native system.
**/
public static void startInitialization(Context applicationContext) {
long initStartTimestampMillis = SystemClock.uptimeMillis();
initJavaUtils(applicationContext);
initResources(applicationContext);
initNative(applicationContext);

// 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;
nativeRecordStartTimestamp(initTimeMillis);

onServiceRegistryAvailable(applicationContext, ServiceRegistry.SHARED);
}

Expand All @@ -89,6 +100,7 @@ public static void ensureInitializationComplete(Context applicationContext, Stri
}

private static native void nativeInit(Context context, String[] args);
private static native void nativeRecordStartTimestamp(long initTimeMillis);

private static void onServiceRegistryAvailable(final Context applicationContext, ServiceRegistry registry) {
parseServicesConfig(applicationContext, registry);
Expand Down

0 comments on commit 7a919c0

Please sign in to comment.