-
Notifications
You must be signed in to change notification settings - Fork 421
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: xueqiushi <[email protected]>
- Loading branch information
Showing
4 changed files
with
182 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
中文版本请参看[这里](README.zh-CN.md) | ||
|
||
# Fast Dump Introduction | ||
|
||
Java memory memory image dump module: | ||
|
||
- Image dump adopts the strategy of `current process virtual machine supend -> fork child | ||
process -> current process virtual machine resume ->c hild process dump memory image`, and the | ||
time-consuming (median about 20s) of collecting images is transferred to child process, the | ||
freezing time of the current process is reduced to less than 20ms (does not affect user operations). | ||
|
||
- Adapt to LeakCanary custom dumper, which can replace LeakCanary's image acquisition module with fast dump. | ||
|
||
# Fast Dump Compatibility | ||
|
||
- Android L and above(API level >= 21) | ||
|
||
- Support armeabi-v7a arm64-v8a x86 x86-64 | ||
|
||
|
||
# Fast Dump Setup | ||
|
||
## Dependencies | ||
|
||
- Add mavenCentral to the repositories of the project root directory build.gradle | ||
```groovy | ||
repositories { | ||
mavenCentral() | ||
} | ||
``` | ||
|
||
- Add dependency in project app/build.gradle | ||
```groovy | ||
dependencies { | ||
implementation "com.kuaishou.koom:koom-fast-dump:${latest_version}" | ||
} | ||
``` | ||
|
||
## Steps | ||
|
||
- Take the integration of fast dump into LeakCanary as an example: | ||
|
||
```kotlin | ||
// Configuration initialization | ||
DefaultInitTask.init(applicationContext as Application) | ||
LeakCanary.config = LeakCanary.config.copy( | ||
heapDumper = HeapDumper { | ||
// The core code is this line. Note that this method will wait for the child process to | ||
// return the dump result, do not call it on the UI thread! | ||
ForkJvmHeapDumper.getInstance().dump(it.absolutePath) | ||
}) | ||
``` | ||
|
||
|
||
- Key Log | ||
|
||
> 16743 16766 I OOMMonitor_ForkJvmHeapDumper: dump xxx.hprof. <br> | ||
> 16743 16766 I OOMMonitor_ForkJvmHeapDumper: before suspend and fork. <br> | ||
> // The pid changes from 16743 to 16807, and the child process starts to dump <br> | ||
> 16807 16807 I mple.leakcanar: hprof: heap dump "xxx.hprof" starting... <br> | ||
> // The child process dump finished, it takes 6.4s <br> | ||
> 16807 16807 I mple.leakcanar: hprof: heap dump completed (24MB) in 6.411s objects 330914 objects with stack traces 0 <br> | ||
> 16807 16807 I JNIBridge: process 16807 will exit! <br> | ||
> // The main process is notified by the completion of the child process dump <br> | ||
> 16743 16766 I OOMMonitor_ForkJvmHeapDumper: dump true, notify from pid 16807 <br> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Fast Dump 介绍 | ||
|
||
Java 内存镜像采集模块: | ||
|
||
- 镜像采集采用`当前进程虚拟机supend -> fork子进程 -> 当前进程虚拟机resume -> 子进程dump内存镜像`的策略,将采集镜像的耗时(中位数约20s)转移到 | ||
子进程,当前进程冻结的时间缩减至20ms以内(不影响用户操作)。 | ||
|
||
- 适配LeakCanary custom dumper,可将LeakCanary的镜像采集模块替换为fast dump。 | ||
|
||
# Fast Dump 适用范围 | ||
|
||
- Android L 及以上(API level >= 21) | ||
|
||
- 支持 armeabi-v7a arm64-v8a x86 x86-64 | ||
|
||
# Fast Dump 接入 | ||
|
||
## 依赖配置 | ||
- 项目根目录 build.gradle 中增加 mavenCentral | ||
```groovy | ||
repositories { | ||
mavenCentral() | ||
} | ||
``` | ||
- 项目 app/build.gradle 中增加依赖 | ||
```groovy | ||
dependencies { | ||
implementation "com.kuaishou.koom:koom-fast-dump:${latest_version}" | ||
} | ||
``` | ||
|
||
## 使用 | ||
|
||
- 以接入LeakCanary为例: | ||
|
||
```kotlin | ||
// 初始化配置 | ||
DefaultInitTask.init(applicationContext as Application) | ||
LeakCanary.config = LeakCanary.config.copy( | ||
heapDumper = HeapDumper { | ||
// 核心代码就这一行,注意此方法会等待子进程返回采集结果,不要在UI线程调用! | ||
ForkJvmHeapDumper.getInstance().dump(it.absolutePath) | ||
}) | ||
``` | ||
## 关键日志 | ||
|
||
> 16743 16766 I OOMMonitor_ForkJvmHeapDumper: dump xxx.hprof. <br> | ||
> 16743 16766 I OOMMonitor_ForkJvmHeapDumper: before suspend and fork. <br> | ||
> // pid从16743变为16807,子进程开始采集 <br> | ||
> 16807 16807 I mple.leakcanar: hprof: heap dump "xxx.hprof" starting... <br> | ||
> // 子进程采集完毕,耗时6.4s <br> | ||
> 16807 16807 I mple.leakcanar: hprof: heap dump completed (24MB) in 6.411s objects 330914 objects with stack traces 0 <br> | ||
> 16807 16807 I JNIBridge: process 16807 will exit! <br> | ||
> // 主进程监听到子进程采集完毕 <br> | ||
> 16743 16766 I OOMMonitor_ForkJvmHeapDumper: dump true, notify from pid 16807 <br> |