BinderCallsStats - add debug entries to output
Test: UT and manually verified that debug entries are included in adb shell dumpsys binder_stats Change-Id: If6a64f7ac14d12323d0cb855b7603eb259e19630
This commit is contained in:
@@ -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;
|
||||
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -634,6 +652,7 @@ public class BinderCallsStatsTest {
|
||||
});
|
||||
setSamplingInterval(1);
|
||||
setDeviceState(mDeviceState.getReadonlyClient());
|
||||
setAddDebugEntries(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -116,6 +116,7 @@ public class BinderCallsStatsService extends Binder {
|
||||
}
|
||||
mEnabled = enabled;
|
||||
mBinderCallsStats.reset();
|
||||
mBinderCallsStats.setAddDebugEntries(enabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user