Git Product home page Git Product logo

nativeleakprof's Introduction

NativeLeakProf

Android Native代码(C/C++)内存泄露分析

  • Hook内存申请本地函数,在替换函数中获取堆栈,在内存中记录申请的内存大小以及堆栈信息
  • 提供API导出动态库泄露(申请了但是未释放)的内存大小
  • 提供API导出动态库泄露堆栈到文件
  • 提供python脚本解析导出的泄露堆栈信息,并生成火焰图,python脚本

使用

添加依赖

implementation 'com.liang.qiu:nativeleakprof:1.0.1'

初始化

在Application的attachBaseContext方法里调用

@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    NativeLeakProf.init(this);
}

获取动态库泄露内存大小列表信息

NativeLeakProf.dumpLeakInfo();

通过dumpLeakInfo方法,可以导出如下的字符串信息

libGLESv2_adreno.so leak: 2.258709MB
libhwui.so leak: 439.270508KB
libc.so leak: 26.500000KB

total leak: 2.713563MB

堆栈导出

调用dumpLeakStack方法导出堆栈,位置在/data/data/xxx.xxx.xxx/files/NativeLeakProf_Stack_xxxxx.txt

NativeLeakProf.dumpLeakStack();

解析堆栈

调用nl_stack_parser.py这个python脚本来解析堆栈数据(自行通过adb pull导出到电脑),举个栗子

/usr/bin/python ~/Documents/AndroidProject/NativeLeakProf/nlp_stack_parser.py ~/android/android-sdk-macosx/ndk-bundle/ ~/Documents/AndroidProject/NativeLeakProf/sample/NativeLeakProf_Stack_c39243bb-4132-4da2-88d9-1e0cfec38627.txt arm64-v8a ~/Documents/AndroidProject/NativeLeakProf/app/build/intermediates/cmake/debug/obj/arm64-v8a/

参数如下

/usr/bin/python ~/Documents/AndroidProject/NativeLeakProf/nlp_stack_parser.py "android ndk路径" "stack文件路径" "arm架构(armeabi/armeabi-v7a/arm64-v8a)" "带符号表so所在目录"

样例(有待完善)

demo

nativeleakprof's People

Contributors

wangwangchen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.