Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
Add histogram for tracking the time for retrieving system accounts.
Browse files Browse the repository at this point in the history
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 96bb0fd)

Review URL: https://codereview.chromium.org/1277823002 .

Cr-Commit-Position: refs/branch-heads/2454@{#247}
Cr-Branched-From: 12bfc33-refs/heads/master@{#338390}
  • Loading branch information
tommynyquist committed Aug 6, 2015
1 parent a0c54b2 commit 6e2542f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -57,4 +67,17 @@ public AccountManagerFuture<Boolean> hasFeatures(Account account, String[] featu
AccountManagerCallback<Boolean> 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);
}
}
13 changes: 13 additions & 0 deletions tools/metrics/histograms/histograms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38962,6 +38962,13 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
</summary>
</histogram>

<histogram name="Signin.AndroidGetAccountsTime" units="milliseconds">
<owner>[email protected]</owner>
<summary>
The time it takes to retrieve the list of accounts from the system.
</summary>
</histogram>

<histogram name="Signin.AndroidSigninPromo" enum="AndroidSigninPromoAction">
<owner>[email protected]</owner>
<summary>Track how a user interfacts with the android signin promo.</summary>
Expand Down Expand Up @@ -70476,6 +70483,12 @@ To add a new entry, add it with any value and run test to compute valid value.
<affected-histogram name="PLT.StartToFinish_NormalLoad"/>
</histogram_suffixes>

<histogram_suffixes name="AndroidGetAccountsTypes">
<suffix name="AccountManager" label="Using Android AccountManager API"/>
<suffix name="GoogleAuthUtil" label="Using GoogleAuthUtil API"/>
<affected-histogram name="Signin.AndroidGetAccountsTime"/>
</histogram_suffixes>

<histogram_suffixes name="AppListFirstPaintWarmStartFast" separator="">
<suffix name="" label="Normal start."/>
<suffix name="Fast"
Expand Down

0 comments on commit 6e2542f

Please sign in to comment.