Loading core/java/com/android/internal/os/BatteryStatsImpl.java +11 −4 Original line number Diff line number Diff line Loading @@ -6613,21 +6613,28 @@ public class BatteryStatsImpl extends BatteryStats { * the power consumption to the calling app. */ public void noteBinderCallStats(int workSourceUid, long incrementalCallCount, Collection<BinderCallsStats.CallStat> callStats, int[] binderThreadNativeTids) { noteBinderCallStats(workSourceUid, incrementalCallCount, callStats, binderThreadNativeTids, Collection<BinderCallsStats.CallStat> callStats) { noteBinderCallStats(workSourceUid, incrementalCallCount, callStats, mClocks.elapsedRealtime(), mClocks.uptimeMillis()); } public void noteBinderCallStats(int workSourceUid, long incrementalCallCount, Collection<BinderCallsStats.CallStat> callStats, int[] binderThreadNativeTids, Collection<BinderCallsStats.CallStat> callStats, long elapsedRealtimeMs, long uptimeMs) { synchronized (this) { getUidStatsLocked(workSourceUid, elapsedRealtimeMs, uptimeMs) .noteBinderCallStatsLocked(incrementalCallCount, callStats); mSystemServerCpuThreadReader.setBinderThreadNativeTids(binderThreadNativeTids); } } /** * Takes note of native IDs of threads taking incoming binder calls. The CPU time * of these threads is attributed to the apps making those binder calls. */ public void noteBinderThreadNativeIds(int[] binderThreadNativeTids) { mSystemServerCpuThreadReader.setBinderThreadNativeTids(binderThreadNativeTids); } /** * Estimates the proportion of system server CPU activity handling incoming binder calls * that can be attributed to each app Loading core/java/com/android/internal/os/BinderCallsStats.java +15 −4 Original line number Diff line number Diff line Loading @@ -119,8 +119,8 @@ public class BinderCallsStats implements BinderInternal.Observer { if (uidEntry != null) { ArrayMap<CallStatKey, CallStat> callStats = uidEntry.mCallStats; mCallStatsObserver.noteCallStats(uidEntry.workSourceUid, uidEntry.incrementalCallCount, callStats.values(), mNativeTids.toArray()); uidEntry.incrementalCallCount, callStats.values() ); uidEntry.incrementalCallCount = 0; for (int j = callStats.size() - 1; j >= 0; j--) { callStats.valueAt(j).incrementalCallCount = 0; Loading Loading @@ -168,6 +168,7 @@ public class BinderCallsStats implements BinderInternal.Observer { public void setCallStatsObserver( BinderInternal.CallStatsObserver callStatsObserver) { mCallStatsObserver = callStatsObserver; noteBinderThreadNativeIds(); noteCallsStatsDelayed(); } Loading @@ -182,13 +183,13 @@ public class BinderCallsStats implements BinderInternal.Observer { @Override @Nullable public CallSession callStarted(Binder binder, int code, int workSourceUid) { noteNativeThreadId(); if (!mRecordingAllTransactionsForUid && (mDeviceState == null || mDeviceState.isCharging())) { return null; } noteNativeThreadId(); final CallSession s = obtainCallSession(); s.binderClass = binder.getClass(); s.transactionCode = code; Loading Loading @@ -359,6 +360,16 @@ public class BinderCallsStats implements BinderInternal.Observer { mNativeTids = copyOnWriteArray; } } noteBinderThreadNativeIds(); } private void noteBinderThreadNativeIds() { if (mCallStatsObserver == null) { return; } mCallStatsObserver.noteBinderThreadNativeIds(getNativeTids()); } /** Loading core/java/com/android/internal/os/BinderInternal.java +6 −2 Original line number Diff line number Diff line Loading @@ -143,8 +143,12 @@ public class BinderInternal { * Notes incoming binder call stats associated with this work source UID. */ void noteCallStats(int workSourceUid, long incrementalCallCount, Collection<BinderCallsStats.CallStat> callStats, int[] binderThreadNativeTids); Collection<BinderCallsStats.CallStat> callStats); /** * Notes the native IDs of threads taking incoming binder calls. */ void noteBinderThreadNativeIds(int[] binderThreadNativeTids); } /** Loading core/java/com/android/internal/os/SystemServerCpuThreadReader.java +5 −13 Original line number Diff line number Diff line Loading @@ -31,7 +31,7 @@ import java.util.Arrays; */ public class SystemServerCpuThreadReader { private KernelCpuThreadReader mKernelCpuThreadReader; private int[] mBinderThreadNativeTids; private int[] mBinderThreadNativeTids = new int[0]; // Sorted private int[] mThreadCpuTimesUs; private int[] mBinderThreadCpuTimesUs; Loading Loading @@ -75,7 +75,8 @@ public class SystemServerCpuThreadReader { } public void setBinderThreadNativeTids(int[] nativeTids) { mBinderThreadNativeTids = nativeTids; mBinderThreadNativeTids = nativeTids.clone(); Arrays.sort(mBinderThreadNativeTids); } /** Loading Loading @@ -107,7 +108,8 @@ public class SystemServerCpuThreadReader { int threadCpuUsagesSize = threadCpuUsages.size(); for (int j = 0; j < threadCpuUsagesSize; j++) { KernelCpuThreadReader.ThreadCpuUsage tcu = threadCpuUsages.get(j); boolean isBinderThread = isBinderThread(tcu.threadId); boolean isBinderThread = Arrays.binarySearch(mBinderThreadNativeTids, tcu.threadId) >= 0; final int len = Math.min(tcu.usageTimesMillis.length, mThreadCpuTimesUs.length); for (int k = 0; k < len; k++) { Loading Loading @@ -138,14 +140,4 @@ public class SystemServerCpuThreadReader { return mDeltaCpuThreadTimes; } private boolean isBinderThread(int threadId) { if (mBinderThreadNativeTids != null) { for (int i = 0; i < mBinderThreadNativeTids.length; i++) { if (threadId == mBinderThreadNativeTids[i]) { return true; } } } return false; } } core/tests/coretests/src/com/android/internal/os/BatteryStatsBinderCallStatsTest.java +5 −5 Original line number Diff line number Diff line Loading @@ -60,7 +60,7 @@ public class BatteryStatsBinderCallStatsTest extends TestCase { stat1.cpuTimeMicros = 1000; callStats.add(stat1); bi.noteBinderCallStats(workSourceUid, 42, callStats, null); bi.noteBinderCallStats(workSourceUid, 42, callStats); callStats.clear(); BinderCallsStats.CallStat stat2 = new BinderCallsStats.CallStat(callingUid, Loading @@ -70,7 +70,7 @@ public class BatteryStatsBinderCallStatsTest extends TestCase { stat2.cpuTimeMicros = 500; callStats.add(stat2); bi.noteBinderCallStats(workSourceUid, 8, callStats, null); bi.noteBinderCallStats(workSourceUid, 8, callStats); BatteryStatsImpl.Uid uid = bi.getUidStatsLocked(workSourceUid); assertEquals(42 + 8, uid.getBinderCallCount()); Loading Loading @@ -112,7 +112,7 @@ public class BatteryStatsBinderCallStatsTest extends TestCase { stat1b.cpuTimeMicros = 1500; callStats.add(stat1b); bi.noteBinderCallStats(workSourceUid1, 65, callStats, null); bi.noteBinderCallStats(workSourceUid1, 65, callStats); // No recorded stats for some methods. Must use the global average. callStats.clear(); Loading @@ -121,11 +121,11 @@ public class BatteryStatsBinderCallStatsTest extends TestCase { stat2.incrementalCallCount = 10; callStats.add(stat2); bi.noteBinderCallStats(workSourceUid2, 40, callStats, null); bi.noteBinderCallStats(workSourceUid2, 40, callStats); // No stats for any calls. Must use the global average callStats.clear(); bi.noteBinderCallStats(workSourceUid3, 50, callStats, null); bi.noteBinderCallStats(workSourceUid3, 50, callStats); bi.updateSystemServiceCallStats(); Loading Loading
core/java/com/android/internal/os/BatteryStatsImpl.java +11 −4 Original line number Diff line number Diff line Loading @@ -6613,21 +6613,28 @@ public class BatteryStatsImpl extends BatteryStats { * the power consumption to the calling app. */ public void noteBinderCallStats(int workSourceUid, long incrementalCallCount, Collection<BinderCallsStats.CallStat> callStats, int[] binderThreadNativeTids) { noteBinderCallStats(workSourceUid, incrementalCallCount, callStats, binderThreadNativeTids, Collection<BinderCallsStats.CallStat> callStats) { noteBinderCallStats(workSourceUid, incrementalCallCount, callStats, mClocks.elapsedRealtime(), mClocks.uptimeMillis()); } public void noteBinderCallStats(int workSourceUid, long incrementalCallCount, Collection<BinderCallsStats.CallStat> callStats, int[] binderThreadNativeTids, Collection<BinderCallsStats.CallStat> callStats, long elapsedRealtimeMs, long uptimeMs) { synchronized (this) { getUidStatsLocked(workSourceUid, elapsedRealtimeMs, uptimeMs) .noteBinderCallStatsLocked(incrementalCallCount, callStats); mSystemServerCpuThreadReader.setBinderThreadNativeTids(binderThreadNativeTids); } } /** * Takes note of native IDs of threads taking incoming binder calls. The CPU time * of these threads is attributed to the apps making those binder calls. */ public void noteBinderThreadNativeIds(int[] binderThreadNativeTids) { mSystemServerCpuThreadReader.setBinderThreadNativeTids(binderThreadNativeTids); } /** * Estimates the proportion of system server CPU activity handling incoming binder calls * that can be attributed to each app Loading
core/java/com/android/internal/os/BinderCallsStats.java +15 −4 Original line number Diff line number Diff line Loading @@ -119,8 +119,8 @@ public class BinderCallsStats implements BinderInternal.Observer { if (uidEntry != null) { ArrayMap<CallStatKey, CallStat> callStats = uidEntry.mCallStats; mCallStatsObserver.noteCallStats(uidEntry.workSourceUid, uidEntry.incrementalCallCount, callStats.values(), mNativeTids.toArray()); uidEntry.incrementalCallCount, callStats.values() ); uidEntry.incrementalCallCount = 0; for (int j = callStats.size() - 1; j >= 0; j--) { callStats.valueAt(j).incrementalCallCount = 0; Loading Loading @@ -168,6 +168,7 @@ public class BinderCallsStats implements BinderInternal.Observer { public void setCallStatsObserver( BinderInternal.CallStatsObserver callStatsObserver) { mCallStatsObserver = callStatsObserver; noteBinderThreadNativeIds(); noteCallsStatsDelayed(); } Loading @@ -182,13 +183,13 @@ public class BinderCallsStats implements BinderInternal.Observer { @Override @Nullable public CallSession callStarted(Binder binder, int code, int workSourceUid) { noteNativeThreadId(); if (!mRecordingAllTransactionsForUid && (mDeviceState == null || mDeviceState.isCharging())) { return null; } noteNativeThreadId(); final CallSession s = obtainCallSession(); s.binderClass = binder.getClass(); s.transactionCode = code; Loading Loading @@ -359,6 +360,16 @@ public class BinderCallsStats implements BinderInternal.Observer { mNativeTids = copyOnWriteArray; } } noteBinderThreadNativeIds(); } private void noteBinderThreadNativeIds() { if (mCallStatsObserver == null) { return; } mCallStatsObserver.noteBinderThreadNativeIds(getNativeTids()); } /** Loading
core/java/com/android/internal/os/BinderInternal.java +6 −2 Original line number Diff line number Diff line Loading @@ -143,8 +143,12 @@ public class BinderInternal { * Notes incoming binder call stats associated with this work source UID. */ void noteCallStats(int workSourceUid, long incrementalCallCount, Collection<BinderCallsStats.CallStat> callStats, int[] binderThreadNativeTids); Collection<BinderCallsStats.CallStat> callStats); /** * Notes the native IDs of threads taking incoming binder calls. */ void noteBinderThreadNativeIds(int[] binderThreadNativeTids); } /** Loading
core/java/com/android/internal/os/SystemServerCpuThreadReader.java +5 −13 Original line number Diff line number Diff line Loading @@ -31,7 +31,7 @@ import java.util.Arrays; */ public class SystemServerCpuThreadReader { private KernelCpuThreadReader mKernelCpuThreadReader; private int[] mBinderThreadNativeTids; private int[] mBinderThreadNativeTids = new int[0]; // Sorted private int[] mThreadCpuTimesUs; private int[] mBinderThreadCpuTimesUs; Loading Loading @@ -75,7 +75,8 @@ public class SystemServerCpuThreadReader { } public void setBinderThreadNativeTids(int[] nativeTids) { mBinderThreadNativeTids = nativeTids; mBinderThreadNativeTids = nativeTids.clone(); Arrays.sort(mBinderThreadNativeTids); } /** Loading Loading @@ -107,7 +108,8 @@ public class SystemServerCpuThreadReader { int threadCpuUsagesSize = threadCpuUsages.size(); for (int j = 0; j < threadCpuUsagesSize; j++) { KernelCpuThreadReader.ThreadCpuUsage tcu = threadCpuUsages.get(j); boolean isBinderThread = isBinderThread(tcu.threadId); boolean isBinderThread = Arrays.binarySearch(mBinderThreadNativeTids, tcu.threadId) >= 0; final int len = Math.min(tcu.usageTimesMillis.length, mThreadCpuTimesUs.length); for (int k = 0; k < len; k++) { Loading Loading @@ -138,14 +140,4 @@ public class SystemServerCpuThreadReader { return mDeltaCpuThreadTimes; } private boolean isBinderThread(int threadId) { if (mBinderThreadNativeTids != null) { for (int i = 0; i < mBinderThreadNativeTids.length; i++) { if (threadId == mBinderThreadNativeTids[i]) { return true; } } } return false; } }
core/tests/coretests/src/com/android/internal/os/BatteryStatsBinderCallStatsTest.java +5 −5 Original line number Diff line number Diff line Loading @@ -60,7 +60,7 @@ public class BatteryStatsBinderCallStatsTest extends TestCase { stat1.cpuTimeMicros = 1000; callStats.add(stat1); bi.noteBinderCallStats(workSourceUid, 42, callStats, null); bi.noteBinderCallStats(workSourceUid, 42, callStats); callStats.clear(); BinderCallsStats.CallStat stat2 = new BinderCallsStats.CallStat(callingUid, Loading @@ -70,7 +70,7 @@ public class BatteryStatsBinderCallStatsTest extends TestCase { stat2.cpuTimeMicros = 500; callStats.add(stat2); bi.noteBinderCallStats(workSourceUid, 8, callStats, null); bi.noteBinderCallStats(workSourceUid, 8, callStats); BatteryStatsImpl.Uid uid = bi.getUidStatsLocked(workSourceUid); assertEquals(42 + 8, uid.getBinderCallCount()); Loading Loading @@ -112,7 +112,7 @@ public class BatteryStatsBinderCallStatsTest extends TestCase { stat1b.cpuTimeMicros = 1500; callStats.add(stat1b); bi.noteBinderCallStats(workSourceUid1, 65, callStats, null); bi.noteBinderCallStats(workSourceUid1, 65, callStats); // No recorded stats for some methods. Must use the global average. callStats.clear(); Loading @@ -121,11 +121,11 @@ public class BatteryStatsBinderCallStatsTest extends TestCase { stat2.incrementalCallCount = 10; callStats.add(stat2); bi.noteBinderCallStats(workSourceUid2, 40, callStats, null); bi.noteBinderCallStats(workSourceUid2, 40, callStats); // No stats for any calls. Must use the global average callStats.clear(); bi.noteBinderCallStats(workSourceUid3, 50, callStats, null); bi.noteBinderCallStats(workSourceUid3, 50, callStats); bi.updateSystemServiceCallStats(); Loading