Commit a1a298a3 authored by Clark DuVall's avatar Clark DuVall Committed by Commit Bot

Add a feature to use process start time for Android startup metrics

This allows using Process.getStartUptimeMillis() for startup metrics,
which will include the time spent loading java code.

Bug: 1126301
Change-Id: Ia5b050ba268b3445a7dd934fab409298ce9b3c32
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2399918Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Commit-Queue: Clark DuVall <cduvall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#805319}
parent e62204e9
...@@ -14,6 +14,7 @@ import android.content.pm.PackageManager; ...@@ -14,6 +14,7 @@ import android.content.pm.PackageManager;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.media.MediaCodec.CryptoInfo; import android.media.MediaCodec.CryptoInfo;
import android.os.Build; import android.os.Build;
import android.os.Process;
import android.security.NetworkSecurityPolicy; import android.security.NetworkSecurityPolicy;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.PointerIcon; import android.view.PointerIcon;
...@@ -85,4 +86,9 @@ public final class ApiHelperForN { ...@@ -85,4 +86,9 @@ public final class ApiHelperForN {
public static PointerIcon onResolvePointerIcon(View view, MotionEvent event, int pointerIndex) { public static PointerIcon onResolvePointerIcon(View view, MotionEvent event, int pointerIndex) {
return view.onResolvePointerIcon(event, pointerIndex); return view.onResolvePointerIcon(event, pointerIndex);
} }
/** See {@link Process#getStartUptimeMillis()}. */
public static long getStartUptimeMillis() {
return Process.getStartUptimeMillis();
}
} }
...@@ -4,12 +4,14 @@ ...@@ -4,12 +4,14 @@
package org.chromium.chrome.browser.metrics; package org.chromium.chrome.browser.metrics;
import android.os.Build;
import android.os.SystemClock; import android.os.SystemClock;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.MainDex; import org.chromium.base.annotations.MainDex;
import org.chromium.base.annotations.NativeMethods; import org.chromium.base.annotations.NativeMethods;
import org.chromium.base.compat.ApiHelperForN;
/** /**
* Utilities to support startup metrics - Android version. * Utilities to support startup metrics - Android version.
...@@ -87,7 +89,10 @@ public class UmaUtils { ...@@ -87,7 +89,10 @@ public class UmaUtils {
} }
@CalledByNative @CalledByNative
public static long getApplicationStartTime() { public static long getApplicationStartTime(boolean useProcessStartTime) {
if (useProcessStartTime && Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
return ApiHelperForN.getStartUptimeMillis();
}
return sApplicationStartTimeMs; return sApplicationStartTimeMs;
} }
......
...@@ -24,8 +24,14 @@ ...@@ -24,8 +24,14 @@
#include "components/safe_browsing/android/safe_browsing_api_handler_bridge.h" #include "components/safe_browsing/android/safe_browsing_api_handler_bridge.h"
#endif #endif
namespace {
using safe_browsing::SafeBrowsingApiHandler; using safe_browsing::SafeBrowsingApiHandler;
// Whether to use the process start time for startup metrics.
const base::Feature kUseProcessStartTimeForMetrics{
"UseProcessStartTimeForMetrics", base::FEATURE_DISABLED_BY_DEFAULT};
} // namespace
// ChromeMainDelegateAndroid is created when the library is loaded. It is always // ChromeMainDelegateAndroid is created when the library is loaded. It is always
// done in the process' main Java thread. But for a non-browser process, e.g. // done in the process' main Java thread. But for a non-browser process, e.g.
// renderer process, it is not the native Chrome's main thread. // renderer process, it is not the native Chrome's main thread.
...@@ -87,7 +93,8 @@ int ChromeMainDelegateAndroid::RunProcess( ...@@ -87,7 +93,8 @@ int ChromeMainDelegateAndroid::RunProcess(
// start time of the application, and will be same for all requests. // start time of the application, and will be same for all requests.
if (!browser_runner_) { if (!browser_runner_) {
startup_metric_utils::RecordApplicationStartTime( startup_metric_utils::RecordApplicationStartTime(
chrome::android::GetApplicationStartTime()); chrome::android::GetApplicationStartTime(
base::FeatureList::IsEnabled(kUseProcessStartTimeForMetrics)));
browser_runner_ = content::BrowserMainRunner::Create(); browser_runner_ = content::BrowserMainRunner::Create();
} }
......
...@@ -18,10 +18,10 @@ class PrefService; ...@@ -18,10 +18,10 @@ class PrefService;
namespace chrome { namespace chrome {
namespace android { namespace android {
base::TimeTicks GetApplicationStartTime() { base::TimeTicks GetApplicationStartTime(bool use_process_start_time) {
JNIEnv* env = base::android::AttachCurrentThread(); JNIEnv* env = base::android::AttachCurrentThread();
return base::TimeTicks::FromUptimeMillis( return base::TimeTicks::FromUptimeMillis(
Java_UmaUtils_getApplicationStartTime(env)); Java_UmaUtils_getApplicationStartTime(env, use_process_start_time));
} }
static jboolean JNI_UmaUtils_IsClientInMetricsReportingSample(JNIEnv* env) { static jboolean JNI_UmaUtils_IsClientInMetricsReportingSample(JNIEnv* env) {
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
namespace chrome { namespace chrome {
namespace android { namespace android {
base::TimeTicks GetApplicationStartTime(); base::TimeTicks GetApplicationStartTime(bool use_process_start_time);
// Sets whether UMA reporting is enabled. This will call to Java to update // Sets whether UMA reporting is enabled. This will call to Java to update
// the shared preference that is the source of truth for UMA reporting. // the shared preference that is the source of truth for UMA reporting.
......
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