zoukankan      html  css  js  c++  java
  • 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>

  • 相关阅读:
    yield* 表达式
    Set 对象和WeakSet对象
    洗牌算法
    filter() 方法创建一个新数组
    UTF8文件带BOM引起的问题
    ios的白屏坑
    css的字体样式怎么写
    npm全局安装失效修复
    nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)解决方案
    linux下nginx的安装及配置
  • 原文地址:https://www.cnblogs.com/ganchuanpu/p/7880227.html
Copyright © 2011-2022 走看看