Search in sources :

Example 1 with MemoryInfo

use of android.os.Debug.MemoryInfo in project GT by Tencent.

the class MemUtils method getPSS.

/**
	 * 获取进程内存PSS数据
	 * 
	 * @param context
	 * @param pid
	 * @return nativePss、dalvikPss、TotalPss
	 */
public static long[] getPSS(Context context, int pid) {
    // Natvie Dalvik Total
    long[] value = new long[3];
    if (pid >= 0) {
        int[] pids = new int[1];
        pids[0] = pid;
        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;
}
Also used : MemoryInfo(android.os.Debug.MemoryInfo) ActivityManager(android.app.ActivityManager)

Example 2 with MemoryInfo

use of android.os.Debug.MemoryInfo in project GT by Tencent.

the class MemUtils method getPrivDirty.

/**
	 * 获取进程内存Private Dirty数据
	 * 
	 * @param context
	 * @param pid
	 *            进程ID
	 * @return nativePrivateDirty、dalvikPrivateDirty、 TotalPrivateDirty
	 */
public static long[] getPrivDirty(Context context, int pid) {
    ActivityManager mAm = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    int[] pids = new int[1];
    pids[0] = pid;
    MemoryInfo[] memoryInfoArray = mAm.getProcessMemoryInfo(pids);
    MemoryInfo pidMemoryInfo = memoryInfoArray[0];
    // Natvie Dalvik Total
    long[] value = new long[3];
    value[0] = pidMemoryInfo.nativePrivateDirty;
    value[1] = pidMemoryInfo.dalvikPrivateDirty;
    value[2] = pidMemoryInfo.getTotalPrivateDirty();
    return value;
}
Also used : MemoryInfo(android.os.Debug.MemoryInfo) ActivityManager(android.app.ActivityManager)

Example 3 with MemoryInfo

use of android.os.Debug.MemoryInfo in project android_frameworks_base by ParanoidAndroid.

the class MemoryUsageTest method getPss.

private int getPss(String processName) {
    ActivityManager am = (ActivityManager) getInstrumentation().getContext().getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningAppProcessInfo> apps = am.getRunningAppProcesses();
    for (RunningAppProcessInfo proc : apps) {
        if (!proc.processName.equals(processName)) {
            continue;
        }
        int[] pids = { proc.pid };
        MemoryInfo meminfo = am.getProcessMemoryInfo(pids)[0];
        return meminfo.getTotalPss();
    }
    return -1;
}
Also used : MemoryInfo(android.os.Debug.MemoryInfo) RunningAppProcessInfo(android.app.ActivityManager.RunningAppProcessInfo) ActivityManager(android.app.ActivityManager) IActivityManager(android.app.IActivityManager)

Example 4 with MemoryInfo

use of android.os.Debug.MemoryInfo in project android_frameworks_base by crdroidandroid.

the class MemoryUsageTest method getPss.

private int getPss(String processName) {
    ActivityManager am = (ActivityManager) getInstrumentation().getContext().getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningAppProcessInfo> apps = am.getRunningAppProcesses();
    for (RunningAppProcessInfo proc : apps) {
        if (!proc.processName.equals(processName)) {
            continue;
        }
        int[] pids = { proc.pid };
        MemoryInfo meminfo = am.getProcessMemoryInfo(pids)[0];
        return meminfo.getTotalPss();
    }
    return -1;
}
Also used : MemoryInfo(android.os.Debug.MemoryInfo) RunningAppProcessInfo(android.app.ActivityManager.RunningAppProcessInfo) ActivityManager(android.app.ActivityManager) IActivityManager(android.app.IActivityManager)

Example 5 with MemoryInfo

use of android.os.Debug.MemoryInfo in project platform_frameworks_base by android.

the class MemoryUsageTest method getPss.

private int getPss(String processName) {
    ActivityManager am = (ActivityManager) getInstrumentation().getContext().getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningAppProcessInfo> apps = am.getRunningAppProcesses();
    for (RunningAppProcessInfo proc : apps) {
        if (!proc.processName.equals(processName)) {
            continue;
        }
        int[] pids = { proc.pid };
        MemoryInfo meminfo = am.getProcessMemoryInfo(pids)[0];
        return meminfo.getTotalPss();
    }
    return -1;
}
Also used : MemoryInfo(android.os.Debug.MemoryInfo) RunningAppProcessInfo(android.app.ActivityManager.RunningAppProcessInfo) ActivityManager(android.app.ActivityManager) IActivityManager(android.app.IActivityManager)

Aggregations

MemoryInfo (android.os.Debug.MemoryInfo)8 ActivityManager (android.app.ActivityManager)7 RunningAppProcessInfo (android.app.ActivityManager.RunningAppProcessInfo)5 IActivityManager (android.app.IActivityManager)5