From 74868d1c5d47b9f0475e4df1966f41f861521950 Mon Sep 17 00:00:00 2001 From: Dianne Hackborn Date: Mon, 23 Jun 2014 17:13:16 -0700 Subject: [PATCH] More work on proc stats UI for summary display. Improve how we compute the bar to better represent the actual memory situation. Scale the per-app bars to try to show them better in terms of overall memory use. And some bug fixes. Change-Id: I336ff0c938a39092f2ac54d354c57d6b1b8220c0 --- .../applications/ProcessStatsMemDetail.java | 4 +- .../settings/applications/ProcessStatsUi.java | 89 ++++++++++++++++++- 2 files changed, 87 insertions(+), 6 deletions(-) diff --git a/src/com/android/settings/applications/ProcessStatsMemDetail.java b/src/com/android/settings/applications/ProcessStatsMemDetail.java index 65e94f7a79b..ab7dbdbe4d4 100644 --- a/src/com/android/settings/applications/ProcessStatsMemDetail.java +++ b/src/com/android/settings/applications/ProcessStatsMemDetail.java @@ -135,6 +135,8 @@ public class ProcessStatsMemDetail extends Fragment { CharSequence[] labels = getResources().getTextArray(R.array.proc_stats_process_states); addMemUseDetailsItem(mMemUseParent, getResources().getText(R.string.mem_use_kernel_type), mMemKernelWeight); + addMemUseDetailsItem(mMemUseParent, + getResources().getText(R.string.mem_use_zram_type), mMemZRamWeight); addMemUseDetailsItem(mMemUseParent, getResources().getText(R.string.mem_use_native_type), mMemNativeWeight); for (int i=0; i= ProcessStats.STATE_IMPORTANT_FOREGROUND) { + backgroundWeight += totalMem.processStateWeight[i]; + persBackgroundWeight += totalMem.processStateWeight[i]; + } + if (i == ProcessStats.STATE_PERSISTENT) { + persBackgroundWeight += totalMem.processStateWeight[i]; + } } } + if (DEBUG) { + Log.i(TAG, "Used RAM: " + Formatter.formatShortFileSize(getActivity(), + (long)((usedWeight * 1024) / memTotalTime))); + Log.i(TAG, "Free RAM: " + Formatter.formatShortFileSize(getActivity(), + (long)((freeWeight * 1024) / memTotalTime))); + Log.i(TAG, "Total RAM: " + Formatter.formatShortFileSize(getActivity(), + (long)(((freeWeight+usedWeight) * 1024) / memTotalTime))); + Log.i(TAG, "Background+Cached RAM: " + Formatter.formatShortFileSize(getActivity(), + (long)((backgroundWeight * 1024) / memTotalTime))); + } mMemTotalWeight = freeWeight + usedWeight; - float usedRatio = (float)(usedWeight/(freeWeight+usedWeight)); + + // For computing the ratio to show, we want to count the baseline cached RAM we + // need (at which point we start killing processes) as used RAM, so that if we + // reach the point of thrashing due to no RAM for any background processes we + // report that as RAM being full. To do this, we need to first convert the weights + // back to actual RAM... and since the RAM values we compute here won't exactly + // match the real physical RAM, scale those to the actual physical RAM. No problem! + double usedRam = (usedWeight*1024)/memTotalTime; + double freeRam = (freeWeight*1024)/memTotalTime; + double totalRam = usedRam + freeRam; + MemInfoReader memReader = new MemInfoReader(); + memReader.readMemInfo(); + double realTotalRam = memReader.getTotalSize(); + double totalScale = realTotalRam / totalRam; + double realUsedRam = usedRam * totalScale; + double realFreeRam = freeRam * totalScale; + if (DEBUG) { + Log.i(TAG, "Scaled Used RAM: " + Formatter.formatShortFileSize(getActivity(), + (long)realUsedRam)); + Log.i(TAG, "Scaled Free RAM: " + Formatter.formatShortFileSize(getActivity(), + (long)realFreeRam)); + } + ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo(); + ((ActivityManager)getActivity().getSystemService(Context.ACTIVITY_SERVICE)).getMemoryInfo( + memInfo); + if (memInfo.hiddenAppThreshold >= realFreeRam) { + realUsedRam = realFreeRam; + realFreeRam = 0; + } else { + realUsedRam += memInfo.hiddenAppThreshold; + realFreeRam -= memInfo.hiddenAppThreshold; + } + if (DEBUG) { + Log.i(TAG, "Adj Scaled Used RAM: " + Formatter.formatShortFileSize(getActivity(), + (long)realUsedRam)); + Log.i(TAG, "Adj Scaled Free RAM: " + Formatter.formatShortFileSize(getActivity(), + (long)realFreeRam)); + } + + float usedRatio = (float)(realUsedRam/(realFreeRam+realUsedRam)); colors.setRatios(usedRatio, 0, 1-usedRatio); if (false) { @@ -653,13 +713,24 @@ public class ProcessStatsUi extends PreferenceFragment maxWeight = proc.mWeight; } } - mMaxWeight = maxWeight; + if (mStatsType == MENU_TYPE_BACKGROUND) { + mMaxWeight = (long)(mShowSystem ? persBackgroundWeight : backgroundWeight); + if (mMaxWeight < maxWeight) { + mMaxWeight = maxWeight; + } + if (DEBUG) { + Log.i(TAG, "Bar max RAM: " + Formatter.formatShortFileSize(getActivity(), + (mMaxWeight * 1024) / memTotalTime)); + } + } else { + mMaxWeight = maxWeight; + } if (DEBUG) Log.d(TAG, "-------------------- BUILDING UI"); for (int i=0, N=(entries != null ? entries.size() : 0); i