From 6e2542fcd02cd1876f2a02fb8603f0efc2063e55 Mon Sep 17 00:00:00 2001 From: Tommy Nyquist Date: Thu, 6 Aug 2015 09:34:40 -0700 Subject: [PATCH] Add histogram for tracking the time for retrieving system accounts. On Android, it might be slow to retrieve the list of accounts, and as such, we should track how long time it takes to query for them, since this is done from the main thread. BUG=509826 Review URL: https://codereview.chromium.org/1260663004 Cr-Commit-Position: refs/heads/master@{#341228} (cherry picked from commit 96bb0fdb968033261cc9d5a7b4906208fef61f26) Review URL: https://codereview.chromium.org/1277823002 . Cr-Commit-Position: refs/branch-heads/2454@{#247} Cr-Branched-From: 12bfc3360892ec53cd00fc239a47e5298beb063b-refs/heads/master@{#338390} --- .../signin/SystemAccountManagerDelegate.java | 25 ++++++++++++++++++- tools/metrics/histograms/histograms.xml | 13 ++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/sync/android/java/src/org/chromium/sync/signin/SystemAccountManagerDelegate.java b/sync/android/java/src/org/chromium/sync/signin/SystemAccountManagerDelegate.java index 206fb85f2172a..e8b891aedf01c 100644 --- a/sync/android/java/src/org/chromium/sync/signin/SystemAccountManagerDelegate.java +++ b/sync/android/java/src/org/chromium/sync/signin/SystemAccountManagerDelegate.java @@ -12,6 +12,12 @@ import android.content.Context; import android.os.Bundle; import android.os.Handler; +import android.os.SystemClock; + +import org.chromium.base.library_loader.LibraryLoader; +import org.chromium.base.metrics.RecordHistogram; + +import java.util.concurrent.TimeUnit; /** * Default implementation of {@link AccountManagerDelegate} which delegates all calls to the @@ -32,7 +38,11 @@ public Account[] getAccountsByType(String type) { if (!AccountManagerHelper.get(mApplicationContext).hasGetAccountsPermission()) { return new Account[]{}; } - return mAccountManager.getAccountsByType(type); + long now = SystemClock.elapsedRealtime(); + Account[] accounts = mAccountManager.getAccountsByType(type); + long elapsed = SystemClock.elapsedRealtime() - now; + recordElapsedTimeHistogram("Signin.AndroidGetAccountsTime_AccountManager", elapsed); + return accounts; } @Override @@ -57,4 +67,17 @@ public AccountManagerFuture hasFeatures(Account account, String[] featu AccountManagerCallback callback, Handler handler) { return mAccountManager.hasFeatures(account, features, callback, handler); } + + /** + * Records a histogram value for how long time an action has taken using + * {@link RecordHistogram#recordTimesHistogram(String, long, TimeUnit))} iff the browser + * process has been initialized. + * + * @param histogramName the name of the histogram. + * @param elapsedMs the elapsed time in milliseconds. + */ + protected static void recordElapsedTimeHistogram(String histogramName, long elapsedMs) { + if (!LibraryLoader.isInitialized()) return; + RecordHistogram.recordTimesHistogram(histogramName, elapsedMs, TimeUnit.MILLISECONDS); + } } diff --git a/tools/metrics/histograms/histograms.xml b/tools/metrics/histograms/histograms.xml index 4f49bbe2f7ca4..01233d03ea20e 100644 --- a/tools/metrics/histograms/histograms.xml +++ b/tools/metrics/histograms/histograms.xml @@ -38962,6 +38962,13 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries. + + nyquist@chromium.org + + The time it takes to retrieve the list of accounts from the system. + + + guohui@chromium.org Track how a user interfacts with the android signin promo. @@ -70476,6 +70483,12 @@ To add a new entry, add it with any value and run test to compute valid value. + + + + + +