Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Add telemetry for immersive mode duration time.
Browse files Browse the repository at this point in the history
  • Loading branch information
daoshengmu committed Sep 28, 2018
1 parent bd70ea7 commit d1c7161
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 24 deletions.
12 changes: 3 additions & 9 deletions app/src/common/shared/org/mozilla/vrbrowser/SessionStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import android.content.Context;
import android.graphics.Rect;
import android.os.SystemClock;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;
Expand All @@ -18,7 +17,6 @@
import org.mozilla.gecko.GeckoProfile;
import org.mozilla.geckoview.*;
import org.mozilla.vrbrowser.telemetry.TelemetryWrapper;
import org.mozilla.vrbrowser.utils.UrlUtils;

import java.io.File;
import java.io.FileNotFoundException;
Expand Down Expand Up @@ -48,8 +46,6 @@ public static SessionStore get() {
private LinkedList<SessionChangeListener> mSessionChangeListeners;
private LinkedList<GeckoSession.TextInputDelegate> mTextInputListeners;
private LinkedList<GeckoSession.PromptDelegate> mPromptListeners;
private final long MIN_LOAD_TIME = 40;
private long startLoadTime = 0;

public interface SessionChangeListener {
void onNewSession(GeckoSession aSession, int aId);
Expand Down Expand Up @@ -836,7 +832,7 @@ public void onPageStart(GeckoSession aSession, String aUri) {
return;
}
state.mIsLoading = true;
startLoadTime = SystemClock.elapsedRealtime();
TelemetryWrapper.startPageLoadTime();
for (GeckoSession.ProgressDelegate listener: mProgressListeners) {
listener.onPageStart(aSession, aUri);
}
Expand All @@ -851,10 +847,8 @@ public void onPageStop(GeckoSession aSession, boolean b) {
}

state.mIsLoading = false;
long elapsedLoad = SystemClock.elapsedRealtime() - startLoadTime;
if (elapsedLoad > MIN_LOAD_TIME && !isLocalizedContent(state.mUri)) {
Log.i(LOGTAG, "Sent load to histogram");
TelemetryWrapper.addLoadToHistogram(state.mUri, elapsedLoad);
if (!isLocalizedContent(state.mUri)) {
TelemetryWrapper.uploadPageLoadToHistogram(state.mUri);
}
for (GeckoSession.ProgressDelegate listener: mProgressListeners) {
listener.onPageStop(aSession, b);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.FrameLayout;
import com.mozilla.speechlibrary.MozillaSpeechService;
import org.mozilla.gecko.GeckoVRManager;
import org.mozilla.vrbrowser.audio.AudioEngine;
import org.mozilla.vrbrowser.audio.VRAudioTheme;
Expand Down Expand Up @@ -438,6 +437,7 @@ void pauseGeckoViewCompositor() {
return;
}
mIsPresentingImmersive = true;
TelemetryWrapper.startImmersive();
PauseCompositorRunnable runnable = new PauseCompositorRunnable();

synchronized (this) {
Expand All @@ -459,6 +459,7 @@ void resumeGeckoViewCompositor() {
return;
}
mIsPresentingImmersive = false;
TelemetryWrapper.uploadImmersiveToHistogram();
Handler handler = new Handler(Looper.getMainLooper());
handler.postDelayed(new Runnable() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Context;
import android.content.res.Resources;
import android.os.StrictMode;
import android.os.SystemClock;
import android.support.annotation.UiThread;
import android.util.Log;

Expand Down Expand Up @@ -31,13 +32,19 @@
public class TelemetryWrapper {
private final static String APP_NAME = "FirefoxReality";
private final static String LOGTAG = "VRB";
private final static int BUCKET_SIZE_MS = 100;
private final static int MIN_LOAD_TIME = 40;
private final static int LOADING_BUCKET_SIZE_MS = 100;
private final static int MIN_IMMERSIVE_TIME = 1000;
private final static int IMMERSIVE_BUCKET_SIZE_MS = 10000;
private final static int HISTOGRAM_MIN_INDEX = 0;
private final static int HISTOGRAM_SIZE = 200;

private static HashSet<String> domainMap = new HashSet<String>();
private static int[] histogram = new int[HISTOGRAM_SIZE];
private static int[] loadingTimeHistogram = new int[HISTOGRAM_SIZE];
private static int[] immersiveHistogram = new int[HISTOGRAM_SIZE];
private static int numUri = 0;
private static long startLoadPageTime = 0;
private static long startImmersiveTime = 0;

private class Category {
private static final String ACTION = "action";
Expand All @@ -52,6 +59,7 @@ private class Method {
private static final String TYPE_QUERY = "type_query";
// TODO: Support "select_query" after providing search suggestion.
private static final String VOICE_QUERY = "voice_query";
private static final String IMMERSIVE_MODE = "immersive_mode";
}

private class Object {
Expand Down Expand Up @@ -106,14 +114,27 @@ public static void start() {

@UiThread
public static void stop() {
TelemetryEvent histogramEvent = TelemetryEvent.create(Category.HISTOGRAM, Method.FOREGROUND, Object.BROWSER);
for (int bucketIndex = 0; bucketIndex < histogram.length; ++bucketIndex) {
histogramEvent.extra(Integer.toString(bucketIndex * BUCKET_SIZE_MS), Integer.toString(histogram[bucketIndex]));
// Upload loading time histogram
TelemetryEvent loadingHistogramEvent = TelemetryEvent.create(Category.HISTOGRAM, Method.FOREGROUND, Object.BROWSER);
for (int bucketIndex = 0; bucketIndex < loadingTimeHistogram.length; ++bucketIndex) {
loadingHistogramEvent.extra(Integer.toString(bucketIndex * LOADING_BUCKET_SIZE_MS),
Integer.toString(loadingTimeHistogram[bucketIndex]));
}
histogramEvent.queue();
loadingHistogramEvent.queue();

// Clear histogram array after queueing it
histogram = new int[HISTOGRAM_SIZE];
// Clear loading histogram array after queueing it
loadingTimeHistogram = new int[HISTOGRAM_SIZE];

// Upload immersive time histogram
TelemetryEvent immersiveHistogramEvent = TelemetryEvent.create(Category.HISTOGRAM, Method.IMMERSIVE_MODE, Object.BROWSER);
for (int bucketIndex = 0; bucketIndex < immersiveHistogram.length; ++bucketIndex) {
immersiveHistogramEvent.extra(Integer.toString(bucketIndex * IMMERSIVE_BUCKET_SIZE_MS),
Integer.toString(immersiveHistogram[bucketIndex]));
}
immersiveHistogramEvent.queue();

// Clear loading histogram array after queueing it
immersiveHistogram = new int[HISTOGRAM_SIZE];

// We only upload the domain and URI counts to the probes without including
// users' URI info.
Expand Down Expand Up @@ -176,27 +197,69 @@ private static void browseEvent() {
}

@UiThread
public static void addLoadToHistogram(String uri, Long newLoadTime) {
public static void startPageLoadTime() {
startLoadPageTime = SystemClock.elapsedRealtime();
}

@UiThread
public static void uploadPageLoadToHistogram(String uri) {
if (startLoadPageTime == 0) {
return;
}

URI uriLink = URI.create(uri);
if (uriLink.getHost() == null) {
return;
}

domainMap.add(UrlUtils.stripCommonSubdomains(uriLink.getHost()));
numUri++;
int histogramLoadIndex = toIntExact(newLoadTime / BUCKET_SIZE_MS);

long elapsedLoad = SystemClock.elapsedRealtime() - startLoadPageTime;
if (elapsedLoad < MIN_LOAD_TIME) {
return;
}

int histogramLoadIndex = toIntExact(elapsedLoad / LOADING_BUCKET_SIZE_MS);
Log.i(LOGTAG, "Sent load to histogram");

if (histogramLoadIndex > (HISTOGRAM_SIZE - 2)) {
histogramLoadIndex = HISTOGRAM_SIZE - 1;
Log.e(LOGTAG, "the loading histogram size is overflow.");
} else if (histogramLoadIndex < HISTOGRAM_MIN_INDEX) {
histogramLoadIndex = HISTOGRAM_MIN_INDEX;
}

if (histogramLoadIndex >= histogram.length) {
Log.e(LOGTAG, "the histogram size is overflow.");
histogramLoadIndex = histogram.length - 1;
loadingTimeHistogram[histogramLoadIndex]++;
}

@UiThread
public static void startImmersive() {
startImmersiveTime = SystemClock.elapsedRealtime();
}

@UiThread
public static void uploadImmersiveToHistogram() {
if (startImmersiveTime == 0) {
return;
}
histogram[histogramLoadIndex]++;

long elapsedImmersive = SystemClock.elapsedRealtime() - startImmersiveTime;
if (elapsedImmersive < MIN_IMMERSIVE_TIME) {
return;
}

int histogramImmersiveIndex = toIntExact(elapsedImmersive / IMMERSIVE_BUCKET_SIZE_MS);
Log.i(LOGTAG, "Send immersive time spent to histogram.");

if (histogramImmersiveIndex > (HISTOGRAM_SIZE - 2)) {
histogramImmersiveIndex = HISTOGRAM_SIZE - 1;
Log.e(LOGTAG, "the immersive histogram size is overflow.");
} else if (histogramImmersiveIndex < HISTOGRAM_MIN_INDEX) {
histogramImmersiveIndex = HISTOGRAM_MIN_INDEX;
}

immersiveHistogram[histogramImmersiveIndex]++;
}
}

0 comments on commit d1c7161

Please sign in to comment.