Skip to content

Commit

Permalink
Switch to the typed API for Glean events
Browse files Browse the repository at this point in the history
Required for Glean v52.0.0

Ref mozilla-mobile#19967
  • Loading branch information
badboy committed Jan 19, 2023
1 parent 3e7d0bf commit d2b8738
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
7 changes: 7 additions & 0 deletions app/metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7555,26 +7555,33 @@ engine_tab:
description: |
Number of active tabs (with an engine session assigned) when the app
went to the background.
type: string
background_crashed_tabs:
description: |
Number of tabs marked as crashed when the app went to the background.
type: string
background_total_tabs:
description: |
Number of total tabs when the app went to the background.
type: string
foreground_active_tabs:
description: |
Number of active tabs (with an engine session assigned) when the
app came back to the foreground.
type: string
foreground_crashed_tabs:
description: |
Number of tabs marked as crashed when the app came back to the
foreground.
type: string
foreground_total_tabs:
description: |
Number of total tabs when the app came back to the foreground.
type: string
time_in_background:
description: |
Time (in milliseconds) the app was in the background.
type: string
metadata:
tags:
- Performance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import androidx.lifecycle.LifecycleOwner
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.support.base.android.Clock
import org.mozilla.fenix.GleanMetrics.EngineTab as EngineMetrics
import org.mozilla.fenix.GleanMetrics.EngineTab.foregroundMetricsKeys as MetricsKeys
import org.mozilla.fenix.GleanMetrics.EngineTab.ForegroundMetricsExtra as MetricsExtra

/**
* [LifecycleObserver] to used on the process lifecycle to measure the amount of tabs getting killed
Expand All @@ -33,17 +33,15 @@ class TelemetryLifecycleObserver(
val lastState = pausedState ?: return
val currentState = createTabState()

@Suppress("DEPRECATION")
// FIXME(#19967): Migrate to non-deprecated API.
EngineMetrics.foregroundMetrics.record(
mapOf(
MetricsKeys.backgroundActiveTabs to lastState.activeEngineTabs.toString(),
MetricsKeys.backgroundCrashedTabs to lastState.crashedTabs.toString(),
MetricsKeys.backgroundTotalTabs to lastState.totalTabs.toString(),
MetricsKeys.foregroundActiveTabs to currentState.activeEngineTabs.toString(),
MetricsKeys.foregroundCrashedTabs to currentState.crashedTabs.toString(),
MetricsKeys.foregroundTotalTabs to currentState.totalTabs.toString(),
MetricsKeys.timeInBackground to (currentState.timestamp - lastState.timestamp).toString(),
MetricsExtra(
backgroundActiveTabs = lastState.activeEngineTabs.toString(),
backgroundCrashedTabs = lastState.crashedTabs.toString(),
backgroundTotalTabs = lastState.totalTabs.toString(),
foregroundActiveTabs = currentState.activeEngineTabs.toString(),
foregroundCrashedTabs = currentState.crashedTabs.toString(),
foregroundTotalTabs = currentState.totalTabs.toString(),
timeInBackground = (currentState.timestamp - lastState.timestamp).toString(),
),
)

Expand Down

0 comments on commit d2b8738

Please sign in to comment.