From 5bd0369aed0069eae678ca5273b63d819afd1f82 Mon Sep 17 00:00:00 2001 From: Michael Comella Date: Tue, 10 Mar 2020 13:36:19 -0700 Subject: [PATCH] No issue: remove unused HotStartPerformanceMonitor. This monitor for hot start was intended to be used by FNPRMS to measure hot start. However, hot start was deprioritized so it's now essentially unused. --- .../java/org/mozilla/fenix/HomeActivity.kt | 13 ------ .../fenix/perf/HotStartPerformanceMonitor.kt | 46 ------------------- .../perf/HotStartPerformanceMonitorTest.kt | 43 ----------------- 3 files changed, 102 deletions(-) delete mode 100644 app/src/main/java/org/mozilla/fenix/perf/HotStartPerformanceMonitor.kt delete mode 100644 app/src/test/java/org/mozilla/fenix/perf/HotStartPerformanceMonitorTest.kt diff --git a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt index 5d92c00bb..6989079ec 100644 --- a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt +++ b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt @@ -59,7 +59,6 @@ import org.mozilla.fenix.home.intent.SpeechProcessingIntentProcessor import org.mozilla.fenix.home.intent.StartSearchIntentProcessor import org.mozilla.fenix.library.bookmarks.BookmarkFragmentDirections import org.mozilla.fenix.library.history.HistoryFragmentDirections -import org.mozilla.fenix.perf.HotStartPerformanceMonitor import org.mozilla.fenix.perf.Performance import org.mozilla.fenix.perf.StartupTimeline import org.mozilla.fenix.search.SearchFragmentDirections @@ -86,8 +85,6 @@ open class HomeActivity : LocaleAwareAppCompatActivity() { private var sessionObserver: SessionManager.Observer? = null - private val hotStartMonitor = HotStartPerformanceMonitor() - private var isToolbarInflated = false private val webExtensionPopupFeature by lazy { @@ -161,16 +158,6 @@ open class HomeActivity : LocaleAwareAppCompatActivity() { } } - final override fun onRestart() { - hotStartMonitor.onRestartFirstMethodCall() - super.onRestart() - } - - final override fun onPostResume() { - super.onPostResume() - hotStartMonitor.onPostResumeFinalMethodCall() - } - final override fun onPause() { super.onPause() diff --git a/app/src/main/java/org/mozilla/fenix/perf/HotStartPerformanceMonitor.kt b/app/src/main/java/org/mozilla/fenix/perf/HotStartPerformanceMonitor.kt deleted file mode 100644 index df8b66746..000000000 --- a/app/src/main/java/org/mozilla/fenix/perf/HotStartPerformanceMonitor.kt +++ /dev/null @@ -1,46 +0,0 @@ -/* 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.perf - -import android.os.SystemClock -import android.util.Log - -/** - * Monitors and reports elapsed time to complete hot startup of an Activity. Callers are expected - * to call the appropriate lifecycle methods at the appropriate times. - * - * A "hot startup" is when the application moves from the background to the foreground and both the - * Application/process and the Activity under measurement are already created. - * - * Unfortunately, this monitor does not capture the entire duration of hot start because the - * framework calls several Android framework methods in the application's process before we are able - * to add monitoring code (i.e. the first time our application code is called in onRestart). An - * alternative implementation could measure performance from outside the application. - * - * The logs from this class are not visible to users by default. To see logs from this class, the - * user must enable VERBOSE logging for the appropriate tag: - * adb shell setprop log.tag.FenixPerf VERBOSE - */ -class HotStartPerformanceMonitor( - // We use VERBOSE logging so that the logs are not visible to users by default. We use the - // Android Log methods to minimize overhead introduced in a-c logging. - private val log: (String) -> Unit = { Log.v(Performance.TAG, it) }, - private val getElapsedRealtime: () -> Long = { SystemClock.elapsedRealtime() } -) { - - private var onRestartMillis: Long = -1 - - fun onRestartFirstMethodCall() { - onRestartMillis = getElapsedRealtime() - } - - fun onPostResumeFinalMethodCall() { - // If onRestart was never called, this is not a hot start: ignore it. - if (onRestartMillis >= 0) { - val elapsedMillis = getElapsedRealtime() - onRestartMillis - log("hot start: $elapsedMillis") - } - } -} diff --git a/app/src/test/java/org/mozilla/fenix/perf/HotStartPerformanceMonitorTest.kt b/app/src/test/java/org/mozilla/fenix/perf/HotStartPerformanceMonitorTest.kt deleted file mode 100644 index bba5e462d..000000000 --- a/app/src/test/java/org/mozilla/fenix/perf/HotStartPerformanceMonitorTest.kt +++ /dev/null @@ -1,43 +0,0 @@ -/* 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.perf - -import io.mockk.Called -import io.mockk.MockKAnnotations -import io.mockk.impl.annotations.MockK -import io.mockk.verify -import org.junit.Before -import org.junit.Test - -class HotStartPerformanceMonitorTest { - - private lateinit var monitor: HotStartPerformanceMonitor - - @MockK(relaxed = true) private lateinit var log: (String) -> Unit - private var elapsedRealtime = 0L - - @Before - fun setUp() { - MockKAnnotations.init(this) - monitor = HotStartPerformanceMonitor(log, getElapsedRealtime = { elapsedRealtime }) - } - - @Test - fun `WHEN onRestart is not called but onPostResume is called THEN we do not log`() { - monitor.onPostResumeFinalMethodCall() - verify { log.invoke(any()) wasNot Called } - } - - @Test - fun `WHEN onRestart then onPostResume is called THEN we log the elapsed time`() { - elapsedRealtime = 10 - monitor.onRestartFirstMethodCall() - - elapsedRealtime = 100 - monitor.onPostResumeFinalMethodCall() - - verify { log.invoke("hot start: 90") } // fragile but it's not worth the time to make robust. - } -}