Various proc stats UI improvements.

- Option to include system processes.
- Option to use uss instead of pss sizes.
- Option to select type of stats: background processes, foreground (top)
  processes, cached processes.
- Details now shows max mem usage.

Change-Id: Ic994564ce846bc1021bf35576feeb9ef095b0e48
This commit is contained in:
Dianne Hackborn
2013-09-15 13:22:28 -07:00
parent b8e39041a5
commit 49759af6b0
7 changed files with 225 additions and 39 deletions

View File

@@ -3239,6 +3239,15 @@
<!-- Used to show an amount of time in the form "s seconds" in BatteryHistory -->
<string name="battery_history_seconds"><xliff:g id="seconds">%1$d</xliff:g>s</string>
<!-- Used to show an amount of time in the form "d days, h hours, m minutes, s seconds" in BatteryHistory -->
<string name="battery_history_days_no_seconds"><xliff:g id="days">%1$d</xliff:g>d <xliff:g id="hours">%2$d</xliff:g>h <xliff:g id="minutes">%3$d</xliff:g>m</string>
<!-- Used to show an amount of time in the form "h hours, m minutes, s seconds" in BatteryHistory -->
<string name="battery_history_hours_no_seconds"><xliff:g id="hours">%1$d</xliff:g>h <xliff:g id="minutes">%2$d</xliff:g>m</string>
<!-- Used to show an amount of time in the form "m minutes, s seconds" in BatteryHistory -->
<string name="battery_history_minutes_no_seconds"><xliff:g id="minutes">%1$d</xliff:g>m</string>
<!-- XXX remove? Strings used for displaying usage statistics -->
<string name="usage_stats_label">Usage statistics</string>
@@ -3619,16 +3628,38 @@
<!-- [CHAR LIMIT=NONE] Label for amount of memory use -->
<string name="app_memory_use">Memory use</string>
<!-- [CHAR LIMIT=NONE] Label for process stats, duration of time the stats are over -->
<string name="process_stats_total_duration">Stats over <xliff:g id="time">%1$s</xliff:g></string>
<string name="process_stats_total_duration"><xliff:g id="type">%1$s</xliff:g> apps over
<xliff:g id="time">%2$s</xliff:g></string>
<!-- [CHAR LIMIT=NONE] Label for process stats, text for stats type -->
<string name="process_stats_type_background">Background</string>
<!-- [CHAR LIMIT=NONE] Label for process stats, text for stats type -->
<string name="process_stats_type_foreground">Foreground</string>
<!-- [CHAR LIMIT=NONE] Label for process stats, text for stats type -->
<string name="process_stats_type_cached">Cached</string>
<!-- [CHAR LIMIT=NONE] Label for process stats, duration of time the stats are over -->
<string name="process_stats_memory_status">Device memory is currently
<xliff:g id="memstate">%1$s</xliff:g></string>
<!-- [CHAR LIMIT=NONE] Label for item showing details of average RAM use -->
<string name="process_stats_ram_use">Average RAM use</string>
<string name="process_stats_avg_ram_use">Average RAM use</string>
<!-- [CHAR LIMIT=NONE] Label for item showing details of maximum RAM use -->
<string name="process_stats_max_ram_use">Maximum RAM use</string>
<!-- [CHAR LIMIT=NONE] Label for item showing percent of time spent running -->
<string name="process_stats_run_time">Run time</string>
<!-- [CHAR LIMIT=NONE] Subtitle for process stats services list -->
<string name="services_subtitle">Services</string>
<!-- [CHAR LIMIT=NONE] Menu for process stats to control whether system processes are shown -->
<string name="menu_show_system">Show system</string>
<!-- [CHAR LIMIT=NONE] Menu for process stats to control whether computation should be based
on Uss (Unique Set Size) instead of Pss (Proportional Set Size) -->
<string name="menu_use_uss">Use Uss</string>
<!-- [CHAR LIMIT=NONE] Menu for process stats to select which type of stats to show -->
<string name="menu_proc_stats_type">Stats type</string>
<!-- [CHAR LIMIT=NONE] Menu for process stats to show information on background processes -->
<string name="menu_proc_stats_type_background">Background</string>
<!-- [CHAR LIMIT=NONE] Menu for process stats to show information on foreground processes -->
<string name="menu_proc_stats_type_foreground">Foreground</string>
<!-- [CHAR LIMIT=NONE] Menu for process stats to show information on cached processes -->
<string name="menu_proc_stats_type_cached">Cached</string>
<!-- Voice input/output settings --><skip />
<!-- Title of setting on main settings screen. This item will take the user to the screen to tweak settings related to speech functionality -->

View File

@@ -38,6 +38,9 @@ public final class ProcStatsEntry implements Parcelable {
final boolean mUnique;
final long mDuration;
final long mAvgPss;
final long mMaxPss;
final long mAvgUss;
final long mMaxUss;
final long mWeight;
String mBestTargetPackage;
@@ -50,7 +53,7 @@ public final class ProcStatsEntry implements Parcelable {
public String mUiPackage;
public ProcStatsEntry(ProcessStats.ProcessState proc,
ProcessStats.ProcessDataCollection tmpTotals) {
ProcessStats.ProcessDataCollection tmpTotals, boolean useUss, boolean weightWithTime) {
ProcessStats.computeProcessData(proc, tmpTotals, 0);
mPackage = proc.mPackage;
mUid = proc.mUid;
@@ -58,7 +61,10 @@ public final class ProcStatsEntry implements Parcelable {
mUnique = proc.mCommonProcess == proc;
mDuration = tmpTotals.totalTime;
mAvgPss = tmpTotals.avgPss;
mWeight = mDuration * mAvgPss;
mMaxPss = tmpTotals.maxPss;
mAvgUss = tmpTotals.avgUss;
mMaxUss = tmpTotals.maxUss;
mWeight = (weightWithTime ? mDuration : 1) * (useUss ? mAvgUss : mAvgPss);
}
public ProcStatsEntry(Parcel in) {
@@ -68,13 +74,16 @@ public final class ProcStatsEntry implements Parcelable {
mUnique = in.readInt() != 0;
mDuration = in.readLong();
mAvgPss = in.readLong();
mMaxPss = in.readLong();
mAvgUss = in.readLong();
mMaxUss = in.readLong();
mWeight = in.readLong();
mBestTargetPackage = in.readString();
in.readTypedList(mServices, Service.CREATOR);
}
public void evaluateTargetPackage(ProcessStats stats,
ProcessStats.ProcessDataCollection totals, Comparator<ProcStatsEntry> compare) {
public void evaluateTargetPackage(ProcessStats stats, ProcessStats.ProcessDataCollection totals,
Comparator<ProcStatsEntry> compare, boolean useUss, boolean weightWithTime) {
mBestTargetPackage = null;
if (mUnique) {
mBestTargetPackage = mPackage;
@@ -93,7 +102,8 @@ public final class ProcStatsEntry implements Parcelable {
ProcessStats.ProcessState subProc =
pkgState.mProcesses.valueAt(iproc);
if (subProc.mName.equals(mName)) {
subProcs.add(new ProcStatsEntry(subProc, totals));
subProcs.add(new ProcStatsEntry(subProc, totals, useUss,
weightWithTime));
}
}
}
@@ -184,6 +194,9 @@ public final class ProcStatsEntry implements Parcelable {
dest.writeInt(mUnique ? 1 : 0);
dest.writeLong(mDuration);
dest.writeLong(mAvgPss);
dest.writeLong(mMaxPss);
dest.writeLong(mAvgUss);
dest.writeLong(mMaxUss);
dest.writeLong(mWeight);
dest.writeString(mBestTargetPackage);
dest.writeTypedList(mServices);

View File

@@ -52,6 +52,7 @@ public class ProcessStatsDetail extends Fragment implements Button.OnClickListen
public static final int ACTION_FORCE_STOP = 1;
public static final String EXTRA_ENTRY = "entry";
public static final String EXTRA_USE_USS = "use_uss";
public static final String EXTRA_MAX_WEIGHT = "max_weight";
public static final String EXTRA_TOTAL_TIME = "total_time";
@@ -59,6 +60,7 @@ public class ProcessStatsDetail extends Fragment implements Button.OnClickListen
private DevicePolicyManager mDpm;
private ProcStatsEntry mEntry;
private boolean mUseUss;
private long mMaxWeight;
private long mTotalTime;
@@ -83,6 +85,7 @@ public class ProcessStatsDetail extends Fragment implements Button.OnClickListen
final Bundle args = getArguments();
mEntry = (ProcStatsEntry)args.getParcelable(EXTRA_ENTRY);
mEntry.retrieveUiData(mPm);
mUseUss = args.getBoolean(EXTRA_USE_USS);
mMaxWeight = args.getLong(EXTRA_MAX_WEIGHT);
mTotalTime = args.getLong(EXTRA_TOTAL_TIME);
}
@@ -177,8 +180,12 @@ public class ProcessStatsDetail extends Fragment implements Button.OnClickListen
}
private void fillDetailsSection() {
addDetailsItem(mDetailsParent, getResources().getText(R.string.process_stats_ram_use),
Formatter.formatShortFileSize(getActivity(), mEntry.mAvgPss * 1024));
addDetailsItem(mDetailsParent, getResources().getText(R.string.process_stats_avg_ram_use),
Formatter.formatShortFileSize(getActivity(),
(mUseUss ? mEntry.mAvgUss : mEntry.mAvgPss) * 1024));
addDetailsItem(mDetailsParent, getResources().getText(R.string.process_stats_max_ram_use),
Formatter.formatShortFileSize(getActivity(),
(mUseUss ? mEntry.mMaxUss : mEntry.mMaxPss) * 1024));
addDetailsItem(mDetailsParent, getResources().getText(R.string.process_stats_run_time),
makePercentString(getResources(), mEntry.mDuration, mTotalTime));
}

View File

@@ -37,6 +37,7 @@ import android.util.TimeUtils;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.SubMenu;
import com.android.internal.app.IProcessStats;
import com.android.internal.app.ProcessStats;
import com.android.settings.R;
@@ -56,9 +57,14 @@ public class ProcessStatsUi extends PreferenceFragment {
private static final String KEY_MEM_STATUS = "mem_status";
private static final int MENU_STATS_REFRESH = Menu.FIRST;
private static final int MENU_HELP = Menu.FIRST + 2;
private static final int MENU_SHOW_SYSTEM = Menu.FIRST + 1;
private static final int MENU_USE_USS = Menu.FIRST + 2;
private static final int MENU_TYPE_BACKGROUND = Menu.FIRST + 3;
private static final int MENU_TYPE_FOREGROUND = Menu.FIRST + 4;
private static final int MENU_TYPE_CACHED = Menu.FIRST + 5;
private static final int MENU_HELP = Menu.FIRST + 6;
static final int MAX_ITEMS_TO_LIST = 20;
static final int MAX_ITEMS_TO_LIST = 40;
final static Comparator<ProcStatsEntry> sEntryCompare = new Comparator<ProcStatsEntry>() {
@Override
@@ -79,6 +85,16 @@ public class ProcessStatsUi extends PreferenceFragment {
ProcessStats mStats;
int mMemState;
private boolean mShowSystem;
private boolean mUseUss;
private int mStatsType;
private MenuItem mShowSystemMenu;
private MenuItem mUseUssMenu;
private MenuItem mTypeBackgroundMenu;
private MenuItem mTypeForegroundMenu;
private MenuItem mTypeCachedMenu;
private PreferenceGroup mAppListGroup;
private Preference mMemStatusPref;
@@ -99,6 +115,10 @@ public class ProcessStatsUi extends PreferenceFragment {
mUm = (UserManager)getActivity().getSystemService(Context.USER_SERVICE);
mAppListGroup = (PreferenceGroup) findPreference(KEY_APP_LIST);
mMemStatusPref = mAppListGroup.findPreference(KEY_MEM_STATUS);
mShowSystem = icicle != null ? icicle.getBoolean("show_system") : false;
mUseUss = icicle != null ? icicle.getBoolean("use_uss") : false;
mStatsType = icicle != null ? icicle.getInt("stats_type", MENU_TYPE_BACKGROUND)
: MENU_TYPE_BACKGROUND;
setHasOptionsMenu(true);
}
@@ -113,6 +133,14 @@ public class ProcessStatsUi extends PreferenceFragment {
super.onPause();
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean("show_system", mShowSystem);
outState.putBoolean("use_uss", mUseUss);
outState.putInt("stats_type", mStatsType);
}
@Override
public void onDestroy() {
super.onDestroy();
@@ -130,6 +158,7 @@ public class ProcessStatsUi extends PreferenceFragment {
ProcessStatsPreference pgp = (ProcessStatsPreference) preference;
Bundle args = new Bundle();
args.putParcelable(ProcessStatsDetail.EXTRA_ENTRY, pgp.getEntry());
args.putBoolean(ProcessStatsDetail.EXTRA_USE_USS, mUseUss);
args.putLong(ProcessStatsDetail.EXTRA_MAX_WEIGHT, mMaxWeight);
args.putLong(ProcessStatsDetail.EXTRA_TOTAL_TIME, mTotalTime);
((PreferenceActivity) getActivity()).startPreferencePanel(
@@ -145,6 +174,31 @@ public class ProcessStatsUi extends PreferenceFragment {
.setAlphabeticShortcut('r');
refresh.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM |
MenuItem.SHOW_AS_ACTION_WITH_TEXT);
mShowSystemMenu = menu.add(0, MENU_SHOW_SYSTEM, 0, R.string.menu_show_system)
.setAlphabeticShortcut('s')
.setCheckable(true)
.setChecked(mShowSystem)
.setEnabled(mStatsType == MENU_TYPE_BACKGROUND);
mUseUssMenu = menu.add(0, MENU_USE_USS, 0, R.string.menu_use_uss)
.setAlphabeticShortcut('s')
.setCheckable(true)
.setChecked(mUseUss);
SubMenu subMenu = menu.addSubMenu(R.string.menu_proc_stats_type);
mTypeBackgroundMenu = subMenu.add(0, MENU_TYPE_BACKGROUND, 0,
R.string.menu_proc_stats_type_background)
.setAlphabeticShortcut('b')
.setCheckable(true)
.setChecked(mStatsType == MENU_TYPE_BACKGROUND);
mTypeForegroundMenu = subMenu.add(0, MENU_TYPE_FOREGROUND, 0,
R.string.menu_proc_stats_type_foreground)
.setAlphabeticShortcut('f')
.setCheckable(true)
.setChecked(mStatsType == MENU_TYPE_FOREGROUND);
mTypeCachedMenu = subMenu.add(0, MENU_TYPE_CACHED, 0,
R.string.menu_proc_stats_type_cached)
.setAlphabeticShortcut('c')
.setCheckable(true)
.setChecked(mStatsType == MENU_TYPE_CACHED);
/*
String helpUrl;
@@ -162,6 +216,20 @@ public class ProcessStatsUi extends PreferenceFragment {
mStats = null;
refreshStats();
return true;
case MENU_SHOW_SYSTEM:
mShowSystem = !mShowSystem;
refreshStats();
return true;
case MENU_USE_USS:
mUseUss = !mUseUss;
refreshStats();
return true;
case MENU_TYPE_BACKGROUND:
case MENU_TYPE_FOREGROUND:
case MENU_TYPE_CACHED:
mStatsType = item.getItemId();
refreshStats();
return true;
default:
return false;
}
@@ -173,18 +241,65 @@ public class ProcessStatsUi extends PreferenceFragment {
mAppListGroup.addPreference(notAvailable);
}
public static final int[] BACKGROUND_AND_SYSTEM_PROC_STATES = new int[] {
ProcessStats.STATE_PERSISTENT, ProcessStats.STATE_IMPORTANT_FOREGROUND,
ProcessStats.STATE_IMPORTANT_BACKGROUND, ProcessStats.STATE_BACKUP,
ProcessStats.STATE_HEAVY_WEIGHT, ProcessStats.STATE_SERVICE,
ProcessStats.STATE_SERVICE_RESTARTING, ProcessStats.STATE_RECEIVER
};
public static final int[] FOREGROUND_PROC_STATES = new int[] {
ProcessStats.STATE_TOP
};
public static final int[] CACHED_PROC_STATES = new int[] {
ProcessStats.STATE_CACHED_ACTIVITY, ProcessStats.STATE_CACHED_ACTIVITY_CLIENT,
ProcessStats.STATE_CACHED_EMPTY
};
private void refreshStats() {
if (mStats == null) {
load();
}
if (mShowSystemMenu != null) {
mShowSystemMenu.setChecked(mShowSystem);
mShowSystemMenu.setEnabled(mStatsType == MENU_TYPE_BACKGROUND);
}
if (mUseUssMenu != null) {
mUseUssMenu.setChecked(mUseUss);
}
if (mTypeBackgroundMenu != null) {
mTypeBackgroundMenu.setChecked(mStatsType == MENU_TYPE_BACKGROUND);
}
if (mTypeForegroundMenu != null) {
mTypeForegroundMenu.setChecked(mStatsType == MENU_TYPE_FOREGROUND);
}
if (mTypeCachedMenu != null) {
mTypeCachedMenu.setChecked(mStatsType == MENU_TYPE_CACHED);
}
int[] stats;
int statsLabel;
if (mStatsType == MENU_TYPE_FOREGROUND) {
stats = FOREGROUND_PROC_STATES;
statsLabel = R.string.process_stats_type_foreground;
} else if (mStatsType == MENU_TYPE_CACHED) {
stats = CACHED_PROC_STATES;
statsLabel = R.string.process_stats_type_cached;
} else {
stats = mShowSystem ? BACKGROUND_AND_SYSTEM_PROC_STATES
: ProcessStats.BACKGROUND_PROC_STATES;
statsLabel = R.string.process_stats_type_background;
}
mAppListGroup.removeAll();
mAppListGroup.setOrderingAsAdded(false);
mMemStatusPref.setOrder(-2);
mAppListGroup.addPreference(mMemStatusPref);
String durationString = Utils.formatElapsedTime(getActivity(),
mStats.mTimePeriodEndRealtime-mStats.mTimePeriodStartRealtime);
mStats.mTimePeriodEndRealtime-mStats.mTimePeriodStartRealtime, false);
CharSequence memString;
CharSequence[] memStates = getResources().getTextArray(R.array.ram_states);
if (mMemState >= 0 && mMemState < memStates.length) {
@@ -193,7 +308,7 @@ public class ProcessStatsUi extends PreferenceFragment {
memString = "?";
}
mMemStatusPref.setTitle(getActivity().getString(R.string.process_stats_total_duration,
durationString));
getActivity().getString(statsLabel), durationString));
mMemStatusPref.setSummary(getActivity().getString(R.string.process_stats_memory_status,
memString));
/*
@@ -208,8 +323,7 @@ public class ProcessStatsUi extends PreferenceFragment {
*/
ProcessStats.ProcessDataCollection totals = new ProcessStats.ProcessDataCollection(
ProcessStats.ALL_SCREEN_ADJ, ProcessStats.ALL_MEM_ADJ,
ProcessStats.BACKGROUND_PROC_STATES);
ProcessStats.ALL_SCREEN_ADJ, ProcessStats.ALL_MEM_ADJ, stats);
long now = SystemClock.uptimeMillis();
@@ -251,7 +365,8 @@ public class ProcessStatsUi extends PreferenceFragment {
for (int ip=0, N=mStats.mProcesses.getMap().size(); ip<N; ip++) {
SparseArray<ProcessStats.ProcessState> uids = mStats.mProcesses.getMap().valueAt(ip);
for (int iu=0; iu<uids.size(); iu++) {
ProcStatsEntry ent = new ProcStatsEntry(uids.valueAt(iu), totals);
ProcStatsEntry ent = new ProcStatsEntry(uids.valueAt(iu), totals, mUseUss,
mStatsType == MENU_TYPE_BACKGROUND);
procs.add(ent);
processes.put(ent.mName, ent);
}
@@ -275,9 +390,10 @@ public class ProcessStatsUi extends PreferenceFragment {
ProcStatsEntry proc = procs.get(i);
final double percentOfWeight = (((double)proc.mWeight) / maxWeight) * 100;
final double percentOfTime = (((double)proc.mDuration) / mTotalTime) * 100;
if (percentOfWeight < 1) continue;
if (percentOfWeight < 2) break;
ProcessStatsPreference pref = new ProcessStatsPreference(getActivity(), null, proc);
proc.evaluateTargetPackage(mStats, totals, sEntryCompare);
proc.evaluateTargetPackage(mStats, totals, sEntryCompare, mUseUss,
mStatsType == MENU_TYPE_BACKGROUND);
proc.retrieveUiData(pm);
pref.setTitle(proc.mUiLabel);
if (proc.mUiTargetApp != null) {
@@ -290,6 +406,7 @@ public class ProcessStatsUi extends PreferenceFragment {
}
// Add in service info.
if (mStatsType == MENU_TYPE_BACKGROUND) {
for (int ip=0, N=mStats.mPackages.getMap().size(); ip<N; ip++) {
SparseArray<ProcessStats.PackageState> uids = mStats.mPackages.getMap().valueAt(ip);
for (int iu=0; iu<uids.size(); iu++) {
@@ -304,6 +421,7 @@ public class ProcessStatsUi extends PreferenceFragment {
}
}
}
}
private void load() {
try {

View File

@@ -340,7 +340,7 @@ public class BatteryHistoryChart extends View {
long uSecTime = mStats.computeBatteryRealtime(SystemClock.elapsedRealtime() * 1000,
BatteryStats.STATS_SINCE_CHARGED);
mStatsPeriod = uSecTime;
String durationString = Utils.formatElapsedTime(getContext(), mStatsPeriod / 1000);
String durationString = Utils.formatElapsedTime(getContext(), mStatsPeriod / 1000, true);
mDurationString = getContext().getString(R.string.battery_stats_on_battery,
durationString);
mChargingLabel = getContext().getString(R.string.battery_stats_charging_label);
@@ -382,7 +382,7 @@ public class BatteryHistoryChart extends View {
mHavePhoneSignal = true;
}
if (mHistEnd <= mHistStart) mHistEnd = mHistStart+1;
mTotalDurationString = Utils.formatElapsedTime(getContext(), mHistEnd - mHistStart);
mTotalDurationString = Utils.formatElapsedTime(getContext(), mHistEnd - mHistStart, true);
}
@Override

View File

@@ -333,7 +333,7 @@ public class PowerUsageDetail extends Fragment implements Button.OnClickListener
mUsesGps = true;
// Fall through
default:
value = Utils.formatElapsedTime(getActivity(), mValues[i]);
value = Utils.formatElapsedTime(getActivity(), mValues[i], true);
}
ViewGroup item = (ViewGroup) inflater.inflate(R.layout.power_usage_detail_item_text,
null);

View File

@@ -35,9 +35,13 @@ public class Utils {
* @param millis the elapsed time in milli seconds
* @return the formatted elapsed time
*/
public static String formatElapsedTime(Context context, double millis) {
public static String formatElapsedTime(Context context, double millis, boolean inclSeconds) {
StringBuilder sb = new StringBuilder();
int seconds = (int) Math.floor(millis / 1000);
if (!inclSeconds) {
// Round up.
seconds += 30;
}
int days = 0, hours = 0, minutes = 0;
if (seconds > SECONDS_PER_DAY) {
@@ -52,16 +56,29 @@ public class Utils {
minutes = seconds / SECONDS_PER_MINUTE;
seconds -= minutes * SECONDS_PER_MINUTE;
}
if (inclSeconds) {
if (days > 0) {
sb.append(context.getString(R.string.battery_history_days,
days, hours, minutes, seconds));
} else if (hours > 0) {
sb.append(context.getString(R.string.battery_history_hours, hours, minutes, seconds));
sb.append(context.getString(R.string.battery_history_hours,
hours, minutes, seconds));
} else if (minutes > 0) {
sb.append(context.getString(R.string.battery_history_minutes, minutes, seconds));
} else {
sb.append(context.getString(R.string.battery_history_seconds, seconds));
}
} else {
if (days > 0) {
sb.append(context.getString(R.string.battery_history_days_no_seconds,
days, hours, minutes));
} else if (hours > 0) {
sb.append(context.getString(R.string.battery_history_hours_no_seconds,
hours, minutes));
} else {
sb.append(context.getString(R.string.battery_history_minutes_no_seconds, minutes));
}
}
return sb.toString();
}
}