Android libc_debug.so has a built-in function to dump all heap allocations with its backtrace, which is very useful to debug memory leaks of native processes. Below are the steps summarized during my investigation of mediaserver process:
In Froyo release, there is no need to replace libc.so with libc_debug.so. Try below steps instead of original step 2:
[Update: 06/22/2013]
Actually Android has a built-in service which could dump mediaserver's memory directly, so you can replace memorydumper related steps with below command. Sorry that I wasn't aware of this tool when I wrote this article :)
#dumpsys "media.player" -m
- apply the patch in ./frameworks/base, which registers a memory dumper service in mediaserver process, then rebuild
- (*)flash new system.img, replace libc.so with libc_debug.so, then reboot
- $ adb remount
- $ adb shell mv /system/lib/libc_debug.so /system/lib/libc.so
- $ adb reboot
- run memorydumper to get the initial heap allocations of mediaserver process
- $ adb shell /system/bin/memorydumper
- play several files, save the process maps during playback, then get the memory dump again
- $ adb pull /proc/
<mediaserver_pid>/maps . - $ adb shell /system/bin/memorydumper
- $ adb pull /proc/
- get the diff file of memory allocations
- $ adb pull /data/memstatus_1136.0 .
- $ adb pull /data/memstatus_1136.1 .
- $ diff memstatus_1136.0 memstatus_1136.1 >diff_0_1
- run the script to resolve symbols from the backtrace addresses in the diff file
- $ ./addr2func.py --root-dir=../ --maps-file=./maps diff_0_1
In Froyo release, there is no need to replace libc.so with libc_debug.so. Try below steps instead of original step 2:
- adb shell setprop libc.debug.malloc 1
- adb shell ps mediaserver
- adb shell kill <mediaserver_pid>
[Update: 06/22/2013]
Actually Android has a built-in service which could dump mediaserver's memory directly, so you can replace memorydumper related steps with below command. Sorry that I wasn't aware of this tool when I wrote this article :)
#dumpsys "media.player" -m