38fd382af0d193193f5a3bc7f64eb1e09bd05017 - chromium/src

6 views
Skip to first unread message

chan...@google.com

unread,
May 8, 2018, 3:55:56 PM5/8/18
to chromium...@chromium.org
commit 38fd382af0d193193f5a3bc7f64eb1e09bd05017
Author: Changwan Ryu <chan...@google.com>
AuthorDate: Tue May 08 19:55:17 2018
Commit: Commit Bot <commi...@chromium.org>
CommitDate: Tue May 08 19:55:17 2018

Add UMAs for webview creation time

Android's WebView constructor calls ensureProviderCreated() and then
mProvider.init().

In Chromium WebView, this corresponds to WebViewChromiumFactoryProvider
constructor and startChromiumLocked(), so we capture the time taken
there.

And, as noted in WebViewChromium#init(), the real initialization
(startYourEngines and thus startChromiumLocked) may be delayed until
the first View method is called and View thread can be determined,
so skip it when it hasn't started yet.

The sum of the two creation times is roughly the creation time
contributed by Chromium WebView, but with the following caveats:

1) ensureProviderCreated() may be called earlier in the constructor as
View methods can be called in the constructor.
2) This does not capture the time taken in View constructor and View
inflation, so this is only a portion of webview creation time.

Also, the factory initialization (the first portion) occurs only once,
while the provider initialization (the second portion) occurs every
time the app creates a webview instance.

Since the second portion takes much longer only for the first time,
I'm splitting it into 'First' and 'NonFirst'.

BUG=736545

Change-Id: I16ece2c4a1277a2489f5e8f44d157fd5cc35124d
Reviewed-on: https://chromium-review.googlesource.com/1041152
Commit-Queue: Changwan Ryu <chan...@chromium.org>
Reviewed-by: Bo <bo...@chromium.org>
Reviewed-by: Paul Miller <paulm...@chromium.org>
Reviewed-by: Tobias Sargeant <tobi...@chromium.org>
Reviewed-by: Ilya Sherman <ishe...@chromium.org>
Reviewed-by: Richard Coles <to...@chromium.org>
Cr-Commit-Position: refs/heads/master@{#556937}

diff --git a/android_webview/glue/java/src/com/android/webview/chromium/WebViewChromium.java b/android_webview/glue/java/src/com/android/webview/chromium/WebViewChromium.java
index 1cb3802..0f16254 100644
--- a/android_webview/glue/java/src/com/android/webview/chromium/WebViewChromium.java
+++ b/android_webview/glue/java/src/com/android/webview/chromium/WebViewChromium.java
@@ -22,6 +22,7 @@
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
+import android.os.SystemClock;
import android.print.PrintDocumentAdapter;
import android.util.Log;
import android.util.SparseArray;
@@ -62,6 +63,7 @@
import org.chromium.android_webview.renderer_priority.RendererPriority;
import org.chromium.base.BuildInfo;
import org.chromium.base.ThreadUtils;
+import org.chromium.base.metrics.CachedMetrics.TimesHistogramSample;
import org.chromium.components.autofill.AutofillProvider;
import org.chromium.content_public.browser.NavigationHistory;
import org.chromium.content_public.browser.SmartClipProvider;
@@ -72,6 +74,7 @@
import java.lang.reflect.Method;
import java.util.Map;
import java.util.concurrent.Callable;
+import java.util.concurrent.TimeUnit;

/**
* This class is the delegate to which WebViewProxy forwards all API calls.
@@ -149,6 +152,8 @@
// so is ignored. TODO: remove it from WebViewProvider.
public void init(final Map<String, Object> javaScriptInterfaces,
final boolean privateBrowsing) {
+ long startTime = SystemClock.elapsedRealtime();
+ boolean isFirstWebViewInit = !mFactory.hasStarted();
try (ScopedSysTraceEvent e1 = ScopedSysTraceEvent.scoped("WebViewChromium.init")) {
if (privateBrowsing) {
mFactory.startYourEngines(true);
@@ -233,6 +238,15 @@
}
}
});
+ } finally {
+ // The real initialization may be deferred, in which case we don't record this.
+ if (!mFactory.hasStarted()) return;
+
+ TimesHistogramSample histogram = new TimesHistogramSample(
+ "Android.WebView.Startup.CreationTime.Stage2.ProviderInit."
+ + (isFirstWebViewInit ? "Cold" : "Warm"),
+ TimeUnit.MILLISECONDS);
+ histogram.record(SystemClock.elapsedRealtime() - startTime);
}
}

diff --git a/android_webview/glue/java/src/com/android/webview/chromium/WebViewChromiumFactoryProvider.java b/android_webview/glue/java/src/com/android/webview/chromium/WebViewChromiumFactoryProvider.java
index 883afe5..6d11e32 100644
--- a/android_webview/glue/java/src/com/android/webview/chromium/WebViewChromiumFactoryProvider.java
+++ b/android_webview/glue/java/src/com/android/webview/chromium/WebViewChromiumFactoryProvider.java
@@ -12,6 +12,7 @@
import android.net.Uri;
import android.os.Build;
import android.os.StrictMode;
+import android.os.SystemClock;
import android.os.UserManager;
import android.provider.Settings;
import android.util.Log;
@@ -44,6 +45,7 @@
import org.chromium.base.PathUtils;
import org.chromium.base.ThreadUtils;
import org.chromium.base.library_loader.NativeLibraries;
+import org.chromium.base.metrics.CachedMetrics.TimesHistogramSample;
import org.chromium.components.autofill.AutofillProvider;
import org.chromium.content.browser.selection.LGEmailActionModeWorkaround;

@@ -51,6 +53,7 @@
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;
+import java.util.concurrent.TimeUnit;

/**
* Entry point to the WebView. The system framework talks to this class to get instances of the
@@ -163,6 +166,7 @@

@TargetApi(Build.VERSION_CODES.N) // For getSystemService() and isUserUnlocked().
private void initialize(WebViewDelegate webViewDelegate) {
+ long startTime = SystemClock.elapsedRealtime();
try (ScopedSysTraceEvent e1 =
ScopedSysTraceEvent.scoped("WebViewChromiumFactoryProvider.initialize")) {
// The package is used to locate the services for copying crash minidumps and requesting
@@ -253,6 +257,11 @@
shouldDisableThreadChecking(ContextUtils.getApplicationContext());

setSingleton(this);
+ } finally {
+ TimesHistogramSample histogram = new TimesHistogramSample(
+ "Android.WebView.Startup.CreationTime.Stage1.FactoryInit",
+ TimeUnit.MILLISECONDS);
+ histogram.record(SystemClock.elapsedRealtime() - startTime);
}
}

diff --git a/tools/metrics/histograms/histograms.xml b/tools/metrics/histograms/histograms.xml
index 6ae9249..022ce8d 100644
--- a/tools/metrics/histograms/histograms.xml
+++ b/tools/metrics/histograms/histograms.xml
@@ -1979,6 +1979,37 @@
</summary>
</histogram>

+<histogram name="Android.WebView.Startup.CreationTime.Stage1.FactoryInit"
+ units="ms">
+ <owner>chan...@chromium.org</owner>
+ <summary>
+ How long it takes to initialize a WebViewChromiumFactoryProvider. This is
+ the first major phase of the WebViewChromium construction.
+ </summary>
+</histogram>
+
+<histogram name="Android.WebView.Startup.CreationTime.Stage2.ProviderInit.Cold"
+ units="ms">
+ <owner>chan...@chromium.org</owner>
+ <summary>
+ How long it takes to initialize a WebViewProvider, the first time that one
+ is initialized. WebViewProvider initialization is the second major phase of
+ WebViewChromium construction. The first initialization is recorded
+ separately because it is usually much slower than subsequent ones.
+ </summary>
+</histogram>
+
+<histogram name="Android.WebView.Startup.CreationTime.Stage2.ProviderInit.Warm"
+ units="ms">
+ <owner>chan...@chromium.org</owner>
+ <summary>
+ How long it takes to initialize a WebViewProvider, the first time that one
+ is initialized. WebViewProvider initialization is the second major phase of
+ WebViewChromium construction. When it is not the first time, it is faster
+ and thus recorded separately.
+ </summary>
+</histogram>
+
<histogram name="Android.WebView.TargetSdkVersion" enum="AndroidApiLevel">
<owner>chan...@chromium.org</owner>
<summary>
Reply all
Reply to author
Forward
0 new messages