Skip to content

Commit

Permalink
Adding multiple window Glean telemetry.
Browse files Browse the repository at this point in the history
  • Loading branch information
daoshengmu committed May 27, 2020
1 parent 423851d commit b2483e8
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,24 @@
import org.mozilla.vrbrowser.GleanMetrics.Control;
import org.mozilla.vrbrowser.GleanMetrics.Pages;
import org.mozilla.vrbrowser.GleanMetrics.Immersive;
import org.mozilla.vrbrowser.GleanMetrics.Windows;
import org.mozilla.vrbrowser.browser.SettingsStore;
import org.mozilla.vrbrowser.search.SearchEngineWrapper;
import org.mozilla.vrbrowser.utils.DeviceType;
import org.mozilla.vrbrowser.utils.SystemUtils;
import org.mozilla.vrbrowser.utils.UrlUtils;
import static org.mozilla.vrbrowser.ui.widgets.Windows.WindowPlacement; // need?
import static org.mozilla.vrbrowser.ui.widgets.Windows.MAX_WINDOWS;

import java.net.URI;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Map;

import mozilla.components.service.glean.Glean;
import mozilla.components.service.glean.config.Configuration;
import mozilla.telemetry.glean.GleanTimerId;


public class GleanMetricsService {
Expand All @@ -40,6 +45,10 @@ public class GleanMetricsService {
private static HashSet<String> domainMap = new HashSet<String>();
private static Map<String, GleanTimerId> loadingTimerId = new Hashtable<>();
private static GleanTimerId immersiveTimerId;
private static Map<Integer, GleanTimerId> windowLifeTimerId = new Hashtable<>();
private static GleanTimerId activeWindowTimerId[] = new GleanTimerId[MAX_WINDOWS];
private static GleanTimerId openWindowTimerId[] = new GleanTimerId[MAX_WINDOWS];
private static GleanTimerId openPrivateWindowTimerId[] = new GleanTimerId[MAX_WINDOWS];

// We should call this at the application initial stage.
public static void init(Context aContext) {
Expand Down Expand Up @@ -99,12 +108,118 @@ public static void stopPageLoadTimeWithURI(String uri) {
} catch (IllegalArgumentException e) {
Log.e(LOGTAG, "Invalid URL", e);
}
}

public static void windowsResizeEvent() {
Windows.INSTANCE.resize().add();
}

public static void windowsMoveEvent() {
Windows.INSTANCE.movement().add();
}

public static void activePlacementEvent(int from, boolean active) {
if (active) {
if (from == WindowPlacement.FRONT.getValue()) {
activeWindowTimerId[from] = Windows.INSTANCE.activeInFrontTime().start();
} else if (from == WindowPlacement.LEFT.getValue()) {
activeWindowTimerId[from] = Windows.INSTANCE.activeInLeftTime().start();
} else if (from == WindowPlacement.RIGHT.getValue()) {
activeWindowTimerId[from] = Windows.INSTANCE.activeInRightTime().start();
} else {
Log.d(LOGTAG,"Undefined WindowPlacement type: " + from);
}
} else {
if (from == WindowPlacement.FRONT.getValue()) {
Windows.INSTANCE.activeInFrontTime().stopAndAccumulate(activeWindowTimerId[from]);
} else if (from == WindowPlacement.LEFT.getValue()) {
Windows.INSTANCE.activeInLeftTime().stopAndAccumulate(activeWindowTimerId[from]);
} else if (from == WindowPlacement.RIGHT.getValue()) {
Windows.INSTANCE.activeInRightTime().stopAndAccumulate(activeWindowTimerId[from]);
} else {
Log.d(LOGTAG,"Undefined WindowPlacement type: " + from);
}
}
}

public static void openWindowsEvent(int from, int to, boolean isPrivate) {
if (isPrivate) {
switch (from) {
case 1:
openPrivateWindowTimerId[from - 1] = Windows.INSTANCE.singlePriWindowOpenedTime().start();
break;
case 2:
openPrivateWindowTimerId[from - 1] = Windows.INSTANCE.doublePriWindowOpenedTime().start();
break;
case 3:
openPrivateWindowTimerId[from - 1] = Windows.INSTANCE.triplePriWindowOpenedTime().start();
break;
}
if (to > 0) {
String label = "";
GleanTimerId timerId = openPrivateWindowTimerId[to - 1];
switch (to) {
case 1:
label = "single";
Windows.INSTANCE.singlePriWindowOpenedTime().stopAndAccumulate(timerId);
break;
case 2:
label = "double";
Windows.INSTANCE.doublePriWindowOpenedTime().stopAndAccumulate(timerId);
break;
case 3:
label = "triple";
Windows.INSTANCE.triplePriWindowOpenedTime().stopAndAccumulate(timerId);
break;
default:
break;
}
Windows.INSTANCE.getOpenedPriWindowCount().get(label).add();
}
} else {
switch (from) {
case 1:
openWindowTimerId[from - 1] = Windows.INSTANCE.singleWindowOpenedTime().start();
break;
case 2:
openWindowTimerId[from - 1] = Windows.INSTANCE.doubleWindowOpenedTime().start();
break;
case 3:
openWindowTimerId[from - 1] = Windows.INSTANCE.tripleWindowOpenedTime().start();
break;
}
if (to > 0) {
String label = "";
GleanTimerId timerId = openWindowTimerId[to - 1];
switch (to) {
case 1:
label = "single";
Windows.INSTANCE.singleWindowOpenedTime().stopAndAccumulate(timerId);
break;
case 2:
label = "double";
Windows.INSTANCE.doubleWindowOpenedTime().stopAndAccumulate(timerId);
break;
case 3:
label = "triple";
Windows.INSTANCE.tripleWindowOpenedTime().stopAndAccumulate(timerId);
break;
default:
break;
}
Windows.INSTANCE.getOpenedWindowCount().get(label).add();
}
}
}

public static void sessionStop() {
domainMap.clear();
loadingTimerId.clear();
windowLifeTimerId.clear();
activeWindowTimerId = new GleanTimerId[MAX_WINDOWS];
openWindowTimerId = new GleanTimerId[MAX_WINDOWS];
openPrivateWindowTimerId = new GleanTimerId[MAX_WINDOWS];

Pings.INSTANCE.sessionEnd().submit();
}

Expand Down Expand Up @@ -140,19 +255,18 @@ public static void stopImmersive() {
// TODO: Confirm if we don't need multiple metrics for tracking window open duration.
// like WindowLifetime1 ~ WindowLifetimeN for multiple windows.
public static void openWindowEvent(int windowId) {
// TODO: Blocked by Bug 1595914 and Bug 1595723.
// GleanTimerId id = Durarion.INSTANCE.getWindowLifetime().start();
// windowLifetimeId.put(windowId, id);
GleanTimerId timerId = Windows.INSTANCE.duration().start();
windowLifeTimerId.put(windowId, timerId);
}

public static void closeWindowEvent(int windowId) {
// TODO: Blocked by Bug 1595914 and Bug 1595723.
// if (windowLifetimeId.containsKey(windowId)) {
// Durarion.INSTANCE.getWindowLifetime().stopAndAccumulate(windowLifetimeId.get(windowId));
// windowLifetimeId.remove(windowId);
// } else {
// Log.e(LOGTAG, "Can't find window id.");
// }
if (windowLifeTimerId.containsKey((windowId))) {
GleanTimerId timerId = windowLifeTimerId.get(windowId);
Windows.INSTANCE.duration().stopAndAccumulate(timerId);
windowLifeTimerId.remove(windowId);
} else {
Log.e(LOGTAG, "Can't find close window id.");
}
}

private static String getDefaultSearchEngineIdentifierForTelemetry() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.mozilla.vrbrowser.databinding.NavigationBarBinding;
import org.mozilla.vrbrowser.db.SitePermission;
import org.mozilla.vrbrowser.search.suggestions.SuggestionsProvider;
import org.mozilla.vrbrowser.telemetry.GleanMetricsService;
import org.mozilla.vrbrowser.telemetry.TelemetryWrapper;
import org.mozilla.vrbrowser.ui.viewmodel.TrayViewModel;
import org.mozilla.vrbrowser.ui.viewmodel.WindowViewModel;
Expand Down Expand Up @@ -754,6 +755,7 @@ private void exitResizeMode(ResizeAction aResizeAction) {

if (aResizeAction == ResizeAction.KEEP_SIZE) {
TelemetryWrapper.windowsResizeEvent();
GleanMetricsService.windowsResizeEvent();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -660,17 +660,10 @@ public void disableVRVideoMode() {
}

public void setWindowPlacement(@NonNull Windows.WindowPlacement aPlacement) {
if (mActive) {
TelemetryWrapper.activePlacementEvent(mWindowPlacement.getValue(), false);
}

mWindowPlacement = aPlacement;

mViewModel.setPlacement(mWindowPlacement);

if (mActive) {
TelemetryWrapper.activePlacementEvent(mWindowPlacement.getValue(), true);
}
TelemetryWrapper.activePlacementEvent(mWindowPlacement.getValue(), mActive);
GleanMetricsService.activePlacementEvent(mWindowPlacement.getValue(), mActive);
}

public void setIsOnlyWindow(boolean isOnlyWindow) {
Expand Down Expand Up @@ -729,6 +722,7 @@ public void setActiveWindow(boolean active) {
hideContextMenus();

TelemetryWrapper.activePlacementEvent(mWindowPlacement.getValue(), mActive);
GleanMetricsService.activePlacementEvent(mWindowPlacement.getValue(), mActive);
updateBorder();

mViewModel.setIsActiveWindow(active);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -775,8 +775,10 @@ private void removeWindow(@NonNull WindowWidget aWindow) {

if (mPrivateMode) {
TelemetryWrapper.openWindowsEvent(mPrivateWindows.size() + 1, mPrivateWindows.size(), true);
GleanMetricsService.openWindowsEvent(mPrivateWindows.size() + 1, mPrivateWindows.size(), true);
} else {
TelemetryWrapper.openWindowsEvent(mRegularWindows.size() + 1, mRegularWindows.size(), false);
GleanMetricsService.openWindowsEvent(mRegularWindows.size() + 1, mRegularWindows.size(), false);
}
}

Expand Down Expand Up @@ -937,8 +939,10 @@ private WindowWidget createWindow(@Nullable Session aSession) {

if (mPrivateMode) {
TelemetryWrapper.openWindowsEvent(mPrivateWindows.size() - 1, mPrivateWindows.size(), true);
GleanMetricsService.openWindowsEvent(mPrivateWindows.size() - 1, mPrivateWindows.size(), true);
} else {
TelemetryWrapper.openWindowsEvent(mRegularWindows.size() - 1, mRegularWindows.size(), false);
GleanMetricsService.openWindowsEvent(mRegularWindows.size() - 1, mRegularWindows.size(), false);
}

mForcedCurvedMode = getCurrentWindows().size() > 1;
Expand Down Expand Up @@ -1084,6 +1088,7 @@ public void onMoveLeftClicked(TopBarWidget aWidget) {
WindowWidget window = aWidget.getAttachedWindow();
if (window != null) {
TelemetryWrapper.windowsMoveEvent();
GleanMetricsService.windowsMoveEvent();

moveWindowLeft(window);
}
Expand All @@ -1094,6 +1099,7 @@ public void onMoveRightClicked(TopBarWidget aWidget) {
WindowWidget window = aWidget.getAttachedWindow();
if (window != null) {
TelemetryWrapper.windowsMoveEvent();
GleanMetricsService.windowsMoveEvent();

moveWindowRight(window);
}
Expand Down
14 changes: 14 additions & 0 deletions docs/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ The following metrics are added to the ping:
| pages.page_load |[timing_distribution](https://mozilla.github.io/glean/book/user/metrics/timing_distribution.html) |Measuring how long each page takes to load. |[1](https://github.com/MozillaReality/FirefoxReality/pull/xxx)||2020-11-01 |
| searches.counts |[labeled_counter](https://mozilla.github.io/glean/book/user/metrics/labeled_counters.html) |Counting how many searches are queried in a specific search engine. The search engine `identifier`s are used as keys for this metric. |[1](https://github.com/MozillaReality/FirefoxReality/pull/2241#issuecomment-557740258), [2](https://github.com/MozillaReality/FirefoxReality/pull/3199#issuecomment-617938749)||2020-11-01 |
| url.query_type |[labeled_counter](https://mozilla.github.io/glean/book/user/metrics/labeled_counters.html) |Counting how many URLs are visited in a day, by input method. |[1](https://github.com/MozillaReality/FirefoxReality/pull/2241#issuecomment-557740258), [2](https://github.com/MozillaReality/FirefoxReality/pull/3199#issuecomment-617938749)|<ul><li>type_link</li><li>type_query</li><li>voice_query</li></ul>|2020-11-01 |
| windows.duration |[timing_distribution](https://mozilla.github.io/glean/book/user/metrics/timing_distribution.html) |Measuring how long windows keep opening. |[1](https://github.com/MozillaReality/FirefoxReality/pull/xxx)||2020-11-01 |

## session-end

Expand All @@ -72,6 +73,19 @@ The following metrics are added to the ping:
| tabs.opened |[labeled_counter](https://mozilla.github.io/glean/book/user/metrics/labeled_counters.html) |Number of tabs opened during a session |[1](https://github.com/MozillaReality/FirefoxReality/pull/2327#issuecomment-559103837), [2](https://github.com/MozillaReality/FirefoxReality/pull/3199#issuecomment-617938749)|<ul><li>context_menu</li><li>tabs_dialog</li><li>bookmarks</li><li>history</li><li>fxa_login</li><li>received</li><li>pre_existing</li><li>browser</li><li>downloads</li></ul>|2020-11-01 |
| url.domains |[counter](https://mozilla.github.io/glean/book/user/metrics/counter.html) |Counting how many domains are visited in a session. |[1](https://github.com/MozillaReality/FirefoxReality/pull/2241#issuecomment-557740258), [2](https://github.com/MozillaReality/FirefoxReality/pull/3199#issuecomment-617938749)||2020-11-01 |
| url.visits |[counter](https://mozilla.github.io/glean/book/user/metrics/counter.html) |Counting how many URL links are visited in a session. |[1](https://github.com/MozillaReality/FirefoxReality/pull/2241#issuecomment-557740258), [2](https://github.com/MozillaReality/FirefoxReality/pull/3199#issuecomment-617938749)||2020-11-01 |
| windows.active_in_front_time |[timing_distribution](https://mozilla.github.io/glean/book/user/metrics/timing_distribution.html) |Measuring how long a window is placed at the front in a session. |[1](https://github.com/MozillaReality/FirefoxReality/pull/xxx)||2020-11-01 |
| windows.active_in_left_time |[timing_distribution](https://mozilla.github.io/glean/book/user/metrics/timing_distribution.html) |Measuring how long a window is placed at the left in a session. |[1](https://github.com/MozillaReality/FirefoxReality/pull/xxx)||2020-11-01 |
| windows.active_in_right_time |[timing_distribution](https://mozilla.github.io/glean/book/user/metrics/timing_distribution.html) |Measuring how long a window is placed at the right in a session. |[1](https://github.com/MozillaReality/FirefoxReality/pull/xxx)||2020-11-01 |
| windows.double_pri_window_opened_time |[timing_distribution](https://mozilla.github.io/glean/book/user/metrics/timing_distribution.html) |Measuring how long a user uses double private windows in a session. |[1](https://github.com/MozillaReality/FirefoxReality/pull/xxx)||2020-11-01 |
| windows.double_window_opened_time |[timing_distribution](https://mozilla.github.io/glean/book/user/metrics/timing_distribution.html) |Measuring how long a user uses double windows in a session. |[1](https://github.com/MozillaReality/FirefoxReality/pull/xxx)||2020-11-01 |
| windows.movement |[counter](https://mozilla.github.io/glean/book/user/metrics/counter.html) |Counting how many times of moving a window in a session. |[1](https://github.com/MozillaReality/FirefoxReality/pull/xxx)||2020-11-01 |
| windows.opened_pri_window_count |[labeled_counter](https://mozilla.github.io/glean/book/user/metrics/labeled_counters.html) |Counting which multiple private window mode (single, double, triple) user are using in a session. |[1](https://github.com/MozillaReality/FirefoxReality/pull/xxx)|<ul><li>single</li><li>double</li><li>triple</li></ul>|2020-11-01 |
| windows.opened_window_count |[labeled_counter](https://mozilla.github.io/glean/book/user/metrics/labeled_counters.html) |Counting which multiple window mode (single, double, triple) user are using in a session. |[1](https://github.com/MozillaReality/FirefoxReality/pull/xxx)|<ul><li>single</li><li>double</li><li>triple</li></ul>|2020-11-01 |
| windows.resize |[counter](https://mozilla.github.io/glean/book/user/metrics/counter.html) |Counting how many times of resizing a window in a session. |[1](https://github.com/MozillaReality/FirefoxReality/pull/xxx)||2020-11-01 |
| windows.single_pri_window_opened_time |[timing_distribution](https://mozilla.github.io/glean/book/user/metrics/timing_distribution.html) |Measuring how long a user uses single private window in a session. |[1](https://github.com/MozillaReality/FirefoxReality/pull/xxx)||2020-11-01 |
| windows.single_window_opened_time |[timing_distribution](https://mozilla.github.io/glean/book/user/metrics/timing_distribution.html) |Measuring how long a user uses single window in a session. |[1](https://github.com/MozillaReality/FirefoxReality/pull/xxx)||2020-11-01 |
| windows.triple_pri_window_opened_time |[timing_distribution](https://mozilla.github.io/glean/book/user/metrics/timing_distribution.html) |Measuring how long a user uses triple private windows in a session. |[1](https://github.com/MozillaReality/FirefoxReality/pull/xxx)||2020-11-01 |
| windows.triple_window_opened_time |[timing_distribution](https://mozilla.github.io/glean/book/user/metrics/timing_distribution.html) |Measuring how long a user uses triple window in a session. |[1](https://github.com/MozillaReality/FirefoxReality/pull/xxx)||2020-11-01 |


<!-- AUTOGENERATED BY glean_parser. DO NOT EDIT. -->
Expand Down

0 comments on commit b2483e8

Please sign in to comment.