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

Record Startup.LoadTime.ProcessCreateToApplicationStart on Android

This metric was not previously recorded on Android because
startup_metric_utils::RecordStartupProcessCreationTime was never called.
We can use Process.getStartUptimeMillis() to get this value.

Bug: 1126301
Change-Id: Ic94be3635389c4a3c9b5e0f870b9d3290767a530
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2402209
Commit-Queue: Clark DuVall <cduvall@chromium.org>
Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/master@{#806384}
parent 44c96eac
...@@ -89,13 +89,18 @@ public class UmaUtils { ...@@ -89,13 +89,18 @@ public class UmaUtils {
} }
@CalledByNative @CalledByNative
public static long getApplicationStartTime(boolean useProcessStartTime) { public static long getApplicationStartTime() {
if (useProcessStartTime && Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
return ApiHelperForN.getStartUptimeMillis();
}
return sApplicationStartTimeMs; return sApplicationStartTimeMs;
} }
@CalledByNative
public static long getProcessStartTime() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
return 0;
}
return ApiHelperForN.getStartUptimeMillis();
}
public static long getForegroundStartTicks() { public static long getForegroundStartTicks() {
assert sForegroundStartTimeMs != 0; assert sForegroundStartTimeMs != 0;
return sForegroundStartTimeMs; return sForegroundStartTimeMs;
......
...@@ -92,9 +92,19 @@ int ChromeMainDelegateAndroid::RunProcess( ...@@ -92,9 +92,19 @@ int ChromeMainDelegateAndroid::RunProcess(
// Also only record the start time the first time round, since this is the // Also only record the start time the first time round, since this is the
// 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( base::TimeTicks process_start_time = chrome::android::GetProcessStartTime();
chrome::android::GetApplicationStartTime( base::TimeTicks application_start_time =
base::FeatureList::IsEnabled(kUseProcessStartTimeForMetrics))); chrome::android::GetApplicationStartTime();
if (!process_start_time.is_null()) {
startup_metric_utils::RecordStartupProcessCreationTime(
process_start_time);
// TODO(crbug.com/1127482): Perf bots should add support for measuring
// Startup.LoadTime.ProcessCreateToApplicationStart, then the
// kUseProcessStartTimeForMetrics feature can be removed.
if (base::FeatureList::IsEnabled(kUseProcessStartTimeForMetrics))
application_start_time = process_start_time;
}
startup_metric_utils::RecordApplicationStartTime(application_start_time);
browser_runner_ = content::BrowserMainRunner::Create(); browser_runner_ = content::BrowserMainRunner::Create();
} }
......
...@@ -493,7 +493,8 @@ void RecordMainStartupMetrics(base::TimeTicks application_start_time) { ...@@ -493,7 +493,8 @@ void RecordMainStartupMetrics(base::TimeTicks application_start_time) {
#if defined(OS_MAC) || defined(OS_WIN) || defined(OS_LINUX) || \ #if defined(OS_MAC) || defined(OS_WIN) || defined(OS_LINUX) || \
defined(OS_CHROMEOS) defined(OS_CHROMEOS)
// Record the startup process creation time on supported platforms. // Record the startup process creation time on supported platforms. On Android
// this is recorded in ChromeMainDelegateAndroid.
startup_metric_utils::RecordStartupProcessCreationTime( startup_metric_utils::RecordStartupProcessCreationTime(
base::Process::Current().CreationTime()); base::Process::Current().CreationTime());
#endif #endif
......
...@@ -18,10 +18,16 @@ class PrefService; ...@@ -18,10 +18,16 @@ class PrefService;
namespace chrome { namespace chrome {
namespace android { namespace android {
base::TimeTicks GetApplicationStartTime(bool use_process_start_time) { base::TimeTicks GetApplicationStartTime() {
JNIEnv* env = base::android::AttachCurrentThread(); JNIEnv* env = base::android::AttachCurrentThread();
return base::TimeTicks::FromUptimeMillis( return base::TimeTicks::FromUptimeMillis(
Java_UmaUtils_getApplicationStartTime(env, use_process_start_time)); Java_UmaUtils_getApplicationStartTime(env));
}
base::TimeTicks GetProcessStartTime() {
JNIEnv* env = base::android::AttachCurrentThread();
return base::TimeTicks::FromUptimeMillis(
Java_UmaUtils_getProcessStartTime(env));
} }
static jboolean JNI_UmaUtils_IsClientInMetricsReportingSample(JNIEnv* env) { static jboolean JNI_UmaUtils_IsClientInMetricsReportingSample(JNIEnv* env) {
......
...@@ -12,7 +12,8 @@ ...@@ -12,7 +12,8 @@
namespace chrome { namespace chrome {
namespace android { namespace android {
base::TimeTicks GetApplicationStartTime(bool use_process_start_time); base::TimeTicks GetApplicationStartTime();
base::TimeTicks GetProcessStartTime();
// 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.
......
...@@ -376,8 +376,12 @@ void SetBackgroundModeEnabled() { ...@@ -376,8 +376,12 @@ void SetBackgroundModeEnabled() {
} }
void RecordStartupProcessCreationTime(base::Time time) { void RecordStartupProcessCreationTime(base::Time time) {
RecordStartupProcessCreationTime(StartupTimeToTimeTicks(time));
}
void RecordStartupProcessCreationTime(base::TimeTicks ticks) {
DCHECK(g_process_creation_ticks.is_null()); DCHECK(g_process_creation_ticks.is_null());
g_process_creation_ticks = StartupTimeToTimeTicks(time); g_process_creation_ticks = ticks;
DCHECK(!g_process_creation_ticks.is_null()); DCHECK(!g_process_creation_ticks.is_null());
} }
......
...@@ -34,6 +34,7 @@ void SetBackgroundModeEnabled(); ...@@ -34,6 +34,7 @@ void SetBackgroundModeEnabled();
// Call this with the creation time of the startup (initial/main) process. // Call this with the creation time of the startup (initial/main) process.
void RecordStartupProcessCreationTime(base::Time time); void RecordStartupProcessCreationTime(base::Time time);
void RecordStartupProcessCreationTime(base::TimeTicks ticks);
// Call this with a time recorded as early as possible in the startup process. // Call this with a time recorded as early as possible in the startup process.
// On Android, the application start is the time at which the Java code starts. // On Android, the application start is the time at which the Java code starts.
......
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