The C library (bionic) in the system supports the ability to utilize a different, debug, version of the malloc code at runtime in the system.
Dalvik, like virtual machines for many other languages, does garbage collection on the heap. There appears to be a separate thread (called the HeapWorker) in each VM process that performs the garbage collection actions. (See toolbox ps -t) [need more notes on the garbage collection]
什么是计算机?计算机科学很高深吗?也许你会联想到集成电路,联想到汇编语言,操作系统之类的,然而真正的计算机本质上是很简单的,你自己都能自己动手做出来,
中变传奇私服,所谓的集成电路只不过是实现计算机的一种方式而已,它能使计算机变得更快,更小,它纯属于另一个范畴,至于编程语言,
传奇私服下载,那便是另另一个范畴了,
3000ok,如果你理解了计算机的本质,再理解这些概念就不会觉得难了。 本文我就带着想理解本质的同道中人自己动手做一台可以“编程”的计算机。首先计算机不一定非要是电子的,它完全可以是机械的,本文中我做的这台机器就不是电子的,因为如果想搞...
See an excellent article by Dianne Hackborn at:
Supported values for libc.debug.malloc (debug level values) are:
procrank source is included in system/extras/procrank,jjj.com, and the binary is located in /system/xbin on an android device.
If the system property libc.debug.malloc has a value other than 0, then when a process is instantiated,30ok登陆器, the C library uses functions for allocating and freeing memory, for that process.
Dalvik Heap
Debugging Android application memory usage
See
procrank
(Note that there are other ways that the debug shared library malloc code ends up being used as well. That is, if you are running in the emulator, and the value of the system property ro.kernel.memcheck is not '0', then you get a debug level of 20. Note that debug level 20 can only be used in the emulator.)
(Information was obtained by looking at <android-source-root>/bionic/libc/bionic/malloc_debug_common.c)
System Memory
The Dalvik heap is preloaded with classes and data by zygote (loading over 1900 classes as of Android version 2.2). When zygote forks to start an android application, the new application gets a copy-on-write mapping of this heap. As Dan Borstein says below, this helps with memory reduction as well as application startup time.
I'm not sure whether these shared libraries are shipped in production devices.
smem tool
You can examine the system's view of the memory on the machine, by examining /proc/meminfo.
to the overall memory load.
How to debug native process memory allocations
Here's a screenshot:
Here is procrank's usage:
The memory of an Android system is managed by several different allocators, in several different pools.
procrank will show 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.
Details about memory usage are in
Process Memory
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.)
By default, the standard malloc/free/calloc/realloc/memalign routines are used. By setting libc.debug.malloc, different routines are used, which check for certain kinds of memory errors (such as leaks and overruns). This is done by loading a separate shared library (.so) with these different routines.
# 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
In this example, it shows that the native daemons and programs are an order of magnitude smaller than the Dalvik-based services and programs. Also, even the smallest Dalvik program requires about 1.5 meg (Uss) to run.
The shared libraries are named: /system/lib/libc_malloc_debug_leak.so and /system/lib/libc_malloc_debug_qemu.so
The 'top' command will show VSS and RSS.
If you use 'ddms', you can see a summary of the memory used on the machine, by the system and by the different executing processes. Click on the SysInfo tab, and select "Memory Usage" in the box on the upper left of the pane.
Note that you can get the numbers for each process by hovering your mouse over a particular pie slice. Numbers are shown in K and percentages.
You can see very detailed per-process or systemwide memory information with smem.
[INFO NEEDED: how to show dalvik heap info?]
Dan Borstein said this about heap sharing:
# procrank -hUsage: 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:
Also, see ddms info above.
You can also use procrank to view the working set size of each process, and to reset the working set size counters.