How I debugged memory leak issue for mediaserver
Nov 24, 2015 · 1 minute read · CommentsAndroidNDKAOSP
Recently I had to fix big memory leak issue in “medieaserver”. From the internet I found very nice tool called addr2func
for fixing the issue.
The tool is written by freepine and I modified for supporting latest version of AOSP bases codes(5.0) and uploaded into Github : addr2func
Pre-condition - eng or userdebug build of device and android full source code
- Download addr2func
Give excute permission.
$chmod +x addr2func.py
Enable memory allocation debug feature for
mediaserver
.$adb shell setprop libc.debug.malloc 1 $adb shell ps mediaserver $adb shell kill <mediaserver_pid>
Dump memory status of
mediaserver
intodump1
file.$adb shell ps mediaserver $adb pull /proc/<mediaserver_pid>/maps $adb shell dumpsys media.player -m > dump1
Do the memory leak test on the device.
Dump memory status of
mediaserver
intodump2
file.$adb pull /proc/<mediaserver_pid>/maps $adb shell dumpsys media.player -m > dump2
make
diff
betweendump1
anddump2
.$diff dump1 dump2 > diff
Save memory allocation trace into
mem_trace
file.$./addr2func.py --root-dir=<AOSP_dir> --maps-file=maps --product=<product_name_of_your_build> diff > mem_trace
The memory allocation trace is saved in mem_trace
file. It will show you where exactly the memory is allocated. dup
is duplication count.