Commit 66b7797a authored by Mohamed Amir Yosef's avatar Mohamed Amir Yosef Committed by Commit Bot

[FCM] UMA histogram for how long it take to read persisted GCM messages

When a message arrives for a lazy GCM subscription and Chrome isn't in
the foreground, it is persisted on disk until next time Chrome is in the
foreground.

This CL adds two histograms
1- Record the time spent to check if a subscription lazy upon receiving
a GCM message while Chrome is in the background.
2- Record the time spent in reading and replaying persisted
messages when Chrome goes to the foreground.

Bug: 882887
Change-Id: I2ea8e5a5c5242b573e842b56f08d7f1070d48856
Reviewed-on: https://chromium-review.googlesource.com/c/1333656Reviewed-by: default avatarRobert Kaplow <rkaplow@chromium.org>
Reviewed-by: default avatarPeter Conn <peconn@chromium.org>
Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Commit-Queue: Mohamed Amir Yosef <mamir@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608925}
parent 2abfd4e4
...@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.services.gcm; ...@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.services.gcm;
import android.content.Context; import android.content.Context;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.SystemClock;
import android.text.TextUtils; import android.text.TextUtils;
import com.google.android.gms.gcm.GcmListenerService; import com.google.android.gms.gcm.GcmListenerService;
...@@ -17,6 +18,7 @@ import org.chromium.base.ContextUtils; ...@@ -17,6 +18,7 @@ import org.chromium.base.ContextUtils;
import org.chromium.base.Log; import org.chromium.base.Log;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
import org.chromium.base.library_loader.ProcessInitException; import org.chromium.base.library_loader.ProcessInitException;
import org.chromium.base.metrics.CachedMetrics;
import org.chromium.chrome.browser.init.ChromeBrowserInitializer; import org.chromium.chrome.browser.init.ChromeBrowserInitializer;
import org.chromium.chrome.browser.init.ProcessInitializationHandler; import org.chromium.chrome.browser.init.ProcessInitializationHandler;
import org.chromium.components.background_task_scheduler.BackgroundTaskSchedulerFactory; import org.chromium.components.background_task_scheduler.BackgroundTaskSchedulerFactory;
...@@ -26,6 +28,8 @@ import org.chromium.components.gcm_driver.GCMDriver; ...@@ -26,6 +28,8 @@ import org.chromium.components.gcm_driver.GCMDriver;
import org.chromium.components.gcm_driver.GCMMessage; import org.chromium.components.gcm_driver.GCMMessage;
import org.chromium.components.gcm_driver.LazySubscriptionsManager; import org.chromium.components.gcm_driver.LazySubscriptionsManager;
import java.util.concurrent.TimeUnit;
/** /**
* Receives Downstream messages and status of upstream messages from GCM. * Receives Downstream messages and status of upstream messages from GCM.
*/ */
...@@ -101,13 +105,25 @@ public class ChromeGcmListenerService extends GcmListenerService { ...@@ -101,13 +105,25 @@ public class ChromeGcmListenerService extends GcmListenerService {
ThreadUtils.assertOnUiThread(); ThreadUtils.assertOnUiThread();
final String subscriptionId = LazySubscriptionsManager.buildSubscriptionUniqueId( final String subscriptionId = LazySubscriptionsManager.buildSubscriptionUniqueId(
message.getAppId(), message.getSenderId()); message.getAppId(), message.getSenderId());
if (!ApplicationStatus.hasVisibleActivities() if (!ApplicationStatus.hasVisibleActivities()) {
&& LazySubscriptionsManager.isSubscriptionLazy(subscriptionId)) { boolean isSubscriptionLazy = false;
// TODO(https://crbug.com/882887): record a UMA metric for how long long time = SystemClock.elapsedRealtime();
// does it take to check if the subscription is lazy. if (LazySubscriptionsManager.isSubscriptionLazy(subscriptionId)) {
isSubscriptionLazy = true;
LazySubscriptionsManager.persistMessage(subscriptionId, message); LazySubscriptionsManager.persistMessage(subscriptionId, message);
}
// Use {@link CachedMetrics} so this gets reported when native is
// loaded instead of calling native right away.
new CachedMetrics
.TimesHistogramSample(
"PushMessaging.TimeToCheckIfSubscriptionLazy", TimeUnit.MILLISECONDS)
.record(SystemClock.elapsedRealtime() - time);
if (isSubscriptionLazy) {
return; return;
} }
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Bundle extras = message.toBundle(); Bundle extras = message.toBundle();
......
...@@ -4,15 +4,19 @@ ...@@ -4,15 +4,19 @@
package org.chromium.components.gcm_driver; package org.chromium.components.gcm_driver;
import android.os.SystemClock;
import org.chromium.base.Log; import org.chromium.base.Log;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
import org.chromium.base.VisibleForTesting; import org.chromium.base.VisibleForTesting;
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.metrics.RecordHistogram;
import org.chromium.base.task.AsyncTask; import org.chromium.base.task.AsyncTask;
import java.io.IOException; import java.io.IOException;
import java.util.Set; import java.util.Set;
import java.util.concurrent.TimeUnit;
/** /**
* This class is the Java counterpart to the C++ GCMDriverAndroid class. * This class is the Java counterpart to the C++ GCMDriverAndroid class.
...@@ -53,8 +57,7 @@ public class GCMDriver { ...@@ -53,8 +57,7 @@ public class GCMDriver {
// LazySubscriptionsManager.hasPersistedMessages() should be a cheap way // LazySubscriptionsManager.hasPersistedMessages() should be a cheap way
// to avoid unnecessary disk reads. // to avoid unnecessary disk reads.
if (LazySubscriptionsManager.hasPersistedMessages()) { if (LazySubscriptionsManager.hasPersistedMessages()) {
// TODO(https://crbug.com/882887): record a UMA metric for how long long time = SystemClock.elapsedRealtime();
// does it take to read all persisted messaged.
Set<String> lazySubscriptionIds = LazySubscriptionsManager.getLazySubscriptionIds(); Set<String> lazySubscriptionIds = LazySubscriptionsManager.getLazySubscriptionIds();
for (String id : lazySubscriptionIds) { for (String id : lazySubscriptionIds) {
GCMMessage[] messages = LazySubscriptionsManager.readMessages(id); GCMMessage[] messages = LazySubscriptionsManager.readMessages(id);
...@@ -64,6 +67,14 @@ public class GCMDriver { ...@@ -64,6 +67,14 @@ public class GCMDriver {
LazySubscriptionsManager.deletePersistedMessagesForSubscriptionId(id); LazySubscriptionsManager.deletePersistedMessagesForSubscriptionId(id);
} }
LazySubscriptionsManager.storeHasPersistedMessages(/*hasPersistedMessages=*/false); LazySubscriptionsManager.storeHasPersistedMessages(/*hasPersistedMessages=*/false);
long duration = SystemClock.elapsedRealtime() - time;
// Call RecordHistogram.recordTimesHistogram() on a background thread to avoid expensive
// JNI calls in the critical path.
AsyncTask.THREAD_POOL_EXECUTOR.execute(() -> {
RecordHistogram.recordTimesHistogram("PushMessaging.TimeToReadPersistedMessages",
duration, TimeUnit.MILLISECONDS);
});
} }
return sInstance; return sInstance;
} }
......
...@@ -86583,6 +86583,29 @@ uploading your change for review. ...@@ -86583,6 +86583,29 @@ uploading your change for review.
</summary> </summary>
</histogram> </histogram>
<histogram name="PushMessaging.TimeToCheckIfSubscriptionLazy" units="ms"
expires_after="2019-11-01">
<owner>mamir@chromium.org</owner>
<summary>
When a message arrives to a subscription while Chrome is in the background,
the subscription is checked first for being lazy, and accordingly the
message is forwarded or persisted on disk. Since this check may require disk
access, this histogram measures the time spent in checking if the
subscription is lazy.
</summary>
</histogram>
<histogram name="PushMessaging.TimeToReadPersistedMessages" units="ms"
expires_after="2019-11-01">
<owner>mamir@chromium.org</owner>
<summary>
When a message arrives for a lazy subscription and Chrome isn't in the
foreground, it is persisted on disk until next time Chrome is in the
foreground. This histogram measures the time spent in reading and replaying
persisted messages when Chrome goes to the foreground.
</summary>
</histogram>
<histogram name="PushMessaging.UnregistrationGCMResult" enum="GCMClientResult"> <histogram name="PushMessaging.UnregistrationGCMResult" enum="GCMClientResult">
<owner>johnme@google.com</owner> <owner>johnme@google.com</owner>
<summary> <summary>
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