简体   繁体   English

Firebase 性能自定义跟踪启动/停止问题

[英]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.我想测量屏幕上的加载时间,这涉及多个 API 调用,因此除了 HTTP 跟踪之外还需要自定义跟踪。 The screen has a recyclerview which is paged, so I need to run the trace multiple times.屏幕有一个分页的recyclerview,所以我需要多次运行跟踪。 However this is not working.但是,这是行不通的。 I get errors like Trace 'Home_Loading' has already started, should not start again!我收到类似Trace 'Home_Loading' has already started, should not start again! when I try to run it the second time, even after calling stop().当我第二次尝试运行它时,即使在调用 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导致以下 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.如果您需要执行第二次跟踪,则需要创建一个新的跟踪 object 来启动和停止。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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