Skip to content

Add a fast dumper with HeapDumper API. #2387

@alhah

Description

@alhah

Fast dump

@pyricau As we discussed in #2047 & #2121, I add a fast dumper with HeapDumper API #2237 in KOOM v2.2.0.

How to use it

  1. Add a dependency in your build.gradle
dependencies {
    implementation "com.kuaishou.koom:koom-fast-dump:2.2.0"
}
  1. Initialize koom fast dump and set HeapDumper, then enjoy it.
    DefaultInitTask.init(applicationContext as Application)
    LeakCanary.config = LeakCanary.config.copy(
      heapDumper = HeapDumper {
        ForkJvmHeapDumper.getInstance().dump(it.absolutePath)
      })

Additional information

  1. Compatibility
  • Support Android L and above(API level >= 21)
  • Support armeabi-v7a arm64-v8a x86 x86-64
  1. Min Sdk
    The minSdkVersion of fast dump is 18. If the minSdkVersion of your app is lower than that, it needs to be compatible with overrideLibrary in the manifest.
  <uses-sdk tools:overrideLibrary="com.kwai.koom.fastdump, com.kwai.android.base, com.kwai.koom.base" />
  1. STL Support
    Fast dump support both shared and static libc++, if you are worried about STL conflicts, please use the static version, or you will prefer to the shared version for package size.
dependencies {
  // In shared mode, multiple modules share the same libc++_shared.so (STL), and the package 
  // size is small, but when multiple modules depend on different STL versions, the final 
  // compilation will conflict.
  implementation "com.kuaishou.koom:koom-fast-dump:2.2.0"
  // Or in static mode, each module has its own STL, the package size is large, and there are no 
  // compilation and runtime problems.
  implementation "com.kuaishou.koom:koom-fast-dump-static:2.2.0"
}
  1. Key logcat
    Please check logcat prefix with OOMMonitor to see if fast dump works.
16743 16766 I OOMMonitor_ForkJvmHeapDumper: dump xxx.hprof.
16743 16766 I OOMMonitor_ForkJvmHeapDumper: before suspend and fork.
// The pid changes from 16743 to 16807, and the child process starts to dump
16807 16807 I mple.leakcanar: hprof: heap dump "xxx.hprof" starting...
// The child process dump finished, it takes 6.4s
16807 16807 I mple.leakcanar: hprof: heap dump completed (24MB) in 6.411s objects 330914 objects with stack traces 0
16807 16807 I JNIBridge: process 16807 will exit!
// The main process is notified by the completion of the child process dump
16743 16766 I OOMMonitor_ForkJvmHeapDumper: dump true, notify from pid 16807

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions