Commit 99e71989 authored by Clark DuVall's avatar Clark DuVall Committed by Commit Bot

[WebLayer] Add histograms to measure WebLayer startup

These histograms measure WebLayer startup before WebLayerImpl is loaded,
which we were not measureing before. This will help tell if something
here is contributing to slow startup.

Bug: 1137468
Change-Id: I3e84fc399cf460d60d2e7445326493c528c09178
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2466264
Commit-Queue: Clark DuVall <cduvall@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarIlya Sherman <isherman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#816590}
parent 3bfeb507
...@@ -145,6 +145,7 @@ template("generate_expired_histograms_array") { ...@@ -145,6 +145,7 @@ template("generate_expired_histograms_array") {
"//tools/metrics/histograms/histograms_xml/web_audio/histograms.xml", "//tools/metrics/histograms/histograms_xml/web_audio/histograms.xml",
"//tools/metrics/histograms/histograms_xml/web_core/histograms.xml", "//tools/metrics/histograms/histograms_xml/web_core/histograms.xml",
"//tools/metrics/histograms/histograms_xml/web_rtc/histograms.xml", "//tools/metrics/histograms/histograms_xml/web_rtc/histograms.xml",
"//tools/metrics/histograms/histograms_xml/weblayer/histograms.xml",
"//tools/metrics/histograms/histograms_xml/windows/histograms.xml", "//tools/metrics/histograms/histograms_xml/windows/histograms.xml",
"//tools/metrics/histograms/histograms_xml/obsolete_histograms.xml", "//tools/metrics/histograms/histograms_xml/obsolete_histograms.xml",
"//tools/metrics/histograms/enums.xml", "//tools/metrics/histograms/enums.xml",
......
...@@ -111,4 +111,5 @@ tools/metrics/histograms/histograms_xml/web_apk/histograms.xml ...@@ -111,4 +111,5 @@ tools/metrics/histograms/histograms_xml/web_apk/histograms.xml
tools/metrics/histograms/histograms_xml/web_audio/histograms.xml tools/metrics/histograms/histograms_xml/web_audio/histograms.xml
tools/metrics/histograms/histograms_xml/web_core/histograms.xml tools/metrics/histograms/histograms_xml/web_core/histograms.xml
tools/metrics/histograms/histograms_xml/web_rtc/histograms.xml tools/metrics/histograms/histograms_xml/web_rtc/histograms.xml
tools/metrics/histograms/histograms_xml/weblayer/histograms.xml
tools/metrics/histograms/histograms_xml/windows/histograms.xml tools/metrics/histograms/histograms_xml/windows/histograms.xml
\ No newline at end of file
<!--
Copyright 2020 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.
-->
<!--
This file is used to generate a comprehensive list of WebLayer histograms
along with a detailed description for each histogram.
For best practices on writing histogram descriptions, see
https://chromium.googlesource.com/chromium/src.git/+/HEAD/tools/metrics/histograms/README.md
Please send CLs to chromium-metrics-reviews@google.com rather than to specific
individuals. These CLs will be automatically reassigned to a reviewer within
about 5 minutes. This approach helps the metrics team to load-balance incoming
reviews. Googlers can read more about this at go/gwsq-gerrit.
-->
<histogram-configuration>
<histograms>
<histogram name="WebLayer.Startup.ClassLoaderCreationTime" units="ms"
expires_after="M98">
<owner>cduvall@chromium.org</owner>
<owner>src/weblayer/OWNERS</owner>
<summary>
The time it takes for the WebLayer class loader to be created. Recorded at
WebLayer startup.
</summary>
</histogram>
<histogram name="WebLayer.Startup.ContextCreationTime" units="ms"
expires_after="M98">
<owner>cduvall@chromium.org</owner>
<owner>src/weblayer/OWNERS</owner>
<summary>
The time it takes for the WebLayer context to be created. Recorded at
WebLayer startup.
</summary>
</histogram>
<histogram name="WebLayer.Startup.WebLayerLoaderCreationTime" units="ms"
expires_after="M98">
<owner>cduvall@chromium.org</owner>
<owner>src/weblayer/OWNERS</owner>
<summary>
The time it takes for the WebLayer loader to be created. Recorded at
WebLayer startup.
</summary>
</histogram>
</histograms>
</histogram-configuration>
...@@ -45,6 +45,7 @@ import org.chromium.base.annotations.NativeMethods; ...@@ -45,6 +45,7 @@ import org.chromium.base.annotations.NativeMethods;
import org.chromium.base.compat.ApiHelperForO; import org.chromium.base.compat.ApiHelperForO;
import org.chromium.base.library_loader.LibraryLoader; import org.chromium.base.library_loader.LibraryLoader;
import org.chromium.base.library_loader.LibraryProcessType; import org.chromium.base.library_loader.LibraryProcessType;
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.components.browser_ui.contacts_picker.ContactsPickerDialog; import org.chromium.components.browser_ui.contacts_picker.ContactsPickerDialog;
import org.chromium.components.browser_ui.photo_picker.DecoderServiceHost; import org.chromium.components.browser_ui.photo_picker.DecoderServiceHost;
import org.chromium.components.browser_ui.photo_picker.ImageDecoder; import org.chromium.components.browser_ui.photo_picker.ImageDecoder;
...@@ -432,6 +433,19 @@ public final class WebLayerImpl extends IWebLayer.Stub { ...@@ -432,6 +433,19 @@ public final class WebLayerImpl extends IWebLayer.Stub {
public void setClient(IWebLayerClient client) { public void setClient(IWebLayerClient client) {
StrictModeWorkaround.apply(); StrictModeWorkaround.apply();
sClient = client; sClient = client;
if (WebLayerFactoryImpl.getClientMajorVersion() >= 88) {
try {
RecordHistogram.recordTimesHistogram("WebLayer.Startup.ClassLoaderCreationTime",
sClient.getClassLoaderCreationTime());
RecordHistogram.recordTimesHistogram(
"WebLayer.Startup.ContextCreationTime", sClient.getContextCreationTime());
RecordHistogram.recordTimesHistogram("WebLayer.Startup.WebLayerLoaderCreationTime",
sClient.getWebLayerLoaderCreationTime());
} catch (RemoteException e) {
throw new APICallException(e);
}
}
} }
@Override @Override
......
...@@ -13,4 +13,9 @@ interface IWebLayerClient { ...@@ -13,4 +13,9 @@ interface IWebLayerClient {
// Since Version 86. // Since Version 86.
Intent createImageDecoderServiceIntent() = 3; Intent createImageDecoderServiceIntent() = 3;
// Since Version 88.
long getClassLoaderCreationTime() = 4;
long getContextCreationTime() = 5;
long getWebLayerLoaderCreationTime() = 6;
} }
...@@ -14,6 +14,7 @@ import android.os.Bundle; ...@@ -14,6 +14,7 @@ import android.os.Bundle;
import android.os.IBinder; import android.os.IBinder;
import android.os.RemoteException; import android.os.RemoteException;
import android.os.StrictMode; import android.os.StrictMode;
import android.os.SystemClock;
import android.util.AndroidRuntimeException; import android.util.AndroidRuntimeException;
import android.util.Log; import android.util.Log;
import android.webkit.ValueCallback; import android.webkit.ValueCallback;
...@@ -71,6 +72,11 @@ public class WebLayer { ...@@ -71,6 +72,11 @@ public class WebLayer {
@NonNull @NonNull
private final IWebLayer mImpl; private final IWebLayer mImpl;
// Times used for logging UMA histograms.
private static long sClassLoaderCreationTime;
private static long sContextCreationTime;
private static long sWebLayerLoaderCreationTime;
/** The result of calling {@link #initializeWebViewCompatibilityMode}. */ /** The result of calling {@link #initializeWebViewCompatibilityMode}. */
public enum WebViewCompatibilityResult { public enum WebViewCompatibilityResult {
/** Compatibility mode has been successfully set up. */ /** Compatibility mode has been successfully set up. */
...@@ -274,13 +280,16 @@ public class WebLayer { ...@@ -274,13 +280,16 @@ public class WebLayer {
mContext = mContext.createAttributionContext(context.getAttributionTag()); mContext = mContext.createAttributionContext(context.getAttributionTag());
} }
try { try {
Class factoryClass = getOrCreateRemoteClassLoader(mContext).loadClass( ClassLoader classLoader = getOrCreateRemoteClassLoader(mContext);
"org.chromium.weblayer_private.WebLayerFactoryImpl"); long start = SystemClock.elapsedRealtime();
Class factoryClass =
classLoader.loadClass("org.chromium.weblayer_private.WebLayerFactoryImpl");
mFactory = IWebLayerFactory.Stub.asInterface( mFactory = IWebLayerFactory.Stub.asInterface(
(IBinder) factoryClass (IBinder) factoryClass
.getMethod("create", String.class, int.class, int.class) .getMethod("create", String.class, int.class, int.class)
.invoke(null, WebLayerClientVersionConstants.PRODUCT_VERSION, .invoke(null, WebLayerClientVersionConstants.PRODUCT_VERSION,
WebLayerClientVersionConstants.PRODUCT_MAJOR_VERSION, -1)); WebLayerClientVersionConstants.PRODUCT_MAJOR_VERSION, -1));
sWebLayerLoaderCreationTime = SystemClock.elapsedRealtime() - start;
available = mFactory.isClientSupported(); available = mFactory.isClientSupported();
majorVersion = mFactory.getImplementationMajorVersion(); majorVersion = mFactory.getImplementationMajorVersion();
version = mFactory.getImplementationVersion(); version = mFactory.getImplementationVersion();
...@@ -598,6 +607,7 @@ public class WebLayer { ...@@ -598,6 +607,7 @@ public class WebLayer {
return sRemoteClassLoader; return sRemoteClassLoader;
} }
long start = SystemClock.elapsedRealtime();
// Child processes do not need WebView compatibility since there is no chance // Child processes do not need WebView compatibility since there is no chance
// WebView will run in the same process. // WebView will run in the same process.
if (sDisableWebViewCompatibilityMode) { if (sDisableWebViewCompatibilityMode) {
...@@ -617,6 +627,7 @@ public class WebLayer { ...@@ -617,6 +627,7 @@ public class WebLayer {
} else { } else {
sRemoteClassLoader = WebViewCompatibilityHelper.initialize(appContext); sRemoteClassLoader = WebViewCompatibilityHelper.initialize(appContext);
} }
sClassLoaderCreationTime = SystemClock.elapsedRealtime() - start;
return sRemoteClassLoader; return sRemoteClassLoader;
} }
...@@ -628,6 +639,7 @@ public class WebLayer { ...@@ -628,6 +639,7 @@ public class WebLayer {
if (sRemoteContext != null) { if (sRemoteContext != null) {
return sRemoteContext; return sRemoteContext;
} }
long start = SystemClock.elapsedRealtime();
Class<?> webViewFactoryClass = Class.forName("android.webkit.WebViewFactory"); Class<?> webViewFactoryClass = Class.forName("android.webkit.WebViewFactory");
String implPackageName = getImplPackageName(appContext); String implPackageName = getImplPackageName(appContext);
sAppContext = appContext; sAppContext = appContext;
...@@ -643,6 +655,7 @@ public class WebLayer { ...@@ -643,6 +655,7 @@ public class WebLayer {
(String) webViewFactoryClass.getMethod("getWebViewPackageName").invoke(null); (String) webViewFactoryClass.getMethod("getWebViewPackageName").invoke(null);
sRemoteContext = createRemoteContextFromPackageName(appContext, implPackageName); sRemoteContext = createRemoteContextFromPackageName(appContext, implPackageName);
} }
sContextCreationTime = SystemClock.elapsedRealtime() - start;
return sRemoteContext; return sRemoteContext;
} }
...@@ -721,6 +734,21 @@ public class WebLayer { ...@@ -721,6 +734,21 @@ public class WebLayer {
// The id is part of the public library to avoid conflicts. // The id is part of the public library to avoid conflicts.
return R.id.weblayer_media_session_notification; return R.id.weblayer_media_session_notification;
} }
@Override
public long getClassLoaderCreationTime() {
return sClassLoaderCreationTime;
}
@Override
public long getContextCreationTime() {
return sContextCreationTime;
}
@Override
public long getWebLayerLoaderCreationTime() {
return sWebLayerLoaderCreationTime;
}
} }
@VerifiesOnO @VerifiesOnO
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment