Script to view native allocations prettily.
Usage:
1. Collect a native heap dump from the device. For example:
$ adb shell stop
$ adb shell setprop libc.debug.malloc.program app_process
$ adb shell setprop libc.debug.malloc.options backtrace=64
$ adb shell start
(launch and use app)
$ adb shell am dumpheap -n <pid> /data/local/tmp/native_heap.txt
$ adb pull /data/local/tmp/native_heap.txt
2. Run the viewer:
$ python native_heapdump_viewer.py [options] native_heap.txt
[--verbose]: verbose output
[--html]: html output
[--symbols SYMBOL_DIR]: SYMBOL_DIR is the directory containing the
.so files with symbols. Defaults to $ANDROID_PRODUCT_OUT/symbols
This outputs a file with lines of the form:
5831776 29.09% 100.00% 10532 71b07bc0b0 /system/lib64/libandroid_runtime.so Typeface_createFromArray frameworks/base/core/jni/android/graphics/Typeface.cpp:68
5831776 is the total number of bytes allocated at this stack frame, which
is 29.09% of the total number of bytes allocated and 100.00% of the parent
frame's bytes allocated. 10532 is the total number of allocations at this
stack frame. 71b07bc0b0 is the address of the stack frame.
For generating interactive HTML output, use:
python native_heapdump_viewer.py --html [options] native_heap.txt > allocations.html
Then open allocations.html in a browser. Clicking on nodes will
expand the tree.
Test: Try script on an app following usage instructions.
Bug: 36457259
Change-Id: I18dfe9a00fc1d3e82673dbfb4b5be3dc10480cec
1 file changed