Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase : Jetpack Compose How measure Screen Rendering time like Activity and Fragment

I am trying to do Screen Rendering in Firebase. I can see only Main Activity in Firebase Screen Rendering but not able to see Jetpack Compose Screens. Is there any way to show the JetPack Compose screens? It should reflect in Firebase Screen Rendering Section.

In Jetpack compose is there any way to show the Screen Rendering in Firebase Performance Tab. Only its supporting Activity and Fragment how I can do for the Jetpack Compose.

here I added what the Documents says :

How are screen rendering traces generated?

Each screen rendering trace is identified by the name of the view element in your application. The Performance Monitoring client creates screen rendering traces for every Activity or Fragment used by your application.

Each screen rendering trace performs the following actions:

Starts for every activity and fragment class when the object becomes visible on the screen. OnActivityStarted() for activities and OnFragmentResume() for fragments.

Stops for every activity and fragment class when the object is not visible on the screen. OnActivityStopped() for activities and OnFragmentPaused() for fragments.

how it will done in Jetpack Compose.

like image 960
Sathish Avatar asked Oct 21 '25 01:10

Sathish


1 Answers

You can launch the screen tracing as a DisposableEffect

@Composable
fun LaunchTracing(route: String) {
    val activity = LocalContext.current as Activity
    DisposableEffect(key1 = route) {
        val trace = Trace.create(Constants.SCREEN_TRACE_PREFIX + route).apply { start() }
        val recorder = FrameMetricsRecorder(activity).apply { start() }
        onDispose {
            val metrics = recorder.stop()
            if (metrics.isAvailable)
                ScreenTraceUtil.addFrameCounters(trace, metrics.get())
            else
                Log.e("TRACING", "Unable to record trace for '$route'")
            trace.stop()
        }
    }
}
like image 195
Sergey Bubenshchikov Avatar answered Oct 22 '25 16:10

Sergey Bubenshchikov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!