Commit 993428cd authored by Michael Comella's avatar Michael Comella Committed by Michael Comella
Browse files

For #17969: add duration probes for App.onCreate and HomeActivity.onCreate.

parent 6e0a6489
......@@ -3962,6 +3962,38 @@ startup.timeline:
- mcomella@mozilla.com
expires: "2021-08-01"
perf.startup:
application_on_create:
type: timing_distribution
time_unit: millisecond
description: |
The duration of `FenixApplication.onCreate` in the main process.
bugs:
- https://github.com/mozilla-mobile/fenix/issues/17969
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/17973#issue-572183889
data_sensitivity:
- technical
notification_emails:
- perf-android-fe@mozilla.com
- mcomella@mozilla.com
expires: "2021-08-11"
home_activity_on_create:
type: timing_distribution
time_unit: millisecond
description: |
The duration of `HomeActivity.onCreate`.
bugs:
- https://github.com/mozilla-mobile/fenix/issues/17969
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/17973#issue-572183889
data_sensitivity:
- technical
notification_emails:
- perf-android-fe@mozilla.com
- mcomella@mozilla.com
expires: "2021-08-11"
perf.awesomebar:
history_suggestions:
send_in_pings:
......
......@@ -39,6 +39,7 @@ import mozilla.components.support.rusthttp.RustHttpConfig
import mozilla.components.support.rustlog.RustLog
import mozilla.components.support.utils.logElapsedTime
import mozilla.components.support.webextensions.WebExtensionSupport
import org.mozilla.fenix.GleanMetrics.PerfStartup
import org.mozilla.fenix.components.Components
import org.mozilla.fenix.components.metrics.MetricServiceType
import org.mozilla.fenix.ext.settings
......@@ -71,6 +72,7 @@ open class FenixApplication : LocaleAwareApplication(), Provider {
private set
override fun onCreate() {
val methodDurationTimerId = PerfStartup.applicationOnCreate.start() // DO NOT MOVE ANYTHING ABOVE HERE.
super.onCreate()
setupInAllProcesses()
......@@ -92,6 +94,9 @@ open class FenixApplication : LocaleAwareApplication(), Provider {
}
setupInMainProcessOnly()
// We use start/stop instead of measure so we don't measure outside the main process.
PerfStartup.applicationOnCreate.stopAndAccumulate(methodDurationTimerId) // DO NOT MOVE ANYTHING BELOW HERE.
}
protected open fun initializeGlean() {
......
......@@ -65,6 +65,7 @@ import mozilla.components.support.utils.SafeIntent
import mozilla.components.support.utils.toSafeIntent
import mozilla.components.support.webextensions.WebExtensionPopupFeature
import org.mozilla.fenix.GleanMetrics.Metrics
import org.mozilla.fenix.GleanMetrics.PerfStartup
import org.mozilla.fenix.addons.AddonDetailsFragmentDirections
import org.mozilla.fenix.addons.AddonPermissionsDetailsFragmentDirections
import org.mozilla.fenix.browser.browsingmode.BrowsingMode
......@@ -163,7 +164,7 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
private lateinit var navigationToolbar: Toolbar
final override fun onCreate(savedInstanceState: Bundle?) {
final override fun onCreate(savedInstanceState: Bundle?): Unit = PerfStartup.homeActivityOnCreate.measure {
// DO NOT MOVE ANYTHING ABOVE THIS addMarker CALL.
components.core.engine.profiler?.addMarker("Activity.onCreate", "HomeActivity")
......
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix
import androidx.test.core.app.ApplicationProvider
import mozilla.components.service.glean.testing.GleanTestRule
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.GleanMetrics.PerfStartup
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
@RunWith(FenixRobolectricTestRunner::class)
class FenixApplicationTest {
@get:Rule val gleanTestRule = GleanTestRule(ApplicationProvider.getApplicationContext())
private lateinit var application: FenixApplication
@Before
fun setUp() {
application = ApplicationProvider.getApplicationContext()
}
@Test
fun `GIVEN onCreate is called THEN the duration is measured`() {
// application.onCreate is called before the test as part of test set up:
// https://robolectric.blogspot.com/2013/04/the-test-lifecycle-in-20.html
assertTrue(PerfStartup.applicationOnCreate.testHasValue())
}
}
......@@ -6,10 +6,12 @@ package org.mozilla.fenix
import android.content.Intent
import android.os.Bundle
import androidx.test.core.app.ApplicationProvider
import io.mockk.every
import io.mockk.mockk
import io.mockk.spyk
import io.mockk.verify
import mozilla.components.service.glean.testing.GleanTestRule
import mozilla.components.support.test.robolectric.testContext
import mozilla.components.support.utils.toSafeIntent
import org.junit.Assert.assertEquals
......@@ -18,8 +20,10 @@ import org.junit.Assert.assertNotEquals
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.GleanMetrics.PerfStartup
import org.mozilla.fenix.HomeActivity.Companion.PRIVATE_BROWSING_MODE
import org.mozilla.fenix.browser.browsingmode.BrowsingMode
import org.mozilla.fenix.browser.browsingmode.BrowsingModeManager
......@@ -28,10 +32,13 @@ import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
import org.mozilla.fenix.utils.Settings
import org.robolectric.Robolectric
@RunWith(FenixRobolectricTestRunner::class)
class HomeActivityTest {
@get:Rule val gleanTestRule = GleanTestRule(ApplicationProvider.getApplicationContext())
private lateinit var activity: HomeActivity
@Before
......@@ -131,4 +138,20 @@ class HomeActivityTest {
assertFalse(activity.isActivityColdStarted(startingIntent, Bundle()))
}
@Test
fun `WHEN onCreate is called THEN the duration is measured`() {
assertFalse(PerfStartup.homeActivityOnCreate.testHasValue()) // sanity check.
// For some reason, the androidx replacement for this method, ActivityScenario, fails so we
// use the old Robolectric version. Perhaps it's because it forces the Activity to the
// RESUMED state (unlike Robolectric where we can get to CREATED) so not enough code is
// mocked for that to work.
//
// There are various exceptions thrown on background threads when this test runs but it
// doesn't seem to impact correctness so we ignore them.
Robolectric.buildActivity(HomeActivity::class.java)
.create()
assertTrue(PerfStartup.homeActivityOnCreate.testHasValue())
}
}
......@@ -315,6 +315,8 @@ The following metrics are added to the ping:
| perf.awesomebar.session_suggestions |[timing_distribution](https://mozilla.github.io/glean/book/user/metrics/timing_distribution.html) |Duration of a session awesomebar suggestion query. |[1](https://github.com/mozilla-mobile/fenix/pull/10276#pullrequestreview-411101979)||2020-11-15 |1, 2 |
| perf.awesomebar.shortcuts_suggestions |[timing_distribution](https://mozilla.github.io/glean/book/user/metrics/timing_distribution.html) |Duration of a shortcuts awesomebar suggestion query. |[1](https://github.com/mozilla-mobile/fenix/pull/10276#pullrequestreview-411101979)||2020-11-15 |1, 2 |
| perf.awesomebar.synced_tabs_suggestions |[timing_distribution](https://mozilla.github.io/glean/book/user/metrics/timing_distribution.html) |Duration of a synced tabs awesomebar suggestion query. |[1](https://github.com/mozilla-mobile/fenix/pull/10276#pullrequestreview-411101979)||2020-11-15 |1, 2 |
| perf.startup.application_on_create |[timing_distribution](https://mozilla.github.io/glean/book/user/metrics/timing_distribution.html) |The duration of `FenixApplication.onCreate` in the main process. |[1](todo)||2021-08-11 |1 |
| perf.startup.home_activity_on_create |[timing_distribution](https://mozilla.github.io/glean/book/user/metrics/timing_distribution.html) |The duration of `HomeActivity.onCreate`. |[1](todo)||2021-08-11 |1 |
| preferences.accessibility_services |[string_list](https://mozilla.github.io/glean/book/user/metrics/string_list.html) |Whether or not the user has touch exploration or switch services enabled. These are built into the Android OS, not Fenix prefs. default: "" |[1](https://github.com/mozilla-mobile/fenix/pull/11211), [2](https://github.com/mozilla-mobile/fenix/pull/15713#issuecomment-703972068)||2021-08-01 |2 |
| preferences.open_links_in_a_private_tab |[string_list](https://mozilla.github.io/glean/book/user/metrics/string_list.html) |Whether or not the user has enabled open links in a private tab. default: false |[1](https://github.com/mozilla-mobile/fenix/pull/11211), [2](https://github.com/mozilla-mobile/fenix/pull/15713#issuecomment-703972068)||2021-08-01 |2 |
| preferences.open_links_in_app |[string_list](https://mozilla.github.io/glean/book/user/metrics/string_list.html) |Whether or not the user has the open links in apps feature enabled. default: false |[1](https://github.com/mozilla-mobile/fenix/pull/11446), [2](https://github.com/mozilla-mobile/fenix/pull/15713#issuecomment-703972068)||2021-08-01 |2 |
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment