Thursday, June 11, 2009

android memory usage with hprof

Android provides some mechanisms to generate hprof data:
  1. Dalvik VM will dump hprof file within /data/misc folder if SIGUSR1 and/or SIGQUIT signal is received. Manually send SIGUSR1 to process: kill -10 pid.
  2. The android provides monkey tool (random testing tool), with --hprof option will generate hprof file within /data/misc folder.
  3. In cupcake release, a new API has been introduced to generate a dump programmatically, the static method dumpHprofData(String fileName) of the Debug class. Example: Debug.dumpHprofData("xxx.hprof").
Some tips:
  1. The folder /data/misc shall have 777 permissions.
  2. The hprof file format is heap-dump-tm-pid.hprof-head and heap-dump-tm-pid.hprof if android 1.1 release is used.
  3. The hprof file format is heap-dump-tm-pid.hprof if android 1.5 release is used.
  4. If two files are generated, you need to join the two files into one: type heap-dump-tm-pid.hprof-head > dump.hprof; type heap-dump-tm-pid.hprof >> dump.hprof.
  5. Convert the hprof to standard hprof format: hprofconv dump.hprof out_dump.hprof
  6. Use JProfiler, Eclipse MAT, or other tools to open out_dump.hprof. I tried JProfiler and got the same problems as indicated in http://osdir.com/ml/android-porting/2009-04/msg00597.html.
Some resources:
  1. Eclipse MAT: http://www.eclipse.org/mat/
  2. MAT standalone: MemoryAnalyzer-Incubation-0.7.0.20081210-win32.win32.x86.zip
  3. Hprofconv: http://bigflake.com/HprofConv.c.txt

No comments:

Post a Comment