Android中如何查看内存
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
public static final Creator<ActivityManager.MemoryInfo> | CREATOR | ||||||||||
public long | availMem | The available memory on the system. 表示系统剩余内存 | |||||||||
public boolean | lowMemory | Set to true if the system considers itself to currently
be in a low memory situation. 它是boolean值,表示系统是否处于低内存运行 | |||||||||
public long | threshold | The threshold of availMem at which we consider memory to be
low and start killing background services and other non-extraneous
processes.它表示当系统剩余内存低于好多时就看成低内存运行 | |||||||||
public long | totalMem | The total memory accessible by the kernel. |
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
public static final Creator<Debug.MemoryInfo> | CREATOR | ||||||||||
public int | dalvikPrivateDirty | The private dirty pages used by dalvik. | |||||||||
public int | dalvikPss | The proportional set size for dalvik. | |||||||||
public int | dalvikSharedDirty | The shared dirty pages used by dalvik. | |||||||||
public int | nativePrivateDirty | The private dirty pages used by the native heap. | |||||||||
public int | nativePss | The proportional set size for the native heap. | |||||||||
public int | nativeSharedDirty | The shared dirty pages used by the native heap. | |||||||||
public int | otherPrivateDirty | The private dirty pages used by everything else. | |||||||||
public int | otherPss | The proportional set size for everything else. | |||||||||
public int | otherSharedDirty | The shared dirty pages used by everything else. |
static long getNativeHeapFreeSize()
public static long getPss ()
Retrieves the PSS memory used by the process as given by the smaps.
实例1
int cnt=0;
final static int kBufferMinSize=1000;
final static int kBufferMaxSize=2000;
StringBuffer strBuffer=new StringBuffer(kBufferMinSize);
StringBuffer strBuffer2=new StringBuffer(kBufferMinSize);
StringBuffer strBuffer3=new StringBuffer(kBufferMinSize);
StringBuffer strBufferNativePss=new StringBuffer(kBufferMinSize);
StringBuffer strBufferDalvikPss=new StringBuffer(kBufferMinSize);
StringBuffer strBufferOtherPss=new StringBuffer(kBufferMinSize);
Debug.MemoryInfo memoryInfo=new Debug.MemoryInfo();
final static String tag="robin";
void printMemory()
{
long totalMemory=Runtime.getRuntime().totalMemory();
long freeMemory=Runtime.getRuntime().freeMemory();
long usedMemory=(totalMemory-freeMemory)>>10;
totalMemory=totalMemory>>10;
freeMemory=freeMemory>>10;
if(strBuffer.length()>kBufferMaxSize)
{
strBuffer.delete(0,strBuffer.length());
strBuffer2.delete(0,strBuffer2.length());
strBuffer3.delete(0,strBuffer3.length());
strBufferNativePss.delete(0,strBufferNativePss.length());
strBufferDalvikPss.delete(0,strBufferDalvikPss.length());
}
strBuffer.append(usedMemory+",");
strBuffer2.append(totalMemory+",");
strBuffer3.append((Debug.getNativeHeapSize()>>10)+",");
Debug.getMemoryInfo(memoryInfo);
strBufferNativePss.append((memoryInfo.nativePss)+",");
strBufferDalvikPss.append((memoryInfo.dalvikPss)+",");
if(cnt++%10==0)
{
Log.i(tag,"usedMemory:"+strBuffer.toString());
Log.i(tag,"totalMemory:"+strBuffer2.toString());
Log.i(tag,"NativeHeapSize:"+strBuffer3.toString());
Log.i(tag,"Native PSS:"+strBufferNativePss.toString());
Log.i(tag,"Dalvik PSS:"+strBufferDalvikPss.toString());
}
}
注意,对于输出的内存信息日志,我们稍作编辑就可以用于在excel产中图表,比便更直观的进行分析。郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。