Commit a3249b80 authored by Mohamed Amir Yosef's avatar Mohamed Amir Yosef Committed by Commit Bot

[FCM] Report number of queued messages using CachedMetrics

This CL uses CachedMetric to record the histogram for number of queued
messages instead of using RecordHistogram directly.

RecordHistogram call native directly and hence falsifies the whole
purpose of queuing FCM messages (to avoid calling the native code)

In order to test the behavior, ShadowRecordHistogram had to implement
the method recordCustomCountHistogram() of RecordHistogram.
The reason is CachedMetric is internally using this method directly
instead of the proxy methods such as recordCount100Histogram().

Bug: 882887
Change-Id: I15e9e77ab96cf65084242443a1a134c5df00f7fd
Reviewed-on: https://chromium-review.googlesource.com/c/1340000Reviewed-by: default avatarPeter Conn <peconn@chromium.org>
Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Reviewed-by: default avatarTommy Nyquist <nyquist@chromium.org>
Commit-Queue: Mohamed Amir Yosef <mamir@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608879}
parent 9d52dc48
...@@ -10,6 +10,7 @@ import org.robolectric.annotation.Implementation; ...@@ -10,6 +10,7 @@ import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements; import org.robolectric.annotation.Implements;
import org.robolectric.annotation.Resetter; import org.robolectric.annotation.Resetter;
import org.chromium.base.metrics.CachedMetrics;
import org.chromium.base.metrics.RecordHistogram; import org.chromium.base.metrics.RecordHistogram;
import java.util.HashMap; import java.util.HashMap;
...@@ -41,6 +42,13 @@ public class ShadowRecordHistogram { ...@@ -41,6 +42,13 @@ public class ShadowRecordHistogram {
incrementSampleCount(key); incrementSampleCount(key);
} }
@Implementation
public static void recordCustomCountHistogram(
String name, int sample, int min, int max, int numBuckets) {
Pair<String, Integer> key = Pair.create(name, sample);
incrementSampleCount(key);
}
@Implementation @Implementation
public static void recordEnumeratedHistogram(String name, int sample, int boundary) { public static void recordEnumeratedHistogram(String name, int sample, int boundary) {
assert sample < boundary : "Sample " + sample + " is not within boundary " + boundary + "!"; assert sample < boundary : "Sample " + sample + " is not within boundary " + boundary + "!";
...@@ -55,6 +63,7 @@ public class ShadowRecordHistogram { ...@@ -55,6 +63,7 @@ public class ShadowRecordHistogram {
@Implementation @Implementation
public static int getHistogramValueCountForTesting(String name, int sample) { public static int getHistogramValueCountForTesting(String name, int sample) {
CachedMetrics.commitCachedMetrics();
Integer i = sSamples.get(Pair.create(name, sample)); Integer i = sSamples.get(Pair.create(name, sample));
return (i != null) ? i : 0; return (i != null) ? i : 0;
} }
......
...@@ -15,7 +15,7 @@ import org.chromium.base.ContextUtils; ...@@ -15,7 +15,7 @@ import org.chromium.base.ContextUtils;
import org.chromium.base.Log; import org.chromium.base.Log;
import org.chromium.base.StrictModeContext; import org.chromium.base.StrictModeContext;
import org.chromium.base.VisibleForTesting; import org.chromium.base.VisibleForTesting;
import org.chromium.base.metrics.RecordHistogram; import org.chromium.base.metrics.CachedMetrics;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
...@@ -151,8 +151,10 @@ public class LazySubscriptionsManager { ...@@ -151,8 +151,10 @@ public class LazySubscriptionsManager {
queueJSON = filterMessageBasedOnCollapseKey(queueJSON, message.getCollapseKey()); queueJSON = filterMessageBasedOnCollapseKey(queueJSON, message.getCollapseKey());
} }
RecordHistogram.recordCount100Histogram( // Use {@link CachedMetrics} so this gets reported when native is
"PushMessaging.QueuedMessagesCount", queueJSON.length()); // loaded instead of calling native right away.
new CachedMetrics.Count100HistogramSample("PushMessaging.QueuedMessagesCount")
.record(queueJSON.length());
// If the queue is full remove the oldest message. // If the queue is full remove the oldest message.
if (queueJSON.length() == MESSAGES_QUEUE_SIZE) { if (queueJSON.length() == MESSAGES_QUEUE_SIZE) {
......
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