• LeakCanary上传 leak trace 到服务器


    你可以改变处理完成的默认行为,将 leak trace 和 heap dump 上传到你的服务器以便统计分析。

    创建一个 LeakUploadService, 最简单的就是继承 DisplayLeakService :

    public class LeakUploadService extends DisplayLeakService {
      @Override
      protected void afterDefaultHandling(HeapDump heapDump, AnalysisResult result, String leakInfo) {
        if (!result.leakFound || result.excludedLeak) {
          return;
        }
        myServer.uploadLeakBlocking(heapDump.heapDumpFile, leakInfo);
      }
    }

    请确认 release 版本 使用 RefWatcher.DISABLED

    public class ExampleApplication extends Application {
    
      public static RefWatcher getRefWatcher(Context context) {
        ExampleApplication application = (ExampleApplication) context.getApplicationContext();
        return application.refWatcher;
      }
    
      private RefWatcher refWatcher;
    
      @Override public void onCreate() {
        super.onCreate();
        refWatcher = installLeakCanary();
      }
    
      protected RefWatcher installLeakCanary() {
        return RefWatcher.DISABLED;
      }
    }

    自定义 RefWatcher

    public class DebugExampleApplication extends ExampleApplication {
      protected RefWatcher installLeakCanary() {
        return LeakCanary.install(app, LeakUploadService.class);
      }
    }

    别忘了注册 service:

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        >
      <application android:name="com.example.DebugExampleApplication">
        <service android:name="com.example.LeakUploadService" />
      </application>
    </manifest>

  • 相关阅读:
    Ubuntu 下配置ftp服务端
    mysql的sql文件的备份与还原
    Virtualbox后台管理之VBoxManage
    主从库延迟对项目质量的影响
    jenkins / ant / jmeter 持续集成接口自动化
    infer 检验IOS项目
    pmd静态代码分析
    利用线上数据验证系统 Gor
    python flask (一)
    python SQLAlchemy
  • 原文地址:https://www.cnblogs.com/ganchuanpu/p/7880227.html
Copyright © 2020-2023  润新知