简体   繁体   中英

Firebase Performance custom trace starting/stopping problem

I want to measure loading time on a screen, which involves multiple API calls hence wanting a custom trace in addition to the HTTP traces. The screen has a recyclerview which is paged, so I need to run the trace multiple times. However this is not working. I get errors like Trace 'Home_Loading' has already started, should not start again! when I try to run it the second time, even after calling stop(). So for example, this code

        val startupTrace = FirebasePerformance.getInstance().newTrace("Home_Loading")
        startupTrace.start()
        startupTrace.stop()
        startupTrace.start()
        startupTrace.stop()

results in the following logcat

E/FirebasePerformance: Trace 'Home_Loading' has already started, should not start again!
E/FirebasePerformance: Trace 'Home_Loading' has already stopped, should not stop again!
D/FirebasePerformance: Logging trace metric - Home_Loading 0.0220ms

Are the start/stop methods not synchronous? Or is it not possible to run the same trace more than once?

You can't start and stop a trace more than once. A trace can only have one distinct starting point and ending point. If you need to perform a second trace, you will need a create a new trace object to start and stop.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM