當前位置: 首頁>>代碼示例>>Java>>正文


Java Debug.MemoryInfo方法代碼示例

本文整理匯總了Java中android.os.Debug.MemoryInfo方法的典型用法代碼示例。如果您正苦於以下問題:Java Debug.MemoryInfo方法的具體用法?Java Debug.MemoryInfo怎麽用?Java Debug.MemoryInfo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.os.Debug的用法示例。


在下文中一共展示了Debug.MemoryInfo方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: memoryApp

import android.os.Debug; //導入方法依賴的package包/類
/**
 * 打印內存信息
 */
public static void memoryApp(String info) {

    if ( !DEBUG_MEMORY) {
        return;
    }

    Debug.MemoryInfo memoryInfo = new Debug.MemoryInfo();
    int dalvikPrivateDirty = memoryInfo.dalvikPrivateDirty;
    int dalvikPss = memoryInfo.dalvikPss;
    int dalvikSharedDirty = memoryInfo.dalvikSharedDirty;
    int nativePrivateDirty = memoryInfo.nativePrivateDirty;
    int nativePss = memoryInfo.nativePss;
    int nativeSharedDirty = memoryInfo.nativeSharedDirty;
    int otherPss = memoryInfo.otherPss;
    int otherSharedDirty = memoryInfo.otherSharedDirty;
    String content =
        info + "-->dalvikPrivateDirty:" + dalvikPrivateDirty + ",dalvikPss:" + dalvikPss + ",dalvikSharedDirty:" + dalvikSharedDirty + ",nativePrivateDirty:" +
                nativePrivateDirty + ",nativePss:" + nativePss + ",nativeSharedDirty:" + nativeSharedDirty + ",otherPss:" + otherPss + ",otherSharedDirty:" + otherSharedDirty +
                "\n";
    Log.d(
        content);
}
 
開發者ID:wzx54321,項目名稱:XinFramework,代碼行數:26,代碼來源:MemoryLog.java

示例2: MemoryResource

import android.os.Debug; //導入方法依賴的package包/類
public MemoryResource() {
    memoryInfoList.clear();

    memoryInfoList.add(Runtime.getRuntime().maxMemory());
    memoryInfoList.add(Runtime.getRuntime().totalMemory());
    memoryInfoList.add(Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory());
    memoryInfoList.add(Runtime.getRuntime().freeMemory());

    this.natHeapSize = Debug.getNativeHeapSize();
    this.natHeapFreeSize = Debug.getNativeHeapFreeSize();
    this.pss = Debug.getPss();
    this.loadedClassCount = Debug.getLoadedClassCount();

    this.memoryInfo = new Debug.MemoryInfo();
    Debug.getMemoryInfo(memoryInfo);
}
 
開發者ID:TeamThresh,項目名稱:Lantern-sdk,代碼行數:17,代碼來源:MemoryResource.java

示例3: getPssForService

import android.os.Debug; //導入方法依賴的package包/類
/**
 * Get the PSS used by the process hosting a service.
 *
 * @param packageName Package name of the service to search for.
 * @return the PSS in kB of the process hosting a service, or INVALID_PSS.
 */
@VisibleForTesting
static int getPssForService(ComponentName componentName) {
    if (componentName == null) return INVALID_PSS;
    Context context = ContextUtils.getApplicationContext();
    ActivityManager activityManager =
            (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningServiceInfo> services =
            activityManager.getRunningServices(1000);
    if (services == null) return INVALID_PSS;
    int pid = -1;
    for (ActivityManager.RunningServiceInfo info : services) {
        if (componentName.equals(info.service)) {
            pid = info.pid;
            break;
        }
    }
    if (pid == -1) return INVALID_PSS;
    Debug.MemoryInfo infos[] = activityManager.getProcessMemoryInfo(new int[] {pid});
    if (infos == null || infos.length == 0) return INVALID_PSS;
    return infos[0].getTotalPss();
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:28,代碼來源:GSAServiceClient.java

示例4: printMemoryStatus

import android.os.Debug; //導入方法依賴的package包/類
/**
 * 打印當前內存占用日誌,方便外界診斷。注意,這會顯著消耗性能(約50ms左右)
 *
 * @param tag Used to identify the source of a log message.  It usually identifies
 *            the class or activity where the log call occurs.
 * @param msg The message you would like logged.
 */
public static int printMemoryStatus(String tag, String msg) {
    if (RePluginInternal.FOR_DEV) {
        Debug.MemoryInfo mi = new Debug.MemoryInfo();
        Debug.getMemoryInfo(mi);

        String mit = "desc=, memory_v_0_0_1, process=, " + IPC.getCurrentProcessName() +
                ", totalPss=, " + mi.getTotalPss() +
                ", dalvikPss=, " + mi.dalvikPss +
                ", nativeSize=, " + mi.nativePss +
                ", otherPss=, " + mi.otherPss + ", ";

        return Log.i(tag + "-MEMORY", mit + msg);
    }
    return -1;
}
 
開發者ID:wangyupeng1-iri,項目名稱:springreplugin,代碼行數:23,代碼來源:LogDebug.java

示例5: getUsedMemory

import android.os.Debug; //導入方法依賴的package包/類
/** 獲取指定包名應用占用的內存,單位為byte */
public static long getUsedMemory(String packageName) {
	Context context = UIUtils.getContext();
	if (context == null) {
		return -1;
	}
	if (StringUtils.isEmpty(packageName)) {
		packageName = context.getPackageName();
	}
	long size = 0;
	ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
	List<ActivityManager.RunningAppProcessInfo> runapps = activityManager.getRunningAppProcesses();
	for (ActivityManager.RunningAppProcessInfo runapp : runapps) { // 遍曆運行中的程序
		if (packageName.equals(runapp.processName)) {// 得到程序進程名,進程名一般就是包名,但有些程序的進程名並不對應一個包名
			// 返回指定PID程序的內存信息,可以傳遞多個PID,返回的也是數組型的信息
			Debug.MemoryInfo[] processMemoryInfo = activityManager.getProcessMemoryInfo(new int[]{runapp.pid});
			// 得到內存信息中已使用的內存,單位是K
			size = processMemoryInfo[0].getTotalPrivateDirty() * 1024;
		}
	}
	return size;
}
 
開發者ID:cuilitang,項目名稱:CuiMarket,代碼行數:23,代碼來源:SystemUtils.java

示例6: a

import android.os.Debug; //導入方法依賴的package包/類
public static rgv a(Debug.MemoryInfo paramMemoryInfo)
{
  rgv localrgv = new rgv();
  localrgv.a = Integer.valueOf(paramMemoryInfo.dalvikPss);
  localrgv.b = Integer.valueOf(paramMemoryInfo.nativePss);
  localrgv.c = Integer.valueOf(paramMemoryInfo.otherPss);
  localrgv.d = Integer.valueOf(paramMemoryInfo.dalvikPrivateDirty);
  localrgv.e = Integer.valueOf(paramMemoryInfo.nativePrivateDirty);
  localrgv.f = Integer.valueOf(paramMemoryInfo.otherPrivateDirty);
  if (Build.VERSION.SDK_INT >= 19)
  {
    localrgv.g = Integer.valueOf(paramMemoryInfo.getTotalPrivateClean());
    localrgv.i = Integer.valueOf(paramMemoryInfo.getTotalSwappablePss());
  }
  localrgv.h = Integer.valueOf(paramMemoryInfo.getTotalSharedDirty());
  return localrgv;
}
 
開發者ID:ChiangC,項目名稱:FMTech,代碼行數:18,代碼來源:gec.java

示例7: run

import android.os.Debug; //導入方法依賴的package包/類
@Override
public void run() {
    ActivityManager.MemoryInfo systemMemInfo = new ActivityManager.MemoryInfo();
    am.getMemoryInfo(systemMemInfo);
    Debug.MemoryInfo processMemInfo = am.getProcessMemoryInfo(new int[]{Process.myPid()})[0];
    memInfo = new MemInfo(systemMemInfo, processMemInfo);
    notifyObservers();
    handler.postDelayed(memInfoQueryRunnable, interval);
}
 
開發者ID:Manabu-GT,項目名稱:DebugOverlay-Android,代碼行數:10,代碼來源:MemInfoDataModule.java

示例8: onDataAvailable

import android.os.Debug; //導入方法依賴的package包/類
@Override
public void onDataAvailable(MemInfo data) {
    ActivityManager.MemoryInfo systemMemInfo = data.getSystemMemInfo();
    Debug.MemoryInfo procMemInfo = data.getProcessMemInfo();

    if (DebugOverlay.isDebugLoggingEnabled()) {
        Log.d(TAG, "MemTotal(MB):" + DECIMAL_FORMAT.format(systemMemInfo.totalMem / 1048576f));
        Log.d(TAG, "MemAvail(MB):" + DECIMAL_FORMAT.format(systemMemInfo.availMem / 1048576f));
        Log.d(TAG, "MemThreshold(MB):" + DECIMAL_FORMAT.format(systemMemInfo.threshold / 1048576f));
        Log.d(TAG, "TotalPss(MB):" + DECIMAL_FORMAT.format(procMemInfo.getTotalPss() / 1024f));
        Log.d(TAG, "TotalPrivateDirty(MB):" + DECIMAL_FORMAT.format(procMemInfo.getTotalPrivateDirty() / 1024f));
    }
    
    if (memInfoTxtView != null) {
        StringBuilder builder = new StringBuilder(HEADER);
        builder.append(DECIMAL_FORMAT.format(systemMemInfo.availMem / 1048576f)).append(" ")
                .append(DECIMAL_FORMAT.format(procMemInfo.getTotalPss() / 1024f)).append(" ")
                .append(DECIMAL_FORMAT.format(procMemInfo.getTotalPrivateDirty() / 1024f));

        SpannableStringBuilder spannableBuilder = new SpannableStringBuilder(builder.toString());
        if (systemMemInfo.lowMemory) {
            spannableBuilder.setSpan(
                    new TextAppearanceSpan(memInfoTxtView.getContext(), R.style.debugoverlay_LowMemoryTextAppearance),
                    HEADER.length(),
                    spannableBuilder.length(),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
            );
        }
        memInfoTxtView.setText(spannableBuilder);
    }
}
 
開發者ID:Manabu-GT,項目名稱:DebugOverlay-Android,代碼行數:32,代碼來源:MemInfoViewModule.java

示例9: getMemSize

import android.os.Debug; //導入方法依賴的package包/類
private double getMemSize(RunningAppProcessInfo appProcessInfo) {
    // 進程 ID 號
    int pid = appProcessInfo.pid;
    // 獲得該進程占用的內存
    int[] memPid = new int[] { pid };
    // 此 MemoryInfo 位於 android.os.Debug.MemoryInfo 包中,用來統計進程的內存信息
    Debug.MemoryInfo[] memoryInfo = mActivityManager.getProcessMemoryInfo(memPid);
    // 獲取進程占內存用信息 kb 單位
    return memoryInfo[0].dalvikPrivateDirty;
}
 
開發者ID:xcc3641,項目名稱:Watcher,代碼行數:11,代碼來源:MemoryMonitor.java

示例10: getRunningTaskInfos

import android.os.Debug; //導入方法依賴的package包/類
/**
 * 獲取正在運行的所有進程的信息
 */
public static List<TaskInfo> getRunningTaskInfos(Context context) {
    ActivityManager activityManager = (ActivityManager) context
            .getSystemService(Context.ACTIVITY_SERVICE);
    PackageManager packageManager = context.getPackageManager();
    List<ActivityManager.RunningAppProcessInfo> processInfos = activityManager.getRunningAppProcesses();
    List<TaskInfo> taskInfos = new ArrayList<>();
    for (ActivityManager.RunningAppProcessInfo processInfo :
            processInfos) {
        String packagename = processInfo.processName;
        TaskInfo taskInfo = new TaskInfo();
        taskInfo.setPackageName(packagename);//進程名字
        Debug.MemoryInfo[] memoryInfos = activityManager.getProcessMemoryInfo(new int[]{processInfo.pid});
        long memsize = memoryInfos[0].getTotalPrivateDirty();
        taskInfo.setAppMemory(memsize);
        try {
            PackageInfo packageInfo = packageManager.getPackageInfo(packagename,0);
            Drawable icon = packageInfo.applicationInfo.loadIcon(packageManager);
            taskInfo.setIcon(icon);
            String appname = packageInfo.applicationInfo.loadLabel(packageManager).toString();
            taskInfo.setAppName(appname);
            if ((ApplicationInfo.FLAG_SYSTEM & packageInfo.applicationInfo.flags) != 0) {
                //係統進程
                taskInfo.setUserApp(false);
            } else  {
                //用戶進程
                taskInfo.setUserApp(true);
            }
        } catch (Exception e) {
            e.printStackTrace();
            taskInfo.setAppName(packagename);
            taskInfo.setIcon(context.getResources().getDrawable(R.drawable.ic_default));
        }
        taskInfos.add(taskInfo);
    }
    return taskInfos;
}
 
開發者ID:sh2zqp,項目名稱:MobilePhoneSafeProtector,代碼行數:40,代碼來源:TaskInfoParser.java

示例11: getAppPssInfo

import android.os.Debug; //導入方法依賴的package包/類
/**
 * 獲取應用實際占用內存
 *
 * @param context
 * @param pid
 * @return 應用pss信息KB
 */
public static PssInfo getAppPssInfo(Context context, int pid) {
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    Debug.MemoryInfo memoryInfo = am.getProcessMemoryInfo(new int[]{pid})[0];
    PssInfo pssInfo = new PssInfo();
    pssInfo.totalPss = memoryInfo.getTotalPss();
    pssInfo.dalvikPss = memoryInfo.dalvikPss;
    pssInfo.nativePss = memoryInfo.nativePss;
    pssInfo.otherPss = memoryInfo.otherPss;
    return pssInfo;
}
 
開發者ID:Kyson,項目名稱:MemoryMonitor,代碼行數:18,代碼來源:MemoryUtil.java

示例12: memoryOK

import android.os.Debug; //導入方法依賴的package包/類
private boolean memoryOK() {
    ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
    ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
    activityManager.getMemoryInfo(mi);

    Debug.MemoryInfo md = new Debug.MemoryInfo();
    Debug.getMemoryInfo(md);
    Runtime rt = Runtime.getRuntime();
    long used_memory = md.getTotalPss() / 1024;
    long max_memory = rt.maxMemory() / (1024 * 1024);
    return true;
    //return (max_memory - used_memory) > MEMORY_LIMIT;
}
 
開發者ID:bbodin,項目名稱:slambench-android,代碼行數:14,代碼來源:BenchmarkActivity.java

示例13: QosThread

import android.os.Debug; //導入方法依賴的package包/類
public QosThread(ActivityManager manager, Handler handler,Context context) {
    mContext = context;
    mHandler = handler;
    mCpuStats = new Cpu(mContext.getPackageName());
    mActivityManager = manager;
    mi = new Debug.MemoryInfo();
    mRunning = true;
    mQosObject = new QosObject();
}
 
開發者ID:ksvc,項目名稱:ksyhttpcache_android,代碼行數:10,代碼來源:QosThread.java

示例14: QosInfoThread

import android.os.Debug; //導入方法依賴的package包/類
public QosInfoThread(Context context, Handler handler) {
    mHandler = handler;
    mCpuStats = new CpuInfo();
    mi = new Debug.MemoryInfo();
    mRunning = true;
    mQosObject = new QosBean();
    if(context != null)
        mPackageName = context.getPackageName();
}
 
開發者ID:ksvc,項目名稱:KSYMediaPlayer_Android,代碼行數:10,代碼來源:QosInfoThread.java

示例15: QosThread

import android.os.Debug; //導入方法依賴的package包/類
public QosThread(Context context, Handler handler) {
    mHandler = handler;
    mCpuStats = new Cpu();
    mi = new Debug.MemoryInfo();
    mRunning = true;
    mQosObject = new QosObject();
    if(context != null)
        mPackageName = context.getPackageName();
}
 
開發者ID:ksvc,項目名稱:KSYMediaPlayer_Android,代碼行數:10,代碼來源:QosThread.java


注:本文中的android.os.Debug.MemoryInfo方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。