Thursday, September 24, 2009

E-book: The Busy Coder's Guide to Android Development

, NOT BAD. Google it to find details.

Thursday, August 6, 2009

Automatic Memory Leak Tracking on Android

Android provides a mechanism to track memory leakage.
In folder bionic/libc/bionic/malloc_leak.c is compiled into /system/lib/, it is a memory leakage tracking version of To enable the memory leakage tracking, replace the /system/lib/ with the /system/lib/
> adb shell mv /system/lib/ /system/lib/
> adb shell mv /system/lib/ /system/lib/
Before doing that, be sure to remount the system partition to 'rw'.
Use 'mv' command may have problem without, in that case use 'cp' command instead.
With the memory leak tracking, you shall see something like "MALLOC_DEBUG = 1 (leak checker)" in your logcat output.

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
Some resources:
  1. Eclipse MAT:
  2. MAT standalone:
  3. Hprofconv:

Monday, June 8, 2009

Android Java Space OOM

The default Android java space heap maximum limitation is 16M. If you are running multimedia applications on android, such as jpg file decoding, video decoding, you may run OOM (Out Of Memory). If memory tuning can not help you on the OOM, you can go to the file: frameworks/base/core/jni/AndroidRuntime.cpp, line 607, change opt.optionString = "-Xmx16m" to opt.optionString = "-Xmx20m" for 20M heap size or even bigger.
The limitation is the upward limitation, it will not actually allocate 20M memory every time in every java application.
Take this solution as the last try, focus on your coding quality first.

Tools to monitor your android system memory and performance

Tools to monitor your android/linux system memory and performance:
  • ps -x
  • top
  • cat /proc/meminfo
  • dumpsys meminfo proc-id
  • procrank
  • DDMS (Android SDK tool)
  • time command-line
  • vmstat

Android java space profiling tool - traceview

Android provides a good java space profiling tool: traceview. Traceview can be found in the same folder as adb in Android SDK package. Usage is quite simple and straightforward:
  1. import android.os.Debug;
  2. Debug.startMethodTracing("tag-name");
  3. Debug.stopMethodTracing();
  4. Run the Java application
  5. Fetch out the profiling output file on SD card (SD card is needed) root folder: tag-name.trace
  6. traceview tag-name.trace to open the traceview window
Insert items 1, 2, 3 into your java source code where you want to do profiling.
For more information about traceview window, refer to

Tuesday, May 19, 2009

fdatasync not found in bionic libc

fdatasync(int) declare is found in bionic/libc/include/unistd.h, but it is not actually implemented in libc. I can NOT find the fdatasync symbol in /system/lib/

Thursday, February 26, 2009

UI/Application Exerciser Monkey

The Monkey is a program that runs on your emulator or device and generates pseudo-random streams of user events such as clicks, touches, or gestures, as well as a number of system-level events. You can use the Monkey to stress-test applications that you are developing, in a random yet repeatable manner.
Basic usage of monkey:
usage: monkey [-p ALLOWED_PACKAGE [-p ALLOWED_PACKAGE] ...]
[--ignore-crashes] [--ignore-timeouts]
[--ignore-security-exceptions] [--monitor-native-crashes]
[--kill-process-after-error] [--hprof]
[--pct-touch PERCENT] [--pct-motion PERCENT]
[--pct-trackball PERCENT] [--pct-syskeys PERCENT]
[--pct-nav PERCENT] [--pct-majornav PERCENT]
[--pct-appswitch PERCENT] [--pct-anyevent PERCENT]
[--wait-dbg] [--dbg-no-events]
[-s SEED] [-v [-v] ...] [--throttle MILLISEC]
Example: adb shell monkey 1000
#send 1000 events to all applications