development:android:how_to_debug_memory_leakage_in_media_server_in_android

CC: https://community.freescale.com/docs/DOC-93326

Check memory leakage in media server.

Set libc debug level. So libc will record back trace for all memory allocate.

  • setprop libc.debug.malloc 1

Kill mediaserver to let the libc debug take effect. Android will restart mediaserver.

  • busybox killall -HUP mediaserver

you will see below log if you setting right.

I/libc    ( 3074): /system/bin/mediaserver using MALLOC_DEBUG = 1 (leak checker)

Dump all used memory of mediaserver.

dumpsys media.player -m

Allocation count 297

Total memory 1483423

size   262144, dup    1, 0x401f4c18, 0x400b6152, 0x401a6568, 0x4061a95c, 0x40146cfa, 0x4019639c, 
0x40146ec2, 0x4014a1ec, 0x4014a3ca, 0x00008a98, 0x400b67aa

size   178192, dup    1, 0x401f4c18, 0x400b6152, 0x4280adae, 0x427ffcee, 0x4280ae6c, 0x427ec75a, 
0x427f7e22, 0x42807648, 0x428082ea, 0x415144f0, 0x4151334a, 0x413381d0, 0x401dcbc, 0x401d438c, 0x4014d996, 0x405c3c46, 0x405c7516, 0x405c6ad4, 0x412c02ca, 0x412c0584, 0x4108c64c, 0x4107d622, 
0x4107fbf2, 0x4107c19a, 0x400b2eac, 0x400b2a00

Diff two times of memory dump to check if there is any memory leakage. You can playback one video file between the dump.

diff 1.txt 2.txt > diff.txt

Get maps file of mediaserver.

adb pull proc/<pid of mediaserver>/maps .

Use attached script to map back trace to function symbols and file line.

./addr2func.py --root-dir=../../ --maps-file=./maps --product=sabresd_6dq diff.txt

Notes: should use eng build for the debug.

Another Links : http://freepine.blogspot.kr/2010/02/analyze-memory-leak-of-android-native.html

  • development/android/how_to_debug_memory_leakage_in_media_server_in_android.txt
  • 마지막으로 수정됨: 2020/09/26 02:12
  • (바깥 편집)