diff options
4 files changed, 45 insertions, 14 deletions
diff --git a/apct-tests/perftests/core/src/android/os/BinderCallsStatsPerfTest.java b/apct-tests/perftests/core/src/android/os/BinderCallsStatsPerfTest.java index ba072da8071e..e4a850335aad 100644 --- a/apct-tests/perftests/core/src/android/os/BinderCallsStatsPerfTest.java +++ b/apct-tests/perftests/core/src/android/os/BinderCallsStatsPerfTest.java @@ -59,7 +59,7 @@ public class BinderCallsStatsPerfTest { int i = 0; while (state.keepRunning()) { BinderCallsStats.CallSession s = mBinderCallsStats.callStarted(b, i % 100); - mBinderCallsStats.callEnded(s); + mBinderCallsStats.callEnded(s, 0, 0); i++; } } @@ -71,7 +71,7 @@ public class BinderCallsStatsPerfTest { mBinderCallsStats = new BinderCallsStats(false); while (state.keepRunning()) { BinderCallsStats.CallSession s = mBinderCallsStats.callStarted(b, 0); - mBinderCallsStats.callEnded(s); + mBinderCallsStats.callEnded(s, 0, 0); } } diff --git a/core/java/android/os/Binder.java b/core/java/android/os/Binder.java index 7e7d6170feca..1e6f1acb55a8 100644 --- a/core/java/android/os/Binder.java +++ b/core/java/android/os/Binder.java @@ -760,6 +760,8 @@ public class Binder implements IBinder { } } checkParcel(this, code, reply, "Unreasonably large binder reply buffer"); + int replySizeBytes = reply.dataSize(); + int requestSizeBytes = data.dataSize(); reply.recycle(); data.recycle(); @@ -769,7 +771,7 @@ public class Binder implements IBinder { // to the main transaction loop to wait for another incoming transaction. Either // way, strict mode begone! StrictMode.clearGatheredViolations(); - binderCallsStats.callEnded(callSession); + binderCallsStats.callEnded(callSession, requestSizeBytes, replySizeBytes); return res; } diff --git a/core/java/com/android/internal/os/BinderCallsStats.java b/core/java/com/android/internal/os/BinderCallsStats.java index ec89d8127e5a..fbb99e423cd6 100644 --- a/core/java/com/android/internal/os/BinderCallsStats.java +++ b/core/java/com/android/internal/os/BinderCallsStats.java @@ -92,7 +92,7 @@ public class BinderCallsStats { return s; } - public void callEnded(CallSession s) { + public void callEnded(CallSession s, int parcelRequestSize, int parcelReplySize) { Preconditions.checkNotNull(s); synchronized (mLock) { long duration; @@ -110,7 +110,7 @@ public class BinderCallsStats { // callCount is always incremented, but time only once per sampling interval long samplesCount = cs.callCount / PERIODIC_SAMPLING_INTERVAL + 1; duration = cs.cpuTimeMicros / samplesCount; - latencyDuration = cs.latencyMicros/ samplesCount; + latencyDuration = cs.latencyMicros / samplesCount; } } @@ -129,6 +129,11 @@ public class BinderCallsStats { callStat.cpuTimeMicros += duration; callStat.latencyMicros += latencyDuration; callStat.exceptionCount += s.exceptionThrown ? 1 : 0; + callStat.maxLatencyMicros = Math.max(callStat.maxLatencyMicros, latencyDuration); + callStat.maxRequestSizeBytes = + Math.max(callStat.maxRequestSizeBytes, parcelRequestSize); + callStat.maxReplySizeBytes = + Math.max(callStat.maxReplySizeBytes, parcelReplySize); } else { // update sampled timings in the beginning of each interval if (s.cpuTimeStarted >= 0) { @@ -184,8 +189,9 @@ public class BinderCallsStats { StringBuilder sb = new StringBuilder(); if (mDetailedTracking) { pw.println("Per-UID raw data " + datasetSizeDesc - + "(uid, call_desc, cpu_time_micros, latency_time_micros, exception_count, " - + "call_count):"); + + "(uid, call_desc, cpu_time_micros, latency_time_micros, " + + "max_latency_time_micros, exception_count, max_request_size_bytes, " + + "max_reply_size_bytes, call_count):"); List<UidEntry> topEntries = verbose ? entries : getHighestValues(entries, value -> value.cpuTimeMicros, 0.9); for (UidEntry uidEntry : topEntries) { @@ -195,7 +201,10 @@ public class BinderCallsStats { .append(uidEntry.uid).append(",").append(e) .append(',').append(e.cpuTimeMicros) .append(',').append(e.latencyMicros) + .append(',').append(e.maxLatencyMicros) .append(',').append(e.exceptionCount) + .append(',').append(e.maxRequestSizeBytes) + .append(',').append(e.maxReplySizeBytes) .append(',').append(e.callCount); pw.println(sb); } @@ -280,6 +289,9 @@ public class BinderCallsStats { public int msg; public long cpuTimeMicros; public long latencyMicros; + public long maxLatencyMicros; + public long maxRequestSizeBytes; + public long maxReplySizeBytes; public long callCount; public long exceptionCount; diff --git a/core/tests/coretests/src/com/android/internal/os/BinderCallsStatsTest.java b/core/tests/coretests/src/com/android/internal/os/BinderCallsStatsTest.java index ba61137ff013..b7fef13d5e9d 100644 --- a/core/tests/coretests/src/com/android/internal/os/BinderCallsStatsTest.java +++ b/core/tests/coretests/src/com/android/internal/os/BinderCallsStatsTest.java @@ -35,7 +35,9 @@ import static org.junit.Assert.assertEquals; @RunWith(AndroidJUnit4.class) @Presubmit public class BinderCallsStatsTest { - public static final int TEST_UID = 1; + private static final int TEST_UID = 1; + private static final int REQUEST_SIZE = 2; + private static final int REPLY_SIZE = 3; @Test public void testDetailedOff() { @@ -43,7 +45,7 @@ public class BinderCallsStatsTest { Binder binder = new Binder(); BinderCallsStats.CallSession callSession = bcs.callStarted(binder, 1); bcs.time += 10; - bcs.callEnded(callSession); + bcs.callEnded(callSession, REQUEST_SIZE, REPLY_SIZE); SparseArray<BinderCallsStats.UidEntry> uidEntries = bcs.getUidEntries(); assertEquals(1, uidEntries.size()); @@ -66,7 +68,7 @@ public class BinderCallsStatsTest { callSession = bcs.callStarted(binder, 1); bcs.time += 20; - bcs.callEnded(callSession); + bcs.callEnded(callSession, REQUEST_SIZE, REPLY_SIZE); uidEntry = bcs.getUidEntries().get(TEST_UID); assertEquals(2, uidEntry.callCount); @@ -79,7 +81,7 @@ public class BinderCallsStatsTest { callSession = bcs.callStarted(binder, 2); bcs.time += 50; - bcs.callEnded(callSession); + bcs.callEnded(callSession, REQUEST_SIZE, REPLY_SIZE); uidEntry = bcs.getUidEntries().get(TEST_UID); assertEquals(3, uidEntry.callCount); @@ -95,7 +97,7 @@ public class BinderCallsStatsTest { Binder binder = new Binder(); BinderCallsStats.CallSession callSession = bcs.callStarted(binder, 1); bcs.time += 10; - bcs.callEnded(callSession); + bcs.callEnded(callSession, REQUEST_SIZE, REPLY_SIZE); SparseArray<BinderCallsStats.UidEntry> uidEntries = bcs.getUidEntries(); assertEquals(1, uidEntries.size()); @@ -117,7 +119,7 @@ public class BinderCallsStatsTest { callSession = bcs.callStarted(binder, 1); bcs.time += 20; - bcs.callEnded(callSession); + bcs.callEnded(callSession, REQUEST_SIZE, REPLY_SIZE); uidEntry = bcs.getUidEntries().get(TEST_UID); assertEquals(2, uidEntry.callCount); @@ -127,7 +129,7 @@ public class BinderCallsStatsTest { callSession = bcs.callStarted(binder, 2); bcs.time += 50; - bcs.callEnded(callSession); + bcs.callEnded(callSession, REQUEST_SIZE, REPLY_SIZE); uidEntry = bcs.getUidEntries().get(TEST_UID); assertEquals(3, uidEntry.callCount); @@ -138,6 +140,21 @@ public class BinderCallsStatsTest { } @Test + public void testParcelSize() { + TestBinderCallsStats bcs = new TestBinderCallsStats(true); + Binder binder = new Binder(); + BinderCallsStats.CallSession callSession = bcs.callStarted(binder, 1); + bcs.time += 10; + bcs.callEnded(callSession, REQUEST_SIZE, REPLY_SIZE); + + List<BinderCallsStats.CallStat> callStatsList = + bcs.getUidEntries().get(TEST_UID).getCallStatsList(); + + assertEquals(REQUEST_SIZE, callStatsList.get(0).maxRequestSizeBytes); + assertEquals(REPLY_SIZE, callStatsList.get(0).maxReplySizeBytes); + } + + @Test public void testGetHighestValues() { List<Integer> list = Arrays.asList(1, 2, 3, 4); List<Integer> highestValues = BinderCallsStats |