Consistently use weight to get average mem usage
Rather than just for the labels... Also update bg mem to be converted to the same memory scale for the bars. Also undo some bad average calculations that only made things worse. Bug: 20694769 Change-Id: I676803bf76d336355441891e768ba3c228dbfbca
This commit is contained in:
@@ -90,10 +90,10 @@ public class ProcStatsPackageEntry implements Parcelable {
|
||||
for (int i=0; i < N; i++) {
|
||||
ProcStatsEntry entry = mEntries.get(i);
|
||||
mBgDuration += entry.mBgDuration;
|
||||
mAvgBgMem += entry.mAvgBgMem * entry.mBgDuration;
|
||||
mAvgBgMem += entry.mAvgBgMem;
|
||||
mBgWeight += entry.mBgWeight;
|
||||
mRunDuration += entry.mRunDuration;
|
||||
mAvgRunMem += entry.mAvgRunMem * entry.mRunDuration;
|
||||
mAvgRunMem += entry.mAvgRunMem;
|
||||
mRunWeight += entry.mRunWeight;
|
||||
|
||||
// Each entry is generally a process or something similar. Since it is extremely
|
||||
@@ -103,12 +103,8 @@ public class ProcStatsPackageEntry implements Parcelable {
|
||||
mMaxBgMem += entry.mMaxBgMem;
|
||||
mMaxRunMem += entry.mMaxRunMem;
|
||||
}
|
||||
if (mBgDuration != 0) {
|
||||
mAvgBgMem = mAvgBgMem * N / mBgDuration;
|
||||
}
|
||||
if (mRunDuration != 0) {
|
||||
mAvgRunMem = mAvgRunMem * N / mRunDuration;
|
||||
}
|
||||
mAvgBgMem /= N;
|
||||
mAvgRunMem /= N;
|
||||
}
|
||||
|
||||
public void retrieveUiData(Context context, PackageManager pm) {
|
||||
|
@@ -86,7 +86,7 @@ public class ProcessStatsDetail extends SettingsPreferenceFragment
|
||||
|
||||
private LinearColorBar mColorBar;
|
||||
|
||||
private float mMaxMemoryUsage;
|
||||
private double mMaxMemoryUsage;
|
||||
|
||||
private double mTotalScale;
|
||||
|
||||
@@ -101,7 +101,7 @@ public class ProcessStatsDetail extends SettingsPreferenceFragment
|
||||
mUseUss = args.getBoolean(EXTRA_USE_USS);
|
||||
mWeightToRam = args.getDouble(EXTRA_WEIGHT_TO_RAM);
|
||||
mTotalTime = args.getLong(EXTRA_TOTAL_TIME);
|
||||
mMaxMemoryUsage = args.getFloat(EXTRA_MAX_MEMORY_USAGE);
|
||||
mMaxMemoryUsage = args.getDouble(EXTRA_MAX_MEMORY_USAGE);
|
||||
mTotalScale = args.getDouble(EXTRA_TOTAL_SCALE);
|
||||
mOnePercentTime = mTotalTime/100;
|
||||
|
||||
@@ -199,16 +199,17 @@ public class ProcessStatsDetail extends SettingsPreferenceFragment
|
||||
|
||||
// TODO: Find way to share this code with ProcessStatsPreference.
|
||||
boolean statsForeground = mApp.mRunWeight > mApp.mBgWeight;
|
||||
float mAvgRatio = (statsForeground ? mApp.mAvgRunMem : mApp.mAvgBgMem) / mMaxMemoryUsage;
|
||||
float mMaxRatio = (statsForeground ? mApp.mMaxRunMem : mApp.mMaxBgMem) / mMaxMemoryUsage
|
||||
- mAvgRatio;
|
||||
float mRemainingRatio = 1 - mAvgRatio - mMaxRatio;
|
||||
float avgRatio = (float) ((statsForeground ? mApp.mRunWeight : mApp.mBgWeight)
|
||||
* mWeightToRam / mMaxMemoryUsage);
|
||||
float maxRatio = (float) ((statsForeground ? mApp.mMaxRunMem : mApp.mMaxBgMem)
|
||||
* mTotalScale * 1024 / mMaxMemoryUsage - avgRatio);
|
||||
float remainingRatio = 1 - avgRatio - maxRatio;
|
||||
mColorBar = (LinearColorBar) headerLayout.findViewById(R.id.color_bar);
|
||||
Context context = getActivity();
|
||||
mColorBar.setColors(context.getColor(R.color.memory_avg_use),
|
||||
context.getColor(R.color.memory_max_use),
|
||||
context.getColor(R.color.memory_remaining));
|
||||
mColorBar.setRatios(mAvgRatio, mMaxRatio, mRemainingRatio);
|
||||
mColorBar.setRatios(avgRatio, maxRatio, remainingRatio);
|
||||
}
|
||||
|
||||
public void onClick(View v) {
|
||||
|
@@ -58,7 +58,8 @@ public class ProcessStatsPreference extends Preference {
|
||||
mRemainingColor = context.getColor(R.color.memory_remaining);
|
||||
}
|
||||
|
||||
public void init(ProcStatsPackageEntry entry, PackageManager pm, float maxMemory) {
|
||||
public void init(ProcStatsPackageEntry entry, PackageManager pm, double maxMemory,
|
||||
double weightToRam, double totalScale) {
|
||||
mEntry = entry;
|
||||
setTitle(TextUtils.isEmpty(entry.mUiLabel) ? entry.mPackage : entry.mUiLabel);
|
||||
if (entry.mUiTargetApp != null) {
|
||||
@@ -69,8 +70,10 @@ public class ProcessStatsPreference extends Preference {
|
||||
boolean statsForeground = entry.mRunWeight > entry.mBgWeight;
|
||||
setSummary(entry.mRunDuration > entry.mBgDuration ? entry.getRunningFrequency(getContext())
|
||||
: entry.getBackgroundFrequency(getContext()));
|
||||
mAvgRatio = (statsForeground ? entry.mAvgRunMem : entry.mAvgBgMem) / maxMemory;
|
||||
mMaxRatio = (statsForeground ? entry.mMaxRunMem : entry.mMaxBgMem) / maxMemory - mAvgRatio;
|
||||
mAvgRatio = (float) ((statsForeground ? entry.mRunWeight : entry.mBgWeight)
|
||||
* weightToRam / maxMemory);
|
||||
mMaxRatio = (float) ((statsForeground ? entry.mMaxRunMem : entry.mMaxBgMem)
|
||||
* totalScale * 1024 / maxMemory - mAvgRatio);
|
||||
mRemainingRatio = 1 - mAvgRatio - mMaxRatio;
|
||||
}
|
||||
|
||||
|
@@ -74,17 +74,13 @@ public class ProcessStatsUi extends InstrumentedPreferenceFragment {
|
||||
= new Comparator<ProcStatsPackageEntry>() {
|
||||
@Override
|
||||
public int compare(ProcStatsPackageEntry lhs, ProcStatsPackageEntry rhs) {
|
||||
if (lhs.mRunWeight < rhs.mRunWeight) {
|
||||
return 1;
|
||||
} else if (lhs.mRunWeight > rhs.mRunWeight) {
|
||||
return -1;
|
||||
} else if (lhs.mRunDuration < rhs.mRunDuration) {
|
||||
return 1;
|
||||
} else if (lhs.mRunDuration > rhs.mRunDuration) {
|
||||
return -1;
|
||||
}
|
||||
double rhsWeight = Math.max(rhs.mRunWeight, rhs.mBgWeight);
|
||||
double lhsWeight = Math.max(lhs.mRunWeight, lhs.mBgWeight);
|
||||
if (lhsWeight == rhsWeight) {
|
||||
return 0;
|
||||
}
|
||||
return lhsWeight < rhsWeight ? 1 : -1;
|
||||
}
|
||||
};
|
||||
|
||||
private boolean mShowPercentage;
|
||||
@@ -128,7 +124,7 @@ public class ProcessStatsUi extends InstrumentedPreferenceFragment {
|
||||
};
|
||||
|
||||
private ProcStatsData mStatsManager;
|
||||
private float mMaxMemoryUsage;
|
||||
private double mMaxMemoryUsage;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
@@ -200,7 +196,7 @@ public class ProcessStatsUi extends InstrumentedPreferenceFragment {
|
||||
args.putDouble(ProcessStatsDetail.EXTRA_WEIGHT_TO_RAM,
|
||||
mStatsManager.getMemInfo().weightToRam);
|
||||
args.putLong(ProcessStatsDetail.EXTRA_TOTAL_TIME, memTotalTime);
|
||||
args.putFloat(ProcessStatsDetail.EXTRA_MAX_MEMORY_USAGE, mMaxMemoryUsage);
|
||||
args.putDouble(ProcessStatsDetail.EXTRA_MAX_MEMORY_USAGE, mMaxMemoryUsage);
|
||||
args.putDouble(ProcessStatsDetail.EXTRA_TOTAL_SCALE, mStatsManager.getMemInfo().totalScale);
|
||||
((SettingsActivity) getActivity()).startPreferencePanel(
|
||||
ProcessStatsDetail.class.getName(), args, R.string.details_title, null, null, 0);
|
||||
@@ -422,7 +418,7 @@ public class ProcessStatsUi extends InstrumentedPreferenceFragment {
|
||||
for (int i=0, N=pkgEntries.size(); i<N; i++) {
|
||||
ProcStatsPackageEntry pkg = pkgEntries.get(i);
|
||||
pkg.updateMetrics();
|
||||
float maxMem = Math.max(pkg.mMaxBgMem, pkg.mMaxRunMem);
|
||||
double maxMem = Math.max(pkg.mMaxBgMem, pkg.mMaxRunMem) * 1024 * memInfo.totalScale;
|
||||
if (maxMem > mMaxMemoryUsage) {
|
||||
mMaxMemoryUsage = maxMem;
|
||||
}
|
||||
@@ -452,7 +448,7 @@ public class ProcessStatsUi extends InstrumentedPreferenceFragment {
|
||||
ProcStatsPackageEntry pkg = pkgEntries.get(i);
|
||||
ProcessStatsPreference pref = new ProcessStatsPreference(context);
|
||||
pkg.retrieveUiData(context, mPm);
|
||||
pref.init(pkg, mPm, mMaxMemoryUsage);
|
||||
pref.init(pkg, mPm, mMaxMemoryUsage, memInfo.weightToRam, memInfo.totalScale);
|
||||
pref.setOrder(i);
|
||||
mAppListGroup.addPreference(pref);
|
||||
if (mAppListGroup.getPreferenceCount() > (MAX_ITEMS_TO_LIST+1)) {
|
||||
|
Reference in New Issue
Block a user