Android MemInfo 各项的意义(转)
http://gdgzzch.blog.163.com/blog/static/37640452201371483147573/
http://stackoverflow.com/questions/2298208/how-to-discover-memory-usage-of-my-application-in-android#2299813
http://my.oschina.net/shaorongjie/blog/128442
可以使用adb shell dumpsys meminfo -a <process id>/<process name>来查看一个进程的memory。截图如下:
Naitve Heap Size: 从mallinfo usmblks获得,代表最大总共分配空间
Native Heap Alloc: 从mallinfo uorblks获得,总共分配空间
Native Heap Free: 从mallinfo fordblks获得,代表总共剩余空间
Native Heap Size 约等于Native Heap Alloc + Native Heap Free
mallinfo是一个C库, mallinfo 函数提供了各种各样的通过C的malloc()函数分配的内存的统计信息。
Dalvik Heap Size:从Runtime totalMemory()获得,Dalvik Heap总共的内存大小。
Dalvik Heap Alloc: Runtime totalMemory()-freeMemory() ,Dalvik Heap分配的内存大小。
Dalvik Heap Free:从Runtime freeMemory()获得,Dalvik Heap剩余的内存大小。
Dalvik Heap Size 约等于Dalvik Heap Alloc + Dalvik Heap Free
OtherPss, include
Cursor,Ashmem, Other Dev, .so mmap, .jar mmap, .apk mmap, .ttf mmap,
.dex mmap, Other mmap, Unkown统计信息都可以在process的smap文件看到。
Objects and SQL 信息都是从Android Debug信息中获得。
其他类型 smap 路径名称 描述
Cursor /dev/ashmem/Cursor Cursor消耗的内存(KB)
Ashmem /dev/ashmem 匿名共享内存用来提供共享内存通过分配一个多个进程
可以共享的带名称的内存块
Other dev /dev/ 内部driver占用的在 “Other dev”
.so mmap .so C 库代码占用的内存
.jar mmap .jar Java 文件代码占用的内存
.apk mmap .apk apk代码占用的内存
.ttf mmap .ttf ttf 文件代码占用的内存
.dex mmap .dex Dex 文件代码占用的内存
Other mmap 其他文件占用的内存
But as to what the difference is between "Pss", "PrivateDirty", and "SharedDirty"... well now the fun begins.
A lot of memory in Android (and Linux systems in general) is actually
 shared across multiple processes.  So how much memory a processes uses
is really not clear.  Add on top of that paging out to disk (let alone
swap which we don't use on Android) and it is even less clear.
Thus if you were to take all of the physical RAM actually mapped in
to each process, and add up all of the processes, you would probably end
 up with a number much greater than the actual total RAM.
The Pss number is a metric the kernel computes that takes into
account memory sharing -- basically each page of RAM in a process is
scaled by a ratio of the number of other processes also using that page.
  This way you can (in theory) add up the pss across all processes to
see the total RAM they are using, and compare pss between processes to
get a rough idea of their relative weight.
The other interesting metric here is PrivateDirty, which is basically
 the amount of RAM inside the process that can not be paged to disk (it
is not backed by the same data on disk), and is not shared with any
other processes.  Another way to look at this is the RAM that will
become available to the system when that process goes away (and probably
 quickly subsumed into caches and other uses of it).
That is pretty much the SDK APIs for this. However there is more you can do as a developer with your device.
Using adb, there is a lot of information you can get about the memory
 use of a running system.  A common one is the command "adb shell
dumpsys meminfo" which will spit out a bunch of information about the
memory use of each Java process, containing the above info as well as a
variety of other things.  You can also tack on the name or pid of a
single process to see, for example "adb shell dumpsys meminfo system"
give me the system process:
** MEMINFO in pid 890 [system] **
native dalvik other total
size: 10940 7047 N/A 17987
allocated: 8943 5516 N/A 14459
free: 336 1531 N/A 1867
(Pss): 4585 9282 11916 25783
(shared dirty): 2184 3596 916 6696
(priv dirty): 4504 5956 7456 17916 Objects
Views: 149 ViewRoots: 4
AppContexts: 13 Activities: 0
Assets: 4 AssetManagers: 4
Local Binders: 141 Proxy Binders: 158
Death Recipients: 49
OpenSSL Sockets: 0 SQL
heap: 205 dbFiles: 0
numPagers: 0 inactivePageKB: 0
activePageKB: 0
The top section is the main one, where "size" is the total size in address space of a particular heap, "allocated" is the kb of actual allocations that heap thinks it has, "free" is the remaining kb free the heap has for additional allocations, and "pss" and "priv dirty" are the same as discussed before specific to pages associated with each of the heaps.
If you just want to look at memory usage across all processes, you can use the command "adb shell procrank". Output of this on the same system looks like:
PID Vss Rss Pss Uss cmdline
890 84456K 48668K 25850K 21284K system_server
1231 50748K 39088K 17587K 13792K com.android.launcher2
947 34488K 28528K 10834K 9308K com.android.wallpaper
987 26964K 26956K 8751K 7308K com.google.process.gapps
954 24300K 24296K 6249K 4824K com.android.phone
948 23020K 23016K 5864K 4748K com.android.inputmethod.latin
888 25728K 25724K 5774K 3668K zygote
977 24100K 24096K 5667K 4340K android.process.acore
...
59 336K 332K 99K 92K /system/bin/installd
60 396K 392K 93K 84K /system/bin/keystore
51 280K 276K 74K 68K /system/bin/servicemanager
54 256K 252K 69K 64K /system/bin/debuggerd
Here the Vss and Rss columns are basically noise (these are the straight-forward address space and RAM usage of a process, where if you add up the RAM usage across processes you get an ridiculously large number).
Pss is as we've seen before, and Uss is Priv Dirty.
Interesting thing to note here: Pss and Uss are slightly (or more than slightly) different than what we saw in meminfo. Why is that? Well procrank uses a different kernel mechanism to collect its data than meminfo does, and they give slightly different results. Why is that? Honestly I haven't a clue. I believe procrank may be the more accurate one... but really, this just leave the point: "take any memory info you get with a grain of salt; often a very large grain."
Finally there is the command "adb shell cat /proc/meminfo" that gives a summary of the overall memory usage of the system. There is a lot of data here, only the first few numbers worth discussing (and the remaining ones understood by few people, and my questions of those few people about them often resulting in conflicting explanations):
MemTotal: 395144 kB
MemFree: 184936 kB
Buffers: 880 kB
Cached: 84104 kB
SwapCached: 0 kB
MemTotal is the total amount of memory available to the kernel and user space (often less than the actual physical RAM of the device, since some of that RAM is needed for the radio, DMA buffers, etc).
MemFree is the amount of RAM that is not being used at all. The number you see here is very high; typically on an Android system this would be only a few MB, since we try to use available memory to keep processes running
Cached is the RAM being used for filesystem caches and other such things. Typical systems will need to have 20MB or so for this to avoid getting into bad paging states; the Android out of memory killer is tuned for a particular system to make sure that background processes are killed before the cached RAM is consumed too much by them to result in such paging.
Android MemInfo 各项的意义(转)的更多相关文章
- Android MemInfo
		Note that memory usage on modern operating systems like Linux is an extremely complicated and diffic ... 
- 论Android代码加固的意义和hook
		加固的意义 从安卓2.x版本起,加固技术就逐渐火了起来.最初,只有一些创业型公司涉及加固领域:随着安卓应用的逐渐升温,诸如阿里.腾讯.百度等大型互联网公司逐渐涉及该领域. 那么为什么要对APP进行加固 ... 
- Android中Application的意义及使用方法
		首先,在一个Android程序中,有且只有一个Application对象,在程序启动的时候,首先执行Application的onCreate方法,这是一个Android应用的入口,在开发中,我们常常自 ... 
- 【Android】Fragment真正意义上的onResume和onPause
		前言 Fragment虽然有onResume和onPause的,但是这两个方法是Activity的方法,调用时机也是与Activity相同,和ViewPager搭配使用这个方法就很鸡肋了,根本不是你想 ... 
- /proc/sys/net/ipv4/下各项的意义
		/proc/sys/net/ipv4/icmp_timeexceed_rate这个在traceroute时导致著名的“Solaris middle star”.这个文件控制发送ICMP Tim ... 
- 漫谈moosefs中cgi各项的意义
		原创:http://www.cnblogs.com/bugutian/p/6869278.html 转载请注明出处 一.先上一张图 二.解释 1. Metadata Servers (masters) ... 
- 转: 腾讯Bugly干货分享:Android应用性能评测调优
		转:http://www.kuqin.com/shuoit/20150618/346693.html?utm_source=www.race604.com 前言 在智能手机App竞争越来越激烈的今天, ... 
- [笔记] dumpsys meminfo数据与smaps文件对应关系
		通过cat /proc/$PID/smaps可以查看进程内存的详细映射情况.详细解析可以参考kernel的文档/Documentation/filesystems/proc.txt 如果我们的Andr ... 
- 【Android自学日记】五大布局常用属性
		线性布局(LinearLayout)常用属性: android:orientation="vertical"--决定子类控件的排布方式(vertical垂直:horizontal水 ... 
随机推荐
- ExtJs TreePanel 全选与反选
			selectAll: function() { this.getRootNode().eachChild(function (child) { child.set('checked', true); ... 
- phalcon的CLI应用
			CLI应用是命令行下执行的程序, 可以应用于定时任务,守护进程, 脚本, 公用命令等等. 最小的目录结构:app/config/config.phpapp/tasks/MainTask.phpapp/ ... 
- 使用powerdesinger逆向生成表结构
			(1).使powerdesigner建立和数据库的链接 (2)配置链接详情 (3) (4) (5)更新表结构 (6) (7) 附加:当有时候会报错时: 解决方式: (1.1)更改所连接的数据库 (1. ... 
- EasyUI项目中的自定义JS
			自定义方法: (function($) { $.extend($, { //获取下标,删除时使用 getArrayIndex : function (array,value) { var index ... 
- 统一建模语言 UML (2)
			UML的图 1.用例图(use case diagram) 用例图(Use Case Diagram)是被称为参与者(Actor)的外部用户所能观察到的系统功能的模型图 列出系统中的用例和参与者 显示 ... 
- 【C#】【MySQL】C# 查询数据库语句@Row:=@Row+1以及执行存储过程失败解决方案
			如何实现数据库查询产生虚拟的一列序号的功能: ) )AS r; 该语句可以实现产生虚拟的一列数据在MySQL中运行没有问题. 但是在C#里面调用去出现了错误"Parameter '@ROW' ... 
- MongoDB 启动基于角色的登录认证功能
			参见:https://help.aliyun.com/knowledge_detail/37451.html 步骤一:在未开启认证的环境下,登录到数据库 [mongodb@rac3 bin]$ ./m ... 
- OpenCV_基于局部自适应阈值的图像二值化
			在图像处理应用中二值化操作是一个很常用的处理方式,例如零器件图片的处理.文本图片和验证码图片中字符的提取.车牌识别中的字符分割,以及视频图像中的运动目标检测中的前景分割,等等. 较为常用的图像二值化方 ... 
- 2014Esri全球用户大会之影像和栅格
			1.现在Esri已将影像作为GIS解决方案的一部分,其详细战略部署是如何的? 在过去的十年.Esri有规划的在ArcGIS平台(主要为Desktop和Server)中管理和开发影像和栅格功能.这包含影 ... 
- js上传本地图片遇到的问题
			1.改变页面文件上传默认的样式 <input type="text" size="20" id="upfile" style=&quo ... 
