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.