Loading core/java/com/android/internal/os/BinderCallsStats.java +25 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.internal.os; import android.annotation.NonNull; import android.annotation.Nullable; import android.os.Binder; import android.os.Process; import android.os.SystemClock; import android.os.UserHandle; import android.text.format.DateFormat; Loading Loading @@ -78,6 +79,7 @@ public class BinderCallsStats implements BinderInternal.Observer { private final Random mRandom; private long mStartTime = System.currentTimeMillis(); private long mCallStatsCount = 0; private boolean mAddDebugEntries = false; private CachedDeviceState.Readonly mDeviceState; Loading Loading @@ -317,9 +319,28 @@ public class BinderCallsStats implements BinderInternal.Observer { exported.methodName = methodName; } // Debug entries added to help validate the data. if (mAddDebugEntries) { resultCallStats.add(createDebugEntry("start_time_millis", mStartTime)); resultCallStats.add(createDebugEntry("end_time_millis", System.currentTimeMillis())); } return resultCallStats; } private ExportedCallStat createDebugEntry(String variableName, long value) { final int uid = Process.myUid(); final ExportedCallStat callStat = new ExportedCallStat(); callStat.className = ""; callStat.workSourceUid = uid; callStat.callingUid = uid; callStat.recordedCallCount = 1; callStat.callCount = 1; callStat.methodName = "__DEBUG_" + variableName; callStat.maxReplySizeBytes = value; return callStat; } /** @hide */ public ArrayMap<String, Integer> getExportedExceptionStats() { synchronized (mLock) { Loading Loading @@ -457,6 +478,10 @@ public class BinderCallsStats implements BinderInternal.Observer { } } public void setAddDebugEntries(boolean addDebugEntries) { mAddDebugEntries = addDebugEntries; } /** * Sets the maximum number of items to track. */ Loading core/tests/coretests/src/com/android/internal/os/BinderCallsStatsTest.java +19 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.internal.os; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import android.os.Binder; import android.platform.test.annotations.Presubmit; Loading Loading @@ -613,6 +614,23 @@ public class BinderCallsStatsTest { assertEquals(CALLING_UID, callStats.callingUid); } @Test public void testAddsDebugEntries() { long startTime = System.currentTimeMillis(); TestBinderCallsStats bcs = new TestBinderCallsStats(); bcs.setAddDebugEntries(true); ArrayList<BinderCallsStats.ExportedCallStat> callStats = bcs.getExportedCallStats(); assertEquals(2, callStats.size()); BinderCallsStats.ExportedCallStat debugEntry1 = callStats.get(0); assertEquals("", debugEntry1.className); assertEquals("__DEBUG_start_time_millis", debugEntry1.methodName); assertTrue(startTime <= debugEntry1.maxReplySizeBytes); BinderCallsStats.ExportedCallStat debugEntry2 = callStats.get(1); assertEquals("", debugEntry2.className); assertEquals("__DEBUG_end_time_millis", debugEntry2.methodName); assertTrue(debugEntry1.maxReplySizeBytes <= debugEntry2.maxReplySizeBytes); } class TestBinderCallsStats extends BinderCallsStats { public int callingUid = CALLING_UID; public int workSourceUid = WORKSOURCE_UID; Loading @@ -634,6 +652,7 @@ public class BinderCallsStatsTest { }); setSamplingInterval(1); setDeviceState(mDeviceState.getReadonlyClient()); setAddDebugEntries(false); } @Override Loading services/core/java/com/android/server/BinderCallsStatsService.java +1 −0 Original line number Diff line number Diff line Loading @@ -116,6 +116,7 @@ public class BinderCallsStatsService extends Binder { } mEnabled = enabled; mBinderCallsStats.reset(); mBinderCallsStats.setAddDebugEntries(enabled); } } } Loading Loading
core/java/com/android/internal/os/BinderCallsStats.java +25 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.internal.os; import android.annotation.NonNull; import android.annotation.Nullable; import android.os.Binder; import android.os.Process; import android.os.SystemClock; import android.os.UserHandle; import android.text.format.DateFormat; Loading Loading @@ -78,6 +79,7 @@ public class BinderCallsStats implements BinderInternal.Observer { private final Random mRandom; private long mStartTime = System.currentTimeMillis(); private long mCallStatsCount = 0; private boolean mAddDebugEntries = false; private CachedDeviceState.Readonly mDeviceState; Loading Loading @@ -317,9 +319,28 @@ public class BinderCallsStats implements BinderInternal.Observer { exported.methodName = methodName; } // Debug entries added to help validate the data. if (mAddDebugEntries) { resultCallStats.add(createDebugEntry("start_time_millis", mStartTime)); resultCallStats.add(createDebugEntry("end_time_millis", System.currentTimeMillis())); } return resultCallStats; } private ExportedCallStat createDebugEntry(String variableName, long value) { final int uid = Process.myUid(); final ExportedCallStat callStat = new ExportedCallStat(); callStat.className = ""; callStat.workSourceUid = uid; callStat.callingUid = uid; callStat.recordedCallCount = 1; callStat.callCount = 1; callStat.methodName = "__DEBUG_" + variableName; callStat.maxReplySizeBytes = value; return callStat; } /** @hide */ public ArrayMap<String, Integer> getExportedExceptionStats() { synchronized (mLock) { Loading Loading @@ -457,6 +478,10 @@ public class BinderCallsStats implements BinderInternal.Observer { } } public void setAddDebugEntries(boolean addDebugEntries) { mAddDebugEntries = addDebugEntries; } /** * Sets the maximum number of items to track. */ Loading
core/tests/coretests/src/com/android/internal/os/BinderCallsStatsTest.java +19 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.internal.os; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import android.os.Binder; import android.platform.test.annotations.Presubmit; Loading Loading @@ -613,6 +614,23 @@ public class BinderCallsStatsTest { assertEquals(CALLING_UID, callStats.callingUid); } @Test public void testAddsDebugEntries() { long startTime = System.currentTimeMillis(); TestBinderCallsStats bcs = new TestBinderCallsStats(); bcs.setAddDebugEntries(true); ArrayList<BinderCallsStats.ExportedCallStat> callStats = bcs.getExportedCallStats(); assertEquals(2, callStats.size()); BinderCallsStats.ExportedCallStat debugEntry1 = callStats.get(0); assertEquals("", debugEntry1.className); assertEquals("__DEBUG_start_time_millis", debugEntry1.methodName); assertTrue(startTime <= debugEntry1.maxReplySizeBytes); BinderCallsStats.ExportedCallStat debugEntry2 = callStats.get(1); assertEquals("", debugEntry2.className); assertEquals("__DEBUG_end_time_millis", debugEntry2.methodName); assertTrue(debugEntry1.maxReplySizeBytes <= debugEntry2.maxReplySizeBytes); } class TestBinderCallsStats extends BinderCallsStats { public int callingUid = CALLING_UID; public int workSourceUid = WORKSOURCE_UID; Loading @@ -634,6 +652,7 @@ public class BinderCallsStatsTest { }); setSamplingInterval(1); setDeviceState(mDeviceState.getReadonlyClient()); setAddDebugEntries(false); } @Override Loading
services/core/java/com/android/server/BinderCallsStatsService.java +1 −0 Original line number Diff line number Diff line Loading @@ -116,6 +116,7 @@ public class BinderCallsStatsService extends Binder { } mEnabled = enabled; mBinderCallsStats.reset(); mBinderCallsStats.setAddDebugEntries(enabled); } } } Loading