1、android APP安装流程
2、通过adb shell启动APP(Android Debug Bridge)
1)打开cmd.exe,将当前路径切换到adb.exe所在路径。我的是D:\adt-bundle-windows-x86_64-20131030\sdk\platform-tools
2)然后按下图输入,即可启动app
3)exit退出adb shell
3、通过adb shell查看app信息
查看所有APP内存使用:dumpsys meminfo
查看所有进程的PID:ps -x
查看PID为27720的内存使用:dumpsys meminfo 27720
系统整个内存的使用情况:cat /proc/meminfo
adb shell procrank
4、android对查看内存的支持
public class MainActivity extends Activity{
private static final String TAG = MainActivity.class.getSimpleName();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
am.getMemoryInfo(memoryInfo);
Log.d(TAG, "ActivityManager|availMem:"+(memoryInfo.availMem>>20)
+"M|threshold:"+(memoryInfo.threshold>>20)
+"M|totalMem:"+(memoryInfo.totalMem>>20)+"M");
Log.d(TAG, "memory class:"+am.getMemoryClass()+"M|"+am.getLargeMemoryClass()+"M");
int pid = Process.myPid();
for(ActivityManager.RunningAppProcessInfo info:am.getRunningAppProcesses()){
if(info.pid == pid){
Log.d(TAG, pid+"-"+info.processName+"-"+info.importance);
}
}
Debug.MemoryInfo dmi = new Debug.MemoryInfo();
Debug.getMemoryInfo(dmi);
Log.d(TAG, "Debug-dalvik:"+dmi.dalvikPrivateDirty+"-"+dmi.dalvikPss+"-"+dmi.dalvikSharedDirty);
Log.d(TAG, "Debug-native:"+dmi.nativePrivateDirty+"-"+dmi.nativePss+"-"+dmi.nativeSharedDirty);
Log.d(TAG, "Debug-other:"+dmi.otherPrivateDirty+"-"+dmi.otherPss+"-"+dmi.otherSharedDirty);
Log.d(TAG, "total:"+dmi.getTotalPrivateClean()+"K|"+dmi.getTotalPrivateDirty()+"K|"+dmi.getTotalPss()
+"K|"+dmi.getTotalSharedClean()+"K|"+dmi.getTotalSharedDirty()+"K|"+dmi.getTotalSwappablePss());
Log.d(TAG, "native heap:"+Debug.getNativeHeapSize()+"B|"+Debug.getNativeHeapFreeSize()+"B|"+Debug.getNativeHeapAllocatedSize()+"B");
}
}
5、通过DDMS(Dalvik Debug Monitor Service)来查看android APP内存使用详情
连接手机,在手机上运行你的APP,在eclipse中从Java Perspective切换到DDMS Perspective。选择你的device和app,点击左边的update heap和右边的Cause GC。
6、Garbage Collector
1)常见Log
D|dalvikvm|GC_CONCURRENT freed 1829K, 29% free 16239K/22852K, paused 3ms+5ms, total 81ms
GC_FOR_ALLOC freed 1180K, 15% free 46653K/54864K, paused 194ms, total 194ms
I|dalvikvm-heap|Grow heap (frag case) to 30.405MB for 2486416-byte allocation
WAIT_FOR_CONCURRENT_GC blocked 34ms
GC_EXPLICIT freed 201K, 18% free 10079K/12188K, paused 2ms+2ms, total 26ms