summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Marcin Oczeretko <marcinoc@google.com> 2018-09-10 18:06:52 +0100
committer Marcin Oczeretko <marcinoc@google.com> 2018-09-17 17:25:55 +0100
commit3e6494eb3e59ba4f7d7e26b5c1c5b3378efdf9e6 (patch)
treea1c3ac554751147db4e065893e5da71b6a7ee008
parent6c109c76c99a0d8f3437b4530f6e5281bb45f00d (diff)
Prepare LooperStats to be collected as a Westworld gauge matric
- call LooperStats.reset() from StatsCompanionService - add screen_interactive to the LooperStats atom - temporarily set uid = 1000 to avoid statsd warnings that the uid is invalid Bug: 113651685 Test: Manual and UTs Change-Id: Iacf45fcb746c6bb9837456a2a0c74f5a073ff822
-rw-r--r--cmds/statsd/src/atoms.proto13
-rw-r--r--cmds/statsd/src/external/StatsPullerManager.cpp2
-rw-r--r--core/java/com/android/internal/os/LooperStats.java25
-rw-r--r--core/tests/coretests/src/com/android/internal/os/LooperStatsTest.java14
-rw-r--r--services/core/java/com/android/server/stats/StatsCompanionService.java6
5 files changed, 44 insertions, 16 deletions
diff --git a/cmds/statsd/src/atoms.proto b/cmds/statsd/src/atoms.proto
index 6ab4dd915178..ab12035074f1 100644
--- a/cmds/statsd/src/atoms.proto
+++ b/cmds/statsd/src/atoms.proto
@@ -2261,6 +2261,14 @@ message BinderCallsExceptions {
optional int64 exception_count = 2;
}
+/**
+ * Pulls the statistics of message dispatching on HandlerThreads.
+ *
+ * Looper stats will be reset every time the data is pulled. It means it can only be pulled by one
+ * config on the device.
+ *
+ * Next tag: 11
+ */
message LooperStats {
// Currently not collected and always set to 0.
optional int32 uid = 1 [(is_uid) = true];
@@ -2304,8 +2312,11 @@ message LooperStats {
// Total CPU usage of all processed message.
// Average can be computed using recorded_total_cpu_micros /
// recorded_message_count. Total can be computed using
- // recorded_total_cpu_micros / recorded_message_count * call_count.
+ // recorded_total_cpu_micros / recorded_message_count * message_count.
optional int64 recorded_total_cpu_micros = 9;
+
+ // True if the screen was interactive PowerManager#isInteractive at the end of the call.
+ optional bool screen_interactive = 10;
}
/**
diff --git a/cmds/statsd/src/external/StatsPullerManager.cpp b/cmds/statsd/src/external/StatsPullerManager.cpp
index f6ba0b6017be..7f4a7836a870 100644
--- a/cmds/statsd/src/external/StatsPullerManager.cpp
+++ b/cmds/statsd/src/external/StatsPullerManager.cpp
@@ -184,7 +184,7 @@ const std::map<int, PullAtomInfo> StatsPullerManager::kAllPullAtomInfo = {
// looper_stats
{android::util::LOOPER_STATS,
{{5, 6, 7, 8, 9},
- {2, 3, 4},
+ {2, 3, 4, 10},
1 * NS_PER_SEC,
new StatsCompanionServicePuller(android::util::LOOPER_STATS)}},
// Disk Stats
diff --git a/core/java/com/android/internal/os/LooperStats.java b/core/java/com/android/internal/os/LooperStats.java
index 02a8b224e3c2..0650d0af7caf 100644
--- a/core/java/com/android/internal/os/LooperStats.java
+++ b/core/java/com/android/internal/os/LooperStats.java
@@ -106,6 +106,7 @@ public class LooperStats implements Looper.Observer {
synchronized (entry) {
entry.exceptionCount++;
}
+
recycleSession(session);
}
@@ -116,29 +117,29 @@ public class LooperStats implements Looper.Observer {
/** Returns an array of {@link ExportedEntry entries} with the aggregated statistics. */
public List<ExportedEntry> getEntries() {
- final ArrayList<ExportedEntry> entries;
+ final ArrayList<ExportedEntry> exportedEntries;
synchronized (mLock) {
final int size = mEntries.size();
- entries = new ArrayList<>(size);
+ exportedEntries = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
Entry entry = mEntries.valueAt(i);
synchronized (entry) {
- entries.add(new ExportedEntry(entry));
+ exportedEntries.add(new ExportedEntry(entry));
}
}
}
// Add the overflow and collision entries only if they have any data.
- if (mOverflowEntry.messageCount > 0 || mOverflowEntry.exceptionCount > 0) {
- synchronized (mOverflowEntry) {
- entries.add(new ExportedEntry(mOverflowEntry));
- }
- }
- if (mHashCollisionEntry.messageCount > 0 || mHashCollisionEntry.exceptionCount > 0) {
- synchronized (mHashCollisionEntry) {
- entries.add(new ExportedEntry(mHashCollisionEntry));
+ maybeAddSpecialEntry(exportedEntries, mOverflowEntry);
+ maybeAddSpecialEntry(exportedEntries, mHashCollisionEntry);
+ return exportedEntries;
+ }
+
+ private void maybeAddSpecialEntry(List<ExportedEntry> exportedEntries, Entry specialEntry) {
+ synchronized (specialEntry) {
+ if (specialEntry.messageCount > 0 || specialEntry.exceptionCount > 0) {
+ exportedEntries.add(new ExportedEntry(specialEntry));
}
}
- return entries;
}
/** Removes all collected data. */
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 0eb3d06e79de..565a3ecd0411 100644
--- a/core/tests/coretests/src/com/android/internal/os/LooperStatsTest.java
+++ b/core/tests/coretests/src/com/android/internal/os/LooperStatsTest.java
@@ -342,6 +342,20 @@ public final class LooperStatsTest {
assertThat(looperStats.getEntries().get(0).messageCount).isEqualTo(2);
}
+ @Test
+ public void testReset() {
+ TestableLooperStats looperStats = new TestableLooperStats(1, 1);
+
+ Object token1 = looperStats.messageDispatchStarting();
+ looperStats.messageDispatched(token1, mHandlerFirst.obtainMessage(1000));
+ Object token2 = looperStats.messageDispatchStarting();
+ looperStats.messageDispatched(token2, mHandlerFirst.obtainMessage(2000));
+ looperStats.reset();
+
+ List<LooperStats.ExportedEntry> entries = looperStats.getEntries();
+ assertThat(entries).hasSize(0);
+ }
+
private static void assertThrows(Class<? extends Exception> exceptionClass, Runnable r) {
try {
r.run();
diff --git a/services/core/java/com/android/server/stats/StatsCompanionService.java b/services/core/java/com/android/server/stats/StatsCompanionService.java
index 20918995a8ee..a4d42a127cd6 100644
--- a/services/core/java/com/android/server/stats/StatsCompanionService.java
+++ b/services/core/java/com/android/server/stats/StatsCompanionService.java
@@ -976,10 +976,11 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
}
List<LooperStats.ExportedEntry> entries = looperStats.getEntries();
+ looperStats.reset();
long elapsedNanos = SystemClock.elapsedRealtimeNanos();
for (LooperStats.ExportedEntry entry : entries) {
- StatsLogEventWrapper e = new StatsLogEventWrapper(elapsedNanos, tagId, 9 /* fields */);
- e.writeLong(0); // uid collection not implemented yet
+ StatsLogEventWrapper e = new StatsLogEventWrapper(elapsedNanos, tagId, 10 /* fields */);
+ e.writeInt(1000); // uid collection not implemented yet
e.writeString(entry.handlerClassName);
e.writeString(entry.threadName);
e.writeString(entry.messageName);
@@ -988,6 +989,7 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
e.writeLong(entry.recordedMessageCount);
e.writeLong(entry.totalLatencyMicros);
e.writeLong(entry.cpuUsageMicros);
+ e.writeBoolean(entry.isInteractive);
pulledData.add(e);
}
}