DEBUGGING
Android Logging
- user space logging
adb logcat > logcat.txt
To enable meta data option with logcat , -v option can be used which includes :
To enable meta data option with logcat , -v option can be used which includes :
ex- adb logcat -v threadtime > logcat.txt
brief — Display priority/tag and PID of originating process (the default format).
process — Display PID only.
tag — Display the priority/tag only.
thread — Display process:thread and priority/tag only.
raw — Display the raw log message, with no other metadata fields.
time — Display the date, invocation time, priority/tag, and PID of the originating process.
brief — Display priority/tag and PID of originating process (the default format).
process — Display PID only.
tag — Display the priority/tag only.
thread — Display process:thread and priority/tag only.
raw — Display the raw log message, with no other metadata fields.
time — Display the date, invocation time, priority/tag, and PID of the originating process.
long — Display all metadata fields and separate messages with a blank lines.
alternative logging using -b option
ex - adb logcat -b events > events.txt
radio — View the buffer that contains radio/telephony related messages.
events — View the buffer containing events-related messages.
main — View the main log buffer (default)
radio — View the buffer that contains radio/telephony related messages.
events — View the buffer containing events-related messages.
main — View the main log buffer (default)
- kernel space logging
adb shell dmesg
or ,
adb root
adb shell cat /proc/kmsg > kernel.txt
Process CPU utilization :
adb shell top
with -m option , the number of process can be selected for which % is needed.
ex - adb shell top -m 5
Memory Info
adb shell cat proc/meminfo
Procrank ( courtesy http://elinux.org/Android_Memory_Usage) :
procrank shows you a quick summary of process memory utilization. By default, it shows Vss, Rss, Pss and Uss, and sorts by Vss. However, you can control the sorting order.
procrank source is included in system/extras/procrank, and the binary is located in /system/xbin on an android device.
- Vss = virtual set size
- Rss = resident set size
- Pss = proportional set size
- Uss = unique set size
In general, the two numbers you want to watch are the Pss and Uss (Vss and Rss are generally worthless, because they don't accurately reflect a process's usage of pages shared with other processes.)
- Uss is the set of pages that are unique to a process. This is the amount of memory that would be freed if the application was terminated right now.
- Pss is the amount of memory shared with other processes, accounted in a way that the amount is divided evenly between the processes that share it. This is memory that would not be released if the process was terminated, but is indicative of the amount that this process is "contributing"
to the overall memory load.
You can also use procrank to view the working set size of each process, and to reset the working set size counters.
Here is procrank's usage:
# procrank -h Usage: procrank [ -W ] [ -v | -r | -p | -u | -h ] -v Sort by VSS. -r Sort by RSS. -p Sort by PSS. -u Sort by USS. (Default sort order is PSS.) -R Reverse sort order (default is descending). -w Display statistics for working set only. -W Reset working set of all processes. -h Display this help screen.
And here is some sample output:
# procrank PID Vss Rss Pss Uss cmdline 1217 36848K 35648K 17983K 13956K system_server 1276 32200K 32200K 14048K 10116K android.process.acore 1189 26920K 26920K 9293K 5500K zygote 1321 20328K 20328K 4743K 2344K android.process.media 1356 20360K 20360K 4621K 2148K com.android.email 1303 20184K 20184K 4381K 1724K com.android.settings 1271 19888K 19888K 4297K 1764K com.android.inputmethod.latin 1332 19560K 19560K 3993K 1620K com.android.alarmclock 1187 5068K 5068K 2119K 1476K /system/bin/mediaserver 1384 436K 436K 248K 236K procrank 1 212K 212K 200K 200K /init 753 572K 572K 171K 136K /system/bin/rild 748 340K 340K 163K 152K /system/bin/sh 751 388K 388K 156K 140K /system/bin/vold 1215 148K 148K 136K 136K /sbin/adbd 757 352K 352K 117K 92K /system/bin/dbus-daemon 760 404K 404K 104K 80K /system/bin/keystore 759 312K 312K 102K 88K /system/bin/installd 749 288K 288K 96K 84K /system/bin/servicemanager 752 244K 244K 71K 60K /system/bin/debuggerd
How to debug native process memory allocations
adb root
adb shell setprop libc.debug.malloc 1
adb shell stop
adb shell start
Supported values for libc.debug.malloc (debug level values) are:
- 1 - perform leak detection
- 5 - fill allocated memory to detect overruns
- 10 - fill memory and add sentinels to detect overruns
- 20 - use special instrumented malloc/free routines for the emulator
loglevel
loglevel — Set the default console log level.
The console log level can also be changed by the klogd program, or by writing the specified level to the /proc/sys/kernel/printk file.
The kernel log levels are:
- 0 (KERN_EMERG)
- 1 (KERN_ALERT)
- Actions that must be taken care of immediately.
- 2 (KERN_CRIT)
- Critical conditions.
- 3 (KERN_ERR)
- Non-critical error conditions.
- 4 (KERN_WARNING)
- Warning conditions that should be taken care of.
- 5 (KERN_NOTICE)
- Normal, but significant events.
- 6 (KERN_INFO)
- Informational messages that require no action.
- 7 (KERN_DEBUG)
log_buf_len
log_buf_len — Set the size of the kernel log buffer.
Set the size of the kernel's internal log buffer. n must be a power of 2, if not, it will be rounded up to be a power of two.
GDB Debugging :
copy
<build_path>obj/EXECUTABLES/gdbserver_intermediates/gdbserver. to
the device
host:> adb forward tcp:5039 tcp:5039
host:> adb shell
<device>#
gdbserver :5039 </path/to/executable> [<cmd line params>]
host:> cd
</path/to/unstripped/executable>
host:>
arm-eabi-gdb
(gdb) file <executable>
(gdb) set solib-absolute-prefix <android
product out>/symbols (optional - may not be required)
(gdb) set solib-search-path <android
product out>/system/lib (optional -
may not be required)
(gdb) target remote :5039
(gdb) shared (optional - may not be required)
(gdb) b main
(gdb) cont
or for remote
1) adb forward
tcp:5039 tcp:5039
2) adb shell ps
mediaserver
3) adb shell
gdbserver :5039 --attach <pid>
4) gdbclient
mediaserver :5039
5) (gdb) b
<filename>:<line_num>
6) (gdb) cont
for core dump
analysis :
$arm-linux-androideabi-gdb
symbols/system/bin/app_process
(gdb) set
solib-absolute-prefix ./symbols
(gdb) set
solib-search-path
./symbols/system/lib:./symbols/system/lib/egl:./symbols/system/lib/hw:
(gdb) core
<core_file>
(gdb) backtrace
full or bt
(gdb) info register
(gdb) disassemble
<addr>
No comments:
Post a Comment