List of usage examples for android.app ActivityManager getProcessMemoryInfo
public Debug.MemoryInfo[] getProcessMemoryInfo(int[] pids)
From source file:Main.java
public static long[] getPSS(Context context, int pid) { long[] value = new long[3]; // Natvie Dalvik Total if (pid >= 0) { int[] pids = new int[1]; pids[0] = pid;//from w ww . jav a 2 s .c o m ActivityManager mAm = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); MemoryInfo[] memoryInfoArray = mAm.getProcessMemoryInfo(pids); MemoryInfo pidMemoryInfo = memoryInfoArray[0]; value[0] = pidMemoryInfo.nativePss; value[1] = pidMemoryInfo.dalvikPss; value[2] = pidMemoryInfo.getTotalPss(); } else { value[0] = 0; value[1] = 0; value[2] = 0; } return value; }
From source file:Main.java
public static long[] getPrivDirty(Context context, int pid) { ActivityManager mAm = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); int[] pids = new int[1]; pids[0] = pid;// w w w . ja va2 s. c o m MemoryInfo[] memoryInfoArray = mAm.getProcessMemoryInfo(pids); MemoryInfo pidMemoryInfo = memoryInfoArray[0]; long[] value = new long[3]; // Natvie Dalvik Total value[0] = pidMemoryInfo.nativePrivateDirty; value[1] = pidMemoryInfo.dalvikPrivateDirty; value[2] = pidMemoryInfo.getTotalPrivateDirty(); return value; }
From source file:be.k0suke.tistats.TiStatsModule.java
@Kroll.method public String stats() { Log.d(LCAT, "stats called"); TiApplication tiApp = TiApplication.getInstance(); ActivityManager activityManager = (ActivityManager) tiApp.getSystemService(Activity.ACTIVITY_SERVICE); JSONObject json = new JSONObject(); try {/* ww w .j ava2s . com*/ JSONObject memoryInfoJson = new JSONObject(); ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo(); activityManager.getMemoryInfo(memoryInfo); memoryInfoJson.put("availMem", (int) (memoryInfo.availMem)); JSONObject processMemoryInfoJson = new JSONObject(); int[] pids = new int[1]; pids[0] = android.os.Process.myPid(); android.os.Debug.MemoryInfo[] processMemoryInfo = activityManager.getProcessMemoryInfo(pids); processMemoryInfoJson.put("totalPrivateDirty", processMemoryInfo[0].getTotalPrivateDirty()); processMemoryInfoJson.put("totalSharedDirty", processMemoryInfo[0].getTotalSharedDirty()); processMemoryInfoJson.put("totalPss", processMemoryInfo[0].getTotalPss()); json.put("memoryInfo", memoryInfoJson); json.put("processMemoryInfo", processMemoryInfoJson); } catch (JSONException e) { } return json.toString(); }
From source file:org.wso2.emm.agent.api.RuntimeInfo.java
public Map<String, Application> getAppMemory() throws AndroidAgentException { Map<String, Application> applications = new HashMap<>(); Application appData;/*from w w w . j av a2 s . c om*/ ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); for (String topCommandRow : topCommandRows) { if (topCommandRow != null && !topCommandRow.isEmpty() && !topCommandRow.contains(" root ")) { String[] columns = topCommandRow.replaceFirst("^\\s*", "").split(" "); String pidColumnValue = columns[0].trim(); if (!pidColumnValue.isEmpty() && TextUtils.isDigitsOnly(pidColumnValue)) { appData = new Application(); appData.setPackageName(columns[columns.length - 1]); int pid = Integer.parseInt(pidColumnValue); appData.setPid(Integer.parseInt(columns[0])); int totalPSS = activityManager.getProcessMemoryInfo(new int[] { pid })[0].getTotalPss(); appData.setPss(totalPSS); int totalPrivateDirty = activityManager.getProcessMemoryInfo(new int[] { pid })[0] .getTotalPrivateDirty(); appData.setUss(totalPrivateDirty); int totalSharedDirty = activityManager.getProcessMemoryInfo(new int[] { pid })[0] .getTotalSharedDirty(); appData.setSharedDirty(totalSharedDirty); applications.put(appData.getPackageName(), appData); } } } return applications; }
From source file:com.mozilla.SUTAgentAndroid.service.DoCommand.java
public String StatProcess(String string) { String sRet = ""; ActivityManager aMgr = (ActivityManager) contextWrapper.getSystemService(Activity.ACTIVITY_SERVICE); int[] nPids = new int[1]; nPids[0] = Integer.parseInt(string); android.os.Debug.MemoryInfo[] mi = aMgr.getProcessMemoryInfo(nPids); sRet = "Dalvik Private Dirty pages " + mi[0].dalvikPrivateDirty + " kb\n"; sRet += "Dalvik Proportional Set Size " + mi[0].dalvikPss + " kb\n"; sRet += "Dalvik Shared Dirty pages " + mi[0].dalvikSharedDirty + " kb\n\n"; sRet += "Native Private Dirty pages heap " + mi[0].nativePrivateDirty + " kb\n"; sRet += "Native Proportional Set Size heap " + mi[0].nativePss + " kb\n"; sRet += "Native Shared Dirty pages heap " + mi[0].nativeSharedDirty + " kb\n\n"; sRet += "Other Private Dirty pages " + mi[0].otherPrivateDirty + " kb\n"; sRet += "Other Proportional Set Size " + mi[0].otherPss + " kb\n"; sRet += "Other Shared Dirty pages " + mi[0].otherSharedDirty + " kb\n\n"; sRet += "Total Private Dirty Memory " + mi[0].getTotalPrivateDirty() + " kb\n"; sRet += "Total Proportional Set Size Memory " + mi[0].getTotalPss() + " kb\n"; sRet += "Total Shared Dirty Memory " + mi[0].getTotalSharedDirty() + " kb"; return (sRet); }