[fenix] For perf-frontend-issueshttps://github.com/mozilla-mobile/fenix/pull/33: Add HotStartPerformanceMonitor.
As mentioned in the class comment, we could use an alternative implementation to measure perf from outside the application however it's more complicated to set up and less consistent with our cold startup methodology so we'll start with this.pull/600/head
parent
7f5cac63f1
commit
bde17a6a4e
@ -0,0 +1,40 @@
|
|||||||
|
/* 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.
|
||||||
|
*
|
||||||
|
* 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 {
|
||||||
|
|
||||||
|
private var onRestartMillis: Long = -1
|
||||||
|
|
||||||
|
fun onRestartFirstMethodCall() {
|
||||||
|
onRestartMillis = SystemClock.elapsedRealtime()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onPostResumeFinalMethodCall() {
|
||||||
|
// If onRestart was never called, this is not a hot start: ignore it.
|
||||||
|
if (onRestartMillis >= 0) {
|
||||||
|
val elapsedMillis = SystemClock.elapsedRealtime() - onRestartMillis
|
||||||
|
Log.v(Performance.TAG, "hot start: $elapsedMillis") // android log to minimize overhead.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
/* 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
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A collection of objects related to app performance.
|
||||||
|
*/
|
||||||
|
object Performance {
|
||||||
|
const val TAG = "FenixPerf"
|
||||||
|
}
|
Loading…
Reference in New Issue