From b2483e8a5291c98449f7403a5b0f4bccdc1c3607 Mon Sep 17 00:00:00 2001 From: Daosheng Mu Date: Wed, 27 May 2020 16:40:10 -0700 Subject: [PATCH] Adding multiple window Glean telemetry. --- .../telemetry/GleanMetricsService.java | 134 ++++++++++++++++-- .../ui/widgets/NavigationBarWidget.java | 2 + .../vrbrowser/ui/widgets/WindowWidget.java | 12 +- .../mozilla/vrbrowser/ui/widgets/Windows.java | 6 + docs/metrics.md | 14 ++ 5 files changed, 149 insertions(+), 19 deletions(-) diff --git a/app/src/common/shared/org/mozilla/vrbrowser/telemetry/GleanMetricsService.java b/app/src/common/shared/org/mozilla/vrbrowser/telemetry/GleanMetricsService.java index e51fb2e317..d458d78449 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/telemetry/GleanMetricsService.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/telemetry/GleanMetricsService.java @@ -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 { @@ -40,6 +45,10 @@ public class GleanMetricsService { private static HashSet domainMap = new HashSet(); private static Map loadingTimerId = new Hashtable<>(); private static GleanTimerId immersiveTimerId; + private static Map 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) { @@ -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(); } @@ -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() { diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/NavigationBarWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/NavigationBarWidget.java index 1e3d920797..984024de77 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/NavigationBarWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/NavigationBarWidget.java @@ -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; @@ -754,6 +755,7 @@ private void exitResizeMode(ResizeAction aResizeAction) { if (aResizeAction == ResizeAction.KEEP_SIZE) { TelemetryWrapper.windowsResizeEvent(); + GleanMetricsService.windowsResizeEvent(); } } diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WindowWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WindowWidget.java index 1a2d3a5b67..e5580f54a6 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WindowWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WindowWidget.java @@ -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) { @@ -729,6 +722,7 @@ public void setActiveWindow(boolean active) { hideContextMenus(); TelemetryWrapper.activePlacementEvent(mWindowPlacement.getValue(), mActive); + GleanMetricsService.activePlacementEvent(mWindowPlacement.getValue(), mActive); updateBorder(); mViewModel.setIsActiveWindow(active); diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/Windows.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/Windows.java index d9625282f9..06b6584609 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/Windows.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/Windows.java @@ -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); } } @@ -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; @@ -1084,6 +1088,7 @@ public void onMoveLeftClicked(TopBarWidget aWidget) { WindowWidget window = aWidget.getAttachedWindow(); if (window != null) { TelemetryWrapper.windowsMoveEvent(); + GleanMetricsService.windowsMoveEvent(); moveWindowLeft(window); } @@ -1094,6 +1099,7 @@ public void onMoveRightClicked(TopBarWidget aWidget) { WindowWidget window = aWidget.getAttachedWindow(); if (window != null) { TelemetryWrapper.windowsMoveEvent(); + GleanMetricsService.windowsMoveEvent(); moveWindowRight(window); } diff --git a/docs/metrics.md b/docs/metrics.md index 3f73e8d01b..bf4240b98e 100644 --- a/docs/metrics.md +++ b/docs/metrics.md @@ -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)|
  • type_link
  • type_query
  • voice_query
|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 @@ -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)|
  • context_menu
  • tabs_dialog
  • bookmarks
  • history
  • fxa_login
  • received
  • pre_existing
  • browser
  • downloads
|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)|
  • single
  • double
  • triple
|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)|
  • single
  • double
  • triple
|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 |