如何在检测我的应用程序后生成用于性能分析的跟踪日志时禁用ANR Watchdog?

问题描述 投票:0回答:1

目前正在尝试获取一个巨大的Android应用程序的配置文件跟踪日志文件,我们已经按照documentation about instrumenting my app to get trace logs检测了MyApplication类。

我们正在尝试深入了解您的应用初始化时会发生什么,Dagger 2会在应用启动时创建对象图。

冷启动通常需要几秒钟,我遇到的问题是,当我添加调试跟踪时,它会大大减慢应用程序的初始化速度,使其与ANR消息一起崩溃。

    com.github.anrwatchdog.ANRError: Application Not Responding
    Caused by: com.github.anrwatchdog.ANRError$$$_Thread: main (state = RUNNABLE)

我想知道是否有办法阻止Android操作系统在长时间阻塞时崩溃,或者至少提高ANR阈值。

欢迎任何帮助或提示。谢谢!

对于进一步的上下文,这大致是我在MyApplication.class中所做的事情:

public void onCreate() {
   super.onCreate();

   Debug.startMethodTracing("MyApp_onCreate()");

   injectSelf();
   AppInit.initApp(this);

   Debug.stopMethodTracing();
}

android performance profiling android-anr-dialog
1个回答
0
投票

事实上,事实证明我们有自己的ANRWatchDogManager,我不知道,我可以扩展限制。

public class ANRWatchDogManager implements ANRWatchDog.ANRListener {

在那个班级的某个地方:

    public void startANRWatchDog() {
        final int timeoutInterval = isDebugBuild() && isEmulator()
                ? ANR_INCREASED_TIMEOUT
                : ANR_DEFAULT_TIMEOUT;
        new ANRWatchDog(timeoutInterval).setANRListener(this).start();
    }
© www.soinside.com 2019 - 2024. All rights reserved.