Commit 2b401f3e authored by bttk's avatar bttk Committed by Commit Bot

metrics: Randomly initialize CachedMetrics with histogram cache bypassed

Make CachedMetrics during initialization have 50% chance to have all
histogram samples bypass it's cache and immediately forward metrics to
RecordHistogram (which now uses CachingUmaRecorder).

The state of the bypass is reported with a synthetic field trial:
 -  AndroidCachedMetrics.Control
 -  AndroidCachedMetrics.HistogramsBypassCache

Bug: 1046181
Change-Id: I7fe1d9d4edf6ccf8a6b2dde0348324aaf797f032
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2031443
Commit-Queue: bttk <bttk@chromium.org>
Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Reviewed-by: default avatarAlexei Svitkine <asvitkine@chromium.org>
Reviewed-by: default avatarSky Malice <skym@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738384}
parent c27e2e63
...@@ -28,6 +28,12 @@ public class CachedMetrics { ...@@ -28,6 +28,12 @@ public class CachedMetrics {
@GuardedBy("sMetrics") @GuardedBy("sMetrics")
private static final List<CachedMetric> sMetrics = new ArrayList<CachedMetric>(); private static final List<CachedMetric> sMetrics = new ArrayList<CachedMetric>();
/**
* Randomly choose whether to always immediately invoke {@link RecordHistogram}. This value
* is recorded using a synthetic field trial.
*/
protected static final boolean HISTOGRAMS_BYPASS_CACHE = Math.random() < 0.5;
protected final String mName; protected final String mName;
protected boolean mCached; protected boolean mCached;
...@@ -59,6 +65,19 @@ public class CachedMetrics { ...@@ -59,6 +65,19 @@ public class CachedMetrics {
*/ */
@GuardedBy("sMetrics") @GuardedBy("sMetrics")
protected abstract void commitAndClear(); protected abstract void commitAndClear();
/**
* Returns {@code true} if histogram samples should be immediately recorded.
* <p>
* Handles two cases:
* <ul>
* <li>Cache is not needed, because {@link LibraryLoader} is already initialized.
* <li>Cache is disabled to validate caching present in {@link RecordHistogram}.
* </ul>
*/
protected static boolean shouldHistogramBypassCache() {
return HISTOGRAMS_BYPASS_CACHE || LibraryLoader.getInstance().isInitialized();
}
} }
/** /**
...@@ -113,7 +132,7 @@ public class CachedMetrics { ...@@ -113,7 +132,7 @@ public class CachedMetrics {
public void record(int sample) { public void record(int sample) {
synchronized (CachedMetric.sMetrics) { synchronized (CachedMetric.sMetrics) {
if (LibraryLoader.getInstance().isInitialized()) { if (shouldHistogramBypassCache()) {
recordWithNative(sample); recordWithNative(sample);
} else { } else {
mSamples.add(sample); mSamples.add(sample);
...@@ -153,7 +172,7 @@ public class CachedMetrics { ...@@ -153,7 +172,7 @@ public class CachedMetrics {
public void record(int sample) { public void record(int sample) {
synchronized (CachedMetric.sMetrics) { synchronized (CachedMetric.sMetrics) {
if (LibraryLoader.getInstance().isInitialized()) { if (shouldHistogramBypassCache()) {
recordWithNative(sample); recordWithNative(sample);
} else { } else {
mSamples.add(sample); mSamples.add(sample);
...@@ -192,7 +211,7 @@ public class CachedMetrics { ...@@ -192,7 +211,7 @@ public class CachedMetrics {
public void record(long sample) { public void record(long sample) {
synchronized (CachedMetric.sMetrics) { synchronized (CachedMetric.sMetrics) {
if (LibraryLoader.getInstance().isInitialized()) { if (shouldHistogramBypassCache()) {
recordWithNative(sample); recordWithNative(sample);
} else { } else {
mSamples.add(sample); mSamples.add(sample);
...@@ -249,7 +268,7 @@ public class CachedMetrics { ...@@ -249,7 +268,7 @@ public class CachedMetrics {
public void record(boolean sample) { public void record(boolean sample) {
synchronized (CachedMetric.sMetrics) { synchronized (CachedMetric.sMetrics) {
if (LibraryLoader.getInstance().isInitialized()) { if (shouldHistogramBypassCache()) {
recordWithNative(sample); recordWithNative(sample);
} else { } else {
mSamples.add(sample); mSamples.add(sample);
...@@ -295,7 +314,7 @@ public class CachedMetrics { ...@@ -295,7 +314,7 @@ public class CachedMetrics {
public void record(int sample) { public void record(int sample) {
synchronized (CachedMetric.sMetrics) { synchronized (CachedMetric.sMetrics) {
if (LibraryLoader.getInstance().isInitialized()) { if (shouldHistogramBypassCache()) {
recordWithNative(sample); recordWithNative(sample);
} else { } else {
mSamples.add(sample); mSamples.add(sample);
...@@ -385,4 +404,9 @@ public class CachedMetrics { ...@@ -385,4 +404,9 @@ public class CachedMetrics {
} }
} }
} }
/** Returns true if histograms are immediately recorded with {@link UmaRecorder}. */
public static boolean histogramsBypassCache() {
return CachedMetric.HISTOGRAMS_BYPASS_CACHE;
}
} }
...@@ -95,6 +95,10 @@ public class LaunchMetrics { ...@@ -95,6 +95,10 @@ public class LaunchMetrics {
} }
sHomeScreenLaunches.clear(); sHomeScreenLaunches.clear();
String cachedMetricsGroup =
CachedMetrics.histogramsBypassCache() ? "HistogramsBypassCache" : "Control";
UmaSessionStats.registerSyntheticFieldTrial("AndroidCachedMetrics", cachedMetricsGroup);
// Record generic cached events. // Record generic cached events.
CachedMetrics.commitCachedMetrics(); CachedMetrics.commitCachedMetrics();
} }
......
...@@ -10,6 +10,7 @@ import android.content.res.Configuration; ...@@ -10,6 +10,7 @@ import android.content.res.Configuration;
import android.text.TextUtils; import android.text.TextUtils;
import org.chromium.base.ApplicationStatus; import org.chromium.base.ApplicationStatus;
import org.chromium.base.Log;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.NativeMethods; import org.chromium.base.annotations.NativeMethods;
import org.chromium.base.library_loader.LibraryProcessType; import org.chromium.base.library_loader.LibraryProcessType;
...@@ -33,6 +34,7 @@ import org.chromium.content_public.browser.WebContents; ...@@ -33,6 +34,7 @@ import org.chromium.content_public.browser.WebContents;
* and the framework's MetricService. * and the framework's MetricService.
*/ */
public class UmaSessionStats { public class UmaSessionStats {
private static final String TAG = "UmaSessionStats";
private static final String SAMSUNG_MULTWINDOW_PACKAGE = "com.sec.feature.multiwindow"; private static final String SAMSUNG_MULTWINDOW_PACKAGE = "com.sec.feature.multiwindow";
private static long sNativeUmaSessionStats; private static long sNativeUmaSessionStats;
...@@ -213,6 +215,7 @@ public class UmaSessionStats { ...@@ -213,6 +215,7 @@ public class UmaSessionStats {
} }
public static void registerSyntheticFieldTrial(String trialName, String groupName) { public static void registerSyntheticFieldTrial(String trialName, String groupName) {
Log.d(TAG, "registerSyntheticFieldTrial(%s, %s)", trialName, groupName);
assert isMetricsServiceAvailable(); assert isMetricsServiceAvailable();
UmaSessionStatsJni.get().registerSyntheticFieldTrial(trialName, groupName); UmaSessionStatsJni.get().registerSyntheticFieldTrial(trialName, groupName);
} }
......
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