/** The proportional set size for dalvik. */public int dalvikPss;/** The private dirty pages used by dalvik. */public int dalvikPrivateDirty;/** The shared dirty pages used by dalvik. */public int dalvikSharedDirty;
/** The proportional set size for the native heap. */public int nativePss;/** The private dirty pages used by the native heap. */public int nativePrivateDirty;/** The shared dirty pages used by the native heap. */public int nativeSharedDirty;
/** The proportional set size for everything else. */public int otherPss;/** The private dirty pages used by everything else. */public int otherPrivateDirty;/** The shared dirty pages used by everything else. */public int otherSharedDirty;
P. S.我注意到主题仍然缺乏一个实际而简单的代码片段,说明如果性能不是关键要求,如何估计进程的私有内存使用:
Debug.MemoryInfo memInfo = new Debug.MemoryInfo();Debug.getMemoryInfo(memInfo);long res = memInfo.getTotalPrivateDirty();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)res += memInfo.getTotalPrivateClean();
return res * 1024L;
// su command to get root accessProcess process = Runtime.getRuntime().exec("su");DataOutputStream dataOutputStream =new DataOutputStream(process.getOutputStream());DataInputStream dataInputStream =new DataInputStream(process.getInputStream());if (dataInputStream != null && dataOutputStream != null) {// write id to console with enterdataOutputStream.writeBytes("id\n");dataOutputStream.flush();String Uid = dataInputStream.readLine();// read output and check if uid is thereif (Uid.contains("uid=0")) {// you are root user}}
使用su执行您的命令
Process process = Runtime.getRuntime().exec("su");DataOutputStream dataOutputStream =new DataOutputStream(process.getOutputStream());if (dataOutputStream != null) {// adb commanddataOutputStream.writeBytes("procrank\n");dataOutputStream.flush();BufferedInputStream bufferedInputStream =new BufferedInputStream(process.getInputStream());// this is important as it takes times to return to next line so wait// else you with get empty bytes in buffered streamtry {Thread.sleep(10000);} catch (InterruptedException e) {e.printStackTrace();}// read buffered stream into byte,char etc.byte[] bff = new byte[bufferedInputStream.available()];bufferedInputStream.read(bff);bufferedInputStream.close();}}