summaryrefslogtreecommitdiffstats
path: root/core/java
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2013-08-05 18:18:42 -0700
committerDianne Hackborn <hackbod@google.com>2013-08-06 13:54:07 -0700
commitd2932243e3313b59e7538641731aa98852bc5ac7 (patch)
treed2ccb55820c8c47c535f7b973087cd3446f308b6 /core/java
parent03901667db75696ccd544809e0e7bc000a99f417 (diff)
downloadframeworks_base-d2932243e3313b59e7538641731aa98852bc5ac7.zip
frameworks_base-d2932243e3313b59e7538641731aa98852bc5ac7.tar.gz
frameworks_base-d2932243e3313b59e7538641731aa98852bc5ac7.tar.bz2
Refactor ProcessStats, ProcessTracker.
ProcessStats is now called ProcessCpuTracker. ProcessTracker is now ProcessStatsService, and its inner State class is broken out into a separate top-level ProcessStats class. This ProcessStats is moved to the framework, so we will be able to use it elsewhere. Change-Id: I6a127bcb835b6b474b72647c0b99b82c2137e5c5
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/os/Binder.java17
-rw-r--r--core/java/com/android/internal/os/ProcessCpuTracker.java (renamed from core/java/com/android/internal/os/ProcessStats.java)78
2 files changed, 54 insertions, 41 deletions
diff --git a/core/java/android/os/Binder.java b/core/java/android/os/Binder.java
index 7b91418..4627c88 100644
--- a/core/java/android/os/Binder.java
+++ b/core/java/android/os/Binder.java
@@ -296,7 +296,21 @@ public class Binder implements IBinder {
disabled = sDumpDisabled;
}
if (disabled == null) {
- dump(fd, pw, args);
+ try {
+ dump(fd, pw, args);
+ } catch (SecurityException e) {
+ pw.println();
+ pw.println("Security exception: " + e.getMessage());
+ throw e;
+ } catch (Throwable e) {
+ // Unlike usual calls, in this case if an exception gets thrown
+ // back to us we want to print it back in to the dump data, since
+ // that is where the caller expects all interesting information to
+ // go.
+ pw.println();
+ pw.println("Exception occurred while dumping:");
+ e.printStackTrace(pw);
+ }
} else {
pw.println(sDumpDisabled);
}
@@ -443,7 +457,6 @@ final class BinderProxy implements IBinder {
data.writeStringArray(args);
try {
transact(DUMP_TRANSACTION, data, reply, FLAG_ONEWAY);
- reply.readException();
} finally {
data.recycle();
reply.recycle();
diff --git a/core/java/com/android/internal/os/ProcessStats.java b/core/java/com/android/internal/os/ProcessCpuTracker.java
index 874bc0e..c092807 100644
--- a/core/java/com/android/internal/os/ProcessStats.java
+++ b/core/java/com/android/internal/os/ProcessCpuTracker.java
@@ -34,11 +34,11 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.StringTokenizer;
-public class ProcessStats {
+public class ProcessCpuTracker {
private static final String TAG = "ProcessStats";
private static final boolean DEBUG = false;
private static final boolean localLOGV = DEBUG || false;
-
+
private static final int[] PROCESS_STATS_FORMAT = new int[] {
PROC_SPACE_TERM,
PROC_SPACE_TERM|PROC_PARENS,
@@ -61,7 +61,7 @@ public class ProcessStats {
static final int PROCESS_STAT_MAJOR_FAULTS = 1;
static final int PROCESS_STAT_UTIME = 2;
static final int PROCESS_STAT_STIME = 3;
-
+
/** Stores user time and system time in 100ths of a second. */
private final long[] mProcessStatsData = new long[4];
/** Stores user time and system time in 100ths of a second. */
@@ -123,14 +123,14 @@ public class ProcessStats {
private final float[] mLoadAverageData = new float[3];
private final boolean mIncludeThreads;
-
+
private float mLoad1 = 0;
private float mLoad5 = 0;
private float mLoad15 = 0;
-
+
private long mCurrentSampleTime;
private long mLastSampleTime;
-
+
private long mCurrentSampleRealTime;
private long mLastSampleRealTime;
@@ -149,7 +149,7 @@ public class ProcessStats {
private int[] mCurPids;
private int[] mCurThreadPids;
-
+
private final ArrayList<Stats> mProcStats = new ArrayList<Stats>();
private final ArrayList<Stats> mWorkingProcs = new ArrayList<Stats>();
private boolean mWorkingProcsSorted;
@@ -202,12 +202,12 @@ public class ProcessStats {
public long base_majfaults;
public int rel_minfaults;
public int rel_majfaults;
-
+
public boolean active;
public boolean working;
public boolean added;
public boolean removed;
-
+
Stats(int _pid, int parentPid, boolean includeThreads) {
pid = _pid;
if (parentPid < 0) {
@@ -256,30 +256,30 @@ public class ProcessStats {
};
- public ProcessStats(boolean includeThreads) {
+ public ProcessCpuTracker(boolean includeThreads) {
mIncludeThreads = includeThreads;
}
-
+
public void onLoadChanged(float load1, float load5, float load15) {
}
-
+
public int onMeasureProcessName(String name) {
return 0;
}
-
+
public void init() {
if (DEBUG) Slog.v(TAG, "Init: " + this);
mFirst = true;
update();
}
-
+
public void update() {
if (DEBUG) Slog.v(TAG, "Update: " + this);
mLastSampleTime = mCurrentSampleTime;
mCurrentSampleTime = SystemClock.uptimeMillis();
mLastSampleRealTime = mCurrentSampleRealTime;
mCurrentSampleRealTime = SystemClock.elapsedRealtime();
-
+
final long[] sysCpu = mSystemCpuData;
if (Process.readProcFile("/proc/stat", SYSTEM_CPU_FORMAT,
null, sysCpu, null)) {
@@ -339,11 +339,11 @@ public class ProcessStats {
mWorkingProcsSorted = false;
mFirst = false;
- }
-
+ }
+
private int[] collectStats(String statsFile, int parentPid, boolean first,
int[] curPids, ArrayList<Stats> allProcs) {
-
+
int[] pids = Process.getPids(statsFile, curPids);
int NP = (pids == null) ? 0 : pids.length;
int NS = allProcs.size();
@@ -355,7 +355,7 @@ public class ProcessStats {
break;
}
Stats st = curStatsIndex < NS ? allProcs.get(curStatsIndex) : null;
-
+
if (st != null && st.pid == pid) {
// Update an existing process...
st.added = false;
@@ -373,7 +373,7 @@ public class ProcessStats {
PROCESS_STATS_FORMAT, null, procStats, null)) {
continue;
}
-
+
final long minfaults = procStats[PROCESS_STAT_MINOR_FAULTS];
final long majfaults = procStats[PROCESS_STAT_MAJOR_FAULTS];
final long utime = procStats[PROCESS_STAT_UTIME];
@@ -423,7 +423,7 @@ public class ProcessStats {
continue;
}
-
+
if (st == null || st.pid > pid) {
// We have a new process!
st = new Stats(pid, parentPid, mIncludeThreads);
@@ -477,7 +477,7 @@ public class ProcessStats {
if (DEBUG) Slog.v("Load", "Stats added " + st.name + " pid=" + st.pid
+ " utime=" + st.base_utime + " stime=" + st.base_stime
+ " minfaults=" + st.base_minfaults + " majfaults=" + st.base_majfaults);
-
+
st.rel_utime = 0;
st.rel_stime = 0;
st.rel_minfaults = 0;
@@ -488,7 +488,7 @@ public class ProcessStats {
}
continue;
}
-
+
// This process has gone away!
st.rel_utime = 0;
st.rel_stime = 0;
@@ -520,7 +520,7 @@ public class ProcessStats {
NS--;
if (localLOGV) Slog.v(TAG, "Removed pid " + st.pid + ": " + st);
}
-
+
return pids;
}
@@ -607,27 +607,27 @@ public class ProcessStats {
final public int getLastUserTime() {
return mRelUserTime;
}
-
+
final public int getLastSystemTime() {
return mRelSystemTime;
}
-
+
final public int getLastIoWaitTime() {
return mRelIoWaitTime;
}
-
+
final public int getLastIrqTime() {
return mRelIrqTime;
}
-
+
final public int getLastSoftIrqTime() {
return mRelSoftIrqTime;
}
-
+
final public int getLastIdleTime() {
return mRelIdleTime;
}
-
+
final public float getTotalCpuPercent() {
int denom = mRelUserTime+mRelSystemTime+mRelIrqTime+mRelIdleTime;
if (denom <= 0) {
@@ -635,7 +635,7 @@ public class ProcessStats {
}
return ((float)(mRelUserTime+mRelSystemTime+mRelIrqTime)*100) / denom;
}
-
+
final void buildWorkingProcs() {
if (!mWorkingProcsSorted) {
mWorkingProcs.clear();
@@ -678,7 +678,7 @@ public class ProcessStats {
final public Stats getWorkingStats(int index) {
return mWorkingProcs.get(index);
}
-
+
final public String printCurrentLoad() {
StringWriter sw = new StringWriter();
PrintWriter pw = new FastPrintWriter(sw, false, 128);
@@ -694,10 +694,10 @@ public class ProcessStats {
final public String printCurrentState(long now) {
buildWorkingProcs();
-
+
StringWriter sw = new StringWriter();
PrintWriter pw = new FastPrintWriter(sw, false, 1024);
-
+
pw.print("CPU usage from ");
if (now > mLastSampleTime) {
pw.print(now-mLastSampleTime);
@@ -720,10 +720,10 @@ public class ProcessStats {
pw.print("% awake");
}
pw.println(":");
-
+
final int totalTime = mRelUserTime + mRelSystemTime + mRelIoWaitTime
+ mRelIrqTime + mRelSoftIrqTime + mRelIdleTime;
-
+
if (DEBUG) Slog.i(TAG, "totalTime " + totalTime + " over sample time "
+ (mCurrentSampleTime-mLastSampleTime));
@@ -744,14 +744,14 @@ public class ProcessStats {
}
}
}
-
+
printProcessCPU(pw, "", -1, "TOTAL", totalTime, mRelUserTime, mRelSystemTime,
mRelIoWaitTime, mRelIrqTime, mRelSoftIrqTime, 0, 0);
pw.flush();
return sw.toString();
}
-
+
private void printRatio(PrintWriter pw, long numerator, long denominator) {
long thousands = (numerator*1000)/denominator;
long hundreds = thousands/10;
@@ -812,7 +812,7 @@ public class ProcessStats {
}
pw.println();
}
-
+
private String readFile(String file, char endChar) {
// Permit disk reads here, as /proc/meminfo isn't really "on
// disk" and should be fast. TODO: make BlockGuard ignore