How to debug memory leakage in media server in Android

Document created by Bing Song Employee on Sep 12, 2012Last modified by ebiz_ws_prod on Dec 13, 2017
Version 3Show Document
  • View in full screen mode
  • 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.
      • ./ --root-dir=../../ --maps-file=./maps --product=sabresd_6dq diff.txt
  • Notes: should use eng build for the debug.

Original Attachment has been moved to:

2 people found this helpful