From 68f005fbd48f18cdab0168ba92b8fd40776edc1e Mon Sep 17 00:00:00 2001 From: Dianne Hackborn Date: Wed, 18 Jun 2014 18:29:12 -0700 Subject: [PATCH] Modify proc stats to show new memory use computation. Switch the proc status UI's memory use bar to be based on the new total memory use computation, instead of showing that weird "time spent in memory states" thing. Also now have it link to a detail page that shows details of time spent in memory states and RAM used by various things. Change-Id: I6817a499db518adb8e72466a5e9cfe18a81be5d5 --- res/layout/preference_linearcolor.xml | 1 - res/layout/process_stats_mem_details.xml | 63 ++++++++ res/values/arrays.xml | 26 +++ res/values/strings.xml | 18 +++ src/com/android/settings/Utils.java | 9 ++ .../applications/LinearColorPreference.java | 12 +- .../applications/ProcessStatsMemDetail.java | 152 ++++++++++++++++++ .../settings/applications/ProcessStatsUi.java | 117 ++++++++++++-- .../fuelgauge/BatteryHistoryChart.java | 5 +- 9 files changed, 382 insertions(+), 21 deletions(-) create mode 100644 res/layout/process_stats_mem_details.xml create mode 100644 src/com/android/settings/applications/ProcessStatsMemDetail.java diff --git a/res/layout/preference_linearcolor.xml b/res/layout/preference_linearcolor.xml index 0df866db0db..f3abb9ccb38 100644 --- a/res/layout/preference_linearcolor.xml +++ b/res/layout/preference_linearcolor.xml @@ -19,7 +19,6 @@ android:layout_height="?android:attr/listPreferredItemHeight" android:paddingStart="?android:attr/listPreferredItemPaddingStart" android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"> - + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/res/values/arrays.xml b/res/values/arrays.xml index 5df457b3181..c73300965ce 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -1256,4 +1256,30 @@ 15 20 + + + + Normal + Moderate + Low + Critical + + + + + Persistent + Top activity + Important (foreground) + Important (background) + Backup + Heavy weight + Service (running) + Service (restarting) + Receiver + Home + Last activity + Cached (activity) + Cached (activity client) + Cached (empty) + diff --git a/res/values/strings.xml b/res/values/strings.xml index 2df7903fc55..7afc8c3b946 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -3803,6 +3803,24 @@ Services Duration + + Memory details + + Memory states + + Memory use + + Kernel + + Native + + Kernel caches + + ZRam swap + + Free + + Total 3 hours diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java index 78d40982ecf..5f904424196 100644 --- a/src/com/android/settings/Utils.java +++ b/src/com/android/settings/Utils.java @@ -78,6 +78,15 @@ public final class Utils { */ public static final float DISABLED_ALPHA = 0.4f; + /** + * Color spectrum to use to indicate badness. 0 is completely transparent (no data), + * 1 is most bad (red), the last value is least bad (green). + */ + public static final int[] BADNESS_COLORS = new int[] { + 0x00000000, 0xffc43828, 0xffe54918, 0xfff47b00, + 0xfffabf2c, 0xff679e37, 0xff0a7f42 + }; + /** * Name of the meta-data item that should be set in the AndroidManifest.xml * to specify the icon that should be displayed for the preference. diff --git a/src/com/android/settings/applications/LinearColorPreference.java b/src/com/android/settings/applications/LinearColorPreference.java index 8d9fb724252..b5f707e54d2 100644 --- a/src/com/android/settings/applications/LinearColorPreference.java +++ b/src/com/android/settings/applications/LinearColorPreference.java @@ -25,6 +25,9 @@ public class LinearColorPreference extends Preference { float mRedRatio; float mYellowRatio; float mGreenRatio; + int mRedColor = 0xffaa5030; + int mYellowColor = 0xffaaaa30; + int mGreenColor = 0xff30aa50; int mColoredRegions = LinearColorBar.REGION_ALL; LinearColorBar.OnRegionTappedListener mOnRegionTappedListener; @@ -40,6 +43,13 @@ public class LinearColorPreference extends Preference { notifyChanged(); } + public void setColors(int red, int yellow, int green) { + mRedColor = red; + mYellowColor = yellow; + mGreenColor = green; + notifyChanged(); + } + public void setOnRegionTappedListener(LinearColorBar.OnRegionTappedListener listener) { mOnRegionTappedListener = listener; notifyChanged(); @@ -57,7 +67,7 @@ public class LinearColorPreference extends Preference { LinearColorBar colors = (LinearColorBar)view.findViewById( R.id.linear_color_bar); colors.setShowIndicator(false); - colors.setColors(0xffaa5030, 0xffaaaa30, 0xff30aa50); + colors.setColors(mRedColor, mYellowColor, mGreenColor); colors.setRatios(mRedRatio, mYellowRatio, mGreenRatio); colors.setColoredRegions(mColoredRegions); colors.setOnRegionTappedListener(mOnRegionTappedListener); diff --git a/src/com/android/settings/applications/ProcessStatsMemDetail.java b/src/com/android/settings/applications/ProcessStatsMemDetail.java new file mode 100644 index 00000000000..65e94f7a79b --- /dev/null +++ b/src/com/android/settings/applications/ProcessStatsMemDetail.java @@ -0,0 +1,152 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.applications; + +import android.app.Fragment; +import android.os.Bundle; +import android.text.format.Formatter; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ProgressBar; +import android.widget.TextView; +import com.android.internal.app.ProcessStats; +import com.android.settings.R; + +import static com.android.settings.Utils.prepareCustomPreferencesList; + +public class ProcessStatsMemDetail extends Fragment { + public static final String EXTRA_MEM_TIMES = "mem_times"; + public static final String EXTRA_MEM_STATE_WEIGHTS = "mem_state_weights"; + public static final String EXTRA_MEM_CACHED_WEIGHT = "mem_cached_weight"; + public static final String EXTRA_MEM_FREE_WEIGHT = "mem_free_weight"; + public static final String EXTRA_MEM_ZRAM_WEIGHT = "mem_zram_weight"; + public static final String EXTRA_MEM_KERNEL_WEIGHT = "mem_kernel_weight"; + public static final String EXTRA_MEM_NATIVE_WEIGHT = "mem_native_weight"; + public static final String EXTRA_MEM_TOTAL_WEIGHT = "mem_total_weight"; + public static final String EXTRA_USE_USS = "use_uss"; + public static final String EXTRA_TOTAL_TIME = "total_time"; + + long[] mMemTimes; + double[] mMemStateWeights; + double mMemCachedWeight; + double mMemFreeWeight; + double mMemZRamWeight; + double mMemKernelWeight; + double mMemNativeWeight; + double mMemTotalWeight; + boolean mUseUss; + long mTotalTime; + + private View mRootView; + private ViewGroup mMemStateParent; + private ViewGroup mMemUseParent; + + @Override + public void onCreate(Bundle icicle) { + super.onCreate(icicle); + final Bundle args = getArguments(); + mMemTimes = args.getLongArray(EXTRA_MEM_TIMES); + mMemStateWeights = args.getDoubleArray(EXTRA_MEM_STATE_WEIGHTS); + mMemCachedWeight = args.getDouble(EXTRA_MEM_CACHED_WEIGHT); + mMemFreeWeight = args.getDouble(EXTRA_MEM_FREE_WEIGHT); + mMemZRamWeight = args.getDouble(EXTRA_MEM_ZRAM_WEIGHT); + mMemKernelWeight = args.getDouble(EXTRA_MEM_KERNEL_WEIGHT); + mMemNativeWeight = args.getDouble(EXTRA_MEM_NATIVE_WEIGHT); + mMemTotalWeight = args.getDouble(EXTRA_MEM_TOTAL_WEIGHT); + mUseUss = args.getBoolean(EXTRA_USE_USS); + mTotalTime = args.getLong(EXTRA_TOTAL_TIME); + } + + @Override + public View onCreateView( + LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + final View view = inflater.inflate(R.layout.process_stats_mem_details, container, false); + prepareCustomPreferencesList(container, view, view, false); + + mRootView = view; + createDetails(); + return view; + } + + @Override + public void onPause() { + super.onPause(); + } + + private void createDetails() { + mMemStateParent = (ViewGroup)mRootView.findViewById(R.id.mem_state); + mMemUseParent = (ViewGroup)mRootView.findViewById(R.id.mem_use); + + fillMemStateSection(); + fillMemUseSection(); + } + + private void addDetailsItem(ViewGroup parent, CharSequence title, + float level, CharSequence value) { + LayoutInflater inflater = getActivity().getLayoutInflater(); + ViewGroup item = (ViewGroup) inflater.inflate(R.layout.app_percentage_item, + null); + parent.addView(item); + item.findViewById(android.R.id.icon).setVisibility(View.GONE); + TextView titleView = (TextView) item.findViewById(android.R.id.title); + TextView valueView = (TextView) item.findViewById(android.R.id.text1); + titleView.setText(title); + valueView.setText(value); + ProgressBar progress = (ProgressBar) item.findViewById(android.R.id.progress); + progress.setProgress(Math.round(level*100)); + } + + private void fillMemStateSection() { + CharSequence[] labels = getResources().getTextArray(R.array.proc_stats_memory_states); + for (int i=0; i 0) { + float level = ((float)mMemTimes[i])/mTotalTime; + addDetailsItem(mMemStateParent, labels[i], level, + Formatter.formatShortElapsedTime(getActivity(), mMemTimes[i])); + } + } + } + + private void addMemUseDetailsItem(ViewGroup parent, CharSequence title, double weight) { + if (weight > 0) { + float level = (float)(weight/mMemTotalWeight); + String value = Formatter.formatShortFileSize(getActivity(), + (long)((weight * 1024) / mTotalTime)); + addDetailsItem(parent, title, level, value); + } + } + + private void fillMemUseSection() { + 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_native_type), mMemNativeWeight); + for (int i=0; i= ProcessStats.STATE_HOME) { + freeWeight += totalMem.processStateWeight[i]; + } else { + usedWeight += totalMem.processStateWeight[i]; + } + } + } + mMemTotalWeight = freeWeight + usedWeight; + float usedRatio = (float)(usedWeight/(freeWeight+usedWeight)); + colors.setRatios(usedRatio, 0, 1-usedRatio); + + if (false) { + colors.setOnRegionTappedListener(this); + switch (mMemRegion) { + case LinearColorBar.REGION_RED: + colors.setColoredRegions(LinearColorBar.REGION_RED); + memTotalTime = mMemTimes[ProcessStats.ADJ_MEM_FACTOR_CRITICAL]; + memStates = RED_MEM_STATES; + break; + case LinearColorBar.REGION_YELLOW: + colors.setColoredRegions(LinearColorBar.REGION_RED + | LinearColorBar.REGION_YELLOW); + memTotalTime = mMemTimes[ProcessStats.ADJ_MEM_FACTOR_CRITICAL] + + mMemTimes[ProcessStats.ADJ_MEM_FACTOR_LOW] + + mMemTimes[ProcessStats.ADJ_MEM_FACTOR_MODERATE]; + memStates = YELLOW_MEM_STATES; + break; + default: + colors.setColoredRegions(LinearColorBar.REGION_ALL); + memTotalTime = mTotalTime; + memStates = ProcessStats.ALL_MEM_ADJ; + break; + } + colors.setRatios(mMemTimes[ProcessStats.ADJ_MEM_FACTOR_CRITICAL] / (float)mTotalTime, + (mMemTimes[ProcessStats.ADJ_MEM_FACTOR_LOW] + + mMemTimes[ProcessStats.ADJ_MEM_FACTOR_MODERATE]) / (float)mTotalTime, + mMemTimes[ProcessStats.ADJ_MEM_FACTOR_NORMAL] / (float)mTotalTime); + } + mAppListGroup.addPreference(colors); ProcessStats.ProcessDataCollection totals = new ProcessStats.ProcessDataCollection( diff --git a/src/com/android/settings/fuelgauge/BatteryHistoryChart.java b/src/com/android/settings/fuelgauge/BatteryHistoryChart.java index 85047ceb9cf..b030884886c 100644 --- a/src/com/android/settings/fuelgauge/BatteryHistoryChart.java +++ b/src/com/android/settings/fuelgauge/BatteryHistoryChart.java @@ -362,10 +362,7 @@ public class BatteryHistoryChart extends View { mGpsOnPaint.setStyle(Paint.Style.STROKE); mWifiRunningPaint.setStyle(Paint.Style.STROKE); mCpuRunningPaint.setStyle(Paint.Style.STROKE); - mPhoneSignalChart.setColors(new int[] { - 0x00000000, 0xffc43828, 0xffe54918, 0xfff47b00, - 0xfffabf2c, 0xff679e37, 0xff0a7f42 - }); + mPhoneSignalChart.setColors(com.android.settings.Utils.BADNESS_COLORS); mDebugRectPaint.setARGB(255, 255, 0, 0); mDebugRectPaint.setStyle(Paint.Style.STROKE); mScreenOnPaint.setColor(0xFF009688);