diff options
| author | 2018-11-23 14:11:40 +0000 | |
|---|---|---|
| committer | 2018-11-23 14:11:40 +0000 | |
| commit | 8e90ada67e4b160a9983be1733c5be7e1cfd98e7 (patch) | |
| tree | eff597350a9914acebd15a894bfd970211acd73b | |
| parent | 0961c3e61f4fdd50dadca9d8674e58aaddad9559 (diff) | |
| parent | d32a5135419a9911dbef1b05e7b85ef8f0c9a334 (diff) | |
Merge "LooperStats - add debug entries to output for data validation"
3 files changed, 42 insertions, 1 deletions
diff --git a/core/java/com/android/internal/os/LooperStats.java b/core/java/com/android/internal/os/LooperStats.java index 2b661c25194b..cf2a297bb6a5 100644 --- a/core/java/com/android/internal/os/LooperStats.java +++ b/core/java/com/android/internal/os/LooperStats.java @@ -50,6 +50,7 @@ public class LooperStats implements Looper.Observer { private int mSamplingInterval; private CachedDeviceState.Readonly mDeviceState; private long mStartTime = System.currentTimeMillis(); + private boolean mAddDebugEntries = false; public LooperStats(int samplingInterval, int entriesSizeCap) { this.mSamplingInterval = samplingInterval; @@ -60,6 +61,10 @@ public class LooperStats implements Looper.Observer { mDeviceState = deviceState; } + public void setAddDebugEntries(boolean addDebugEntries) { + mAddDebugEntries = addDebugEntries; + } + @Override public Object messageDispatchStarting() { if (deviceStateAllowsCollection() && shouldCollectDetailedData()) { @@ -142,9 +147,22 @@ public class LooperStats implements Looper.Observer { // Add the overflow and collision entries only if they have any data. maybeAddSpecialEntry(exportedEntries, mOverflowEntry); maybeAddSpecialEntry(exportedEntries, mHashCollisionEntry); + // Debug entries added to help validate the data. + if (mAddDebugEntries) { + exportedEntries.add(createDebugEntry("start_time_millis", mStartTime)); + exportedEntries.add(createDebugEntry("end_time_millis", System.currentTimeMillis())); + } return exportedEntries; } + private ExportedEntry createDebugEntry(String variableName, long value) { + final Entry entry = new Entry("__DEBUG_" + variableName); + entry.messageCount = 1; + entry.recordedMessageCount = 1; + entry.maxDelayMillis = value; + return new ExportedEntry(entry); + } + /** Returns a timestamp indicating when the statistics were last reset. */ public long getStartTimeMillis() { return mStartTime; diff --git a/core/tests/coretests/src/com/android/internal/os/LooperStatsTest.java b/core/tests/coretests/src/com/android/internal/os/LooperStatsTest.java index f637b7c7ec32..31dde5c79f27 100644 --- a/core/tests/coretests/src/com/android/internal/os/LooperStatsTest.java +++ b/core/tests/coretests/src/com/android/internal/os/LooperStatsTest.java @@ -105,7 +105,6 @@ public final class LooperStatsTest { assertThat(entry.recordedDelayMessageCount).isEqualTo(1); assertThat(entry.delayMillis).isEqualTo(30); assertThat(entry.maxDelayMillis).isEqualTo(30); - } @Test @@ -429,6 +428,28 @@ public final class LooperStatsTest { assertThat(entries).hasSize(0); } + @Test + public void testAddsDebugEntries() { + TestableLooperStats looperStats = new TestableLooperStats(1, 100); + looperStats.setAddDebugEntries(true); + + Message message = mHandlerFirst.obtainMessage(1000); + message.when = looperStats.getSystemUptimeMillis(); + Object token = looperStats.messageDispatchStarting(); + looperStats.messageDispatched(token, message); + + List<LooperStats.ExportedEntry> entries = looperStats.getEntries(); + assertThat(entries).hasSize(3); + LooperStats.ExportedEntry debugEntry1 = entries.get(1); + assertThat(debugEntry1.handlerClassName).isEqualTo(""); + assertThat(debugEntry1.messageName).isEqualTo("__DEBUG_start_time_millis"); + assertThat(debugEntry1.maxDelayMillis).isEqualTo(looperStats.getStartTimeMillis()); + LooperStats.ExportedEntry debugEntry2 = entries.get(2); + assertThat(debugEntry2.handlerClassName).isEqualTo(""); + assertThat(debugEntry2.messageName).isEqualTo("__DEBUG_end_time_millis"); + assertThat(debugEntry2.maxDelayMillis).isAtLeast(looperStats.getStartTimeMillis()); + } + private static void assertThrows(Class<? extends Exception> exceptionClass, Runnable r) { try { r.run(); @@ -450,6 +471,7 @@ public final class LooperStatsTest { super(samplingInterval, sizeCap); this.mSamplingInterval = samplingInterval; this.setDeviceState(mDeviceState.getReadonlyClient()); + this.setAddDebugEntries(false); } void tickRealtime(long micros) { diff --git a/services/core/java/com/android/server/LooperStatsService.java b/services/core/java/com/android/server/LooperStatsService.java index 2dee3a0b5c21..c563ad224da6 100644 --- a/services/core/java/com/android/server/LooperStatsService.java +++ b/services/core/java/com/android/server/LooperStatsService.java @@ -141,6 +141,7 @@ public class LooperStatsService extends Binder { if (mEnabled != enabled) { mEnabled = enabled; mStats.reset(); + mStats.setAddDebugEntries(enabled); Looper.setObserver(enabled ? mStats : null); } } |