Skip to content

Commit

Permalink
[AW] Support recording user actions in nonembedded UmaRecorder
Browse files Browse the repository at this point in the history
Fixed: 1082475
Test: bin/run_android_webview_junit_tests -f "*AwNonembeddedUmaReplayerTest*"
Test: bin/run_webview_instrumentation_test_apk -f "*AwNonembeddedUmaRecorderTest*"
Change-Id: I4a0224ad47010b0fcfee6d3eb106398f906803fa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2232839
Commit-Queue: Hazem Ashmawy <hazems@chromium.org>
Reviewed-by: Richard Coles <torne@chromium.org>
Reviewed-by: Nate Fischer <ntfschr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#776985}
  • Loading branch information
HazemSamir authored and Commit Bot committed Jun 10, 2020
1 parent 6b44366 commit 0a03b40
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ private static void replaySparseHistogram(HistogramRecord proto) {
UmaRecorderHolder.get().recordSparseHistogram(proto.getHistogramName(), proto.getSample());
}

/**
* Extract method arguments from the given {@link HistogramRecord} and call
* {@link org.chromium.base.metrics.UmaRecorder#recordUserAction}.
*/
private static void replayUserAction(HistogramRecord proto) {
assert proto.getRecordType() == RecordType.USER_ACTION;

UmaRecorderHolder.get().recordUserAction(
proto.getHistogramName(), proto.getElapsedRealtimeMillis());
}

/**
* Replay UMA API call record by calling that API method.
*
Expand All @@ -86,6 +97,9 @@ public static void replayMethodCall(HistogramRecord methodCall) {
case HISTOGRAM_SPARSE:
replaySparseHistogram(methodCall);
break;
case USER_ACTION:
replayUserAction(methodCall);
break;
default:
Log.d(TAG, "Unrecognized record type");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,22 @@ public void testRecordSparseHistogram() throws Throwable {
Assert.assertArrayEquals(recordProto.toByteArray(), recordedData);
}

@Test
@MediumTest
public void testRecordUserAction() throws Throwable {
String histogramName = "testRecordUserAction";
long elapsedRealtimeMillis = 123456789101112L;
HistogramRecord recordProto = HistogramRecord.newBuilder()
.setRecordType(RecordType.USER_ACTION)
.setHistogramName(histogramName)
.setElapsedRealtimeMillis(elapsedRealtimeMillis)
.setMetadata(TEST_METADATA)
.build();
mUmaRecorder.recordUserAction(histogramName, elapsedRealtimeMillis);
byte[] recordedData = MockMetricsBridgeService.getReceivedDataAfter(1);
Assert.assertArrayEquals(recordProto.toByteArray(), recordedData);
}

@Test
@MediumTest
public void testRecordMultipleHistograms() throws Throwable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,18 @@ public void testReplaySparseHistogram() {
AwNonembeddedUmaReplayer.replayMethodCall(recordProto);
verify(mUmaRecorder).recordSparseHistogram(histogramName, sample);
}

@Test
@SmallTest
public void testReplayUserAction() {
String histogramName = "testReplayUserAction";
long elapsedRealtimeMillis = 123456789101112L;
HistogramRecord recordProto = HistogramRecord.newBuilder()
.setRecordType(RecordType.USER_ACTION)
.setHistogramName(histogramName)
.setElapsedRealtimeMillis(elapsedRealtimeMillis)
.build();
AwNonembeddedUmaReplayer.replayMethodCall(recordProto);
verify(mUmaRecorder).recordUserAction(histogramName, elapsedRealtimeMillis);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,13 @@ public void recordSparseHistogram(String name, int sample) {
*/
@Override
public void recordUserAction(String name, long elapsedRealtimeMillis) {
// Assertion is disabled in release
// TODO(https://crbug.com/1082475) support recording user actions.
assert false : "Recording UserAction in non-embedded WebView processes isn't supported yet";
HistogramRecord record = HistogramRecord.newBuilder()
.setRecordType(RecordType.USER_ACTION)
.setHistogramName(name)
.setElapsedRealtimeMillis(elapsedRealtimeMillis)
.build();

recordHistogram(record);
}

private final Object mLock = new Object();
Expand Down
8 changes: 6 additions & 2 deletions android_webview/proto/metrics_bridge_records.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ option java_package = "org.chromium.android_webview.proto";
// MetricsBridgeService receives to a file and retrieve it back. These
// histogram records are recorded in non-embedded WebView processes.
//
// Next tag: 8
// Next tag: 9
message HistogramRecord {
// Next tag: 4
// Next tag: 5
enum RecordType {
HISTOGRAM_BOOLEAN = 0;
HISTOGRAM_EXPONENTIAL = 1;
HISTOGRAM_LINEAR = 2;
HISTOGRAM_SPARSE = 3;
USER_ACTION = 4;
}
RecordType record_type = 1;

Expand Down Expand Up @@ -54,4 +55,7 @@ message HistogramRecord {
int64 time_recorded = 1;
}
Metadata metadata = 7;

// Used for |record_type| == USER_ACTION only.
int64 elapsed_realtime_millis = 8;
}

0 comments on commit 0a03b40

Please sign in to comment.