Loading core/java/android/metrics/LogMaker.java +10 −0 Original line number Diff line number Diff line Loading @@ -93,6 +93,16 @@ public class LogMaker { return this; } /** * Set event latency. * * @hide // TODO Expose in the future? Too late for O. */ public LogMaker setLatency(long milliseconds) { entries.put(MetricsEvent.NOTIFICATION_SINCE_CREATE_MILLIS, milliseconds); return this; } /** * This will be set by the system when the log is persisted. * Client-supplied values will be ignored. Loading services/core/java/com/android/server/EventLogTags.logtags +1 −1 Original line number Diff line number Diff line Loading @@ -25,7 +25,7 @@ option java_package com.android.server # This is logged when the screen on broadcast has completed 2727 power_screen_broadcast_stop (which|1|5),(wakelockCount|1|1) # This is logged when the screen is turned on or off. 2728 power_screen_state (offOrOn|1|5),(becauseOfUser|1|5),(totalTouchDownTime|2|3),(touchCycles|1|1) 2728 power_screen_state (offOrOn|1|5),(becauseOfUser|1|5),(totalTouchDownTime|2|3),(touchCycles|1|1),(latency|1|3) # This is logged when the partial wake lock (keeping the device awake # regardless of whether the screen is off) is acquired or released. 2729 power_partial_wake_state (releasedorAcquired|1|5),(tag|3) Loading services/core/java/com/android/server/power/Notifier.java +2 −6 Original line number Diff line number Diff line Loading @@ -406,11 +406,7 @@ final class Notifier { mHandler.post(new Runnable() { @Override public void run() { LogMaker log = new LogMaker(MetricsEvent.SCREEN); log.setType(MetricsEvent.TYPE_OPEN); log.setSubtype(0); // not user initiated MetricsLogger.action(log); EventLog.writeEvent(EventLogTags.POWER_SCREEN_STATE, 1, 0, 0, 0); // Note a SCREEN tron event is logged in PowerManagerService. mPolicy.startedWakingUp(); } }); Loading Loading @@ -470,7 +466,7 @@ final class Notifier { log.setType(MetricsEvent.TYPE_CLOSE); log.setSubtype(why); MetricsLogger.action(log); EventLog.writeEvent(EventLogTags.POWER_SCREEN_STATE, 0, why, 0, 0); EventLogTags.writePowerScreenState(0, why, 0, 0, 0); mPolicy.finishedGoingToSleep(why); } }); Loading services/core/java/com/android/server/power/PowerManagerService.java +30 −0 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ import android.hardware.SystemSensorManager; import android.hardware.display.DisplayManagerInternal; import android.hardware.display.DisplayManagerInternal.DisplayPowerRequest; import android.hardware.power.V1_0.PowerHint; import android.metrics.LogMaker; import android.net.Uri; import android.os.BatteryManager; import android.os.BatteryManagerInternal; Loading Loading @@ -75,6 +76,8 @@ import com.android.internal.annotations.VisibleForTesting; import com.android.internal.app.IAppOpsService; import com.android.internal.app.IBatteryStats; import com.android.internal.hardware.AmbientDisplayConfiguration; import com.android.internal.logging.MetricsLogger; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.internal.os.BackgroundThread; import com.android.internal.util.ArrayUtils; import com.android.internal.util.DumpUtils; Loading Loading @@ -188,6 +191,11 @@ public final class PowerManagerService extends SystemService // System property indicating that the screen should remain off until an explicit user action private static final String SYSTEM_PROPERTY_QUIESCENT = "ro.boot.quiescent"; private static final String TRACE_SCREEN_ON = "Screen turning on"; /** If turning screen on takes more than this long, we show a warning on logcat. */ private static final int SCREEN_ON_LATENCY_WARNING_MS = 200; /** Constants for {@link #shutdownOrRebootInternal} */ @Retention(RetentionPolicy.SOURCE) @IntDef({HALT_MODE_SHUTDOWN, HALT_MODE_REBOOT, HALT_MODE_REBOOT_SAFE_MODE}) Loading Loading @@ -1369,6 +1377,8 @@ public final class PowerManagerService extends SystemService return false; } Trace.asyncTraceBegin(Trace.TRACE_TAG_POWER, TRACE_SCREEN_ON, 0); Trace.traceBegin(Trace.TRACE_TAG_POWER, "wakeUp"); try { switch (mWakefulness) { Loading Loading @@ -1551,6 +1561,23 @@ public final class PowerManagerService extends SystemService } } private void logScreenOn() { Trace.asyncTraceEnd(Trace.TRACE_TAG_POWER, TRACE_SCREEN_ON, 0); final int latencyMs = (int) (SystemClock.uptimeMillis() - mLastWakeTime); LogMaker log = new LogMaker(MetricsEvent.SCREEN); log.setType(MetricsEvent.TYPE_OPEN); log.setSubtype(0); // not user initiated log.setLatency(latencyMs); // How long it took. MetricsLogger.action(log); EventLogTags.writePowerScreenState(1, 0, 0, 0, latencyMs); if (latencyMs >= SCREEN_ON_LATENCY_WARNING_MS) { Slog.w(TAG, "Screen on took " + latencyMs+ " ms"); } } private void finishWakefulnessChangeIfNeededLocked() { if (mWakefulnessChanging && mDisplayReady) { if (mWakefulness == WAKEFULNESS_DOZING Loading @@ -1560,6 +1587,9 @@ public final class PowerManagerService extends SystemService if (mWakefulness == WAKEFULNESS_DOZING || mWakefulness == WAKEFULNESS_ASLEEP) { logSleepTimeoutRecapturedLocked(); } if (mWakefulness == WAKEFULNESS_AWAKE) { logScreenOn(); } mWakefulnessChanging = false; mNotifier.onWakefulnessChangeFinished(); } Loading Loading
core/java/android/metrics/LogMaker.java +10 −0 Original line number Diff line number Diff line Loading @@ -93,6 +93,16 @@ public class LogMaker { return this; } /** * Set event latency. * * @hide // TODO Expose in the future? Too late for O. */ public LogMaker setLatency(long milliseconds) { entries.put(MetricsEvent.NOTIFICATION_SINCE_CREATE_MILLIS, milliseconds); return this; } /** * This will be set by the system when the log is persisted. * Client-supplied values will be ignored. Loading
services/core/java/com/android/server/EventLogTags.logtags +1 −1 Original line number Diff line number Diff line Loading @@ -25,7 +25,7 @@ option java_package com.android.server # This is logged when the screen on broadcast has completed 2727 power_screen_broadcast_stop (which|1|5),(wakelockCount|1|1) # This is logged when the screen is turned on or off. 2728 power_screen_state (offOrOn|1|5),(becauseOfUser|1|5),(totalTouchDownTime|2|3),(touchCycles|1|1) 2728 power_screen_state (offOrOn|1|5),(becauseOfUser|1|5),(totalTouchDownTime|2|3),(touchCycles|1|1),(latency|1|3) # This is logged when the partial wake lock (keeping the device awake # regardless of whether the screen is off) is acquired or released. 2729 power_partial_wake_state (releasedorAcquired|1|5),(tag|3) Loading
services/core/java/com/android/server/power/Notifier.java +2 −6 Original line number Diff line number Diff line Loading @@ -406,11 +406,7 @@ final class Notifier { mHandler.post(new Runnable() { @Override public void run() { LogMaker log = new LogMaker(MetricsEvent.SCREEN); log.setType(MetricsEvent.TYPE_OPEN); log.setSubtype(0); // not user initiated MetricsLogger.action(log); EventLog.writeEvent(EventLogTags.POWER_SCREEN_STATE, 1, 0, 0, 0); // Note a SCREEN tron event is logged in PowerManagerService. mPolicy.startedWakingUp(); } }); Loading Loading @@ -470,7 +466,7 @@ final class Notifier { log.setType(MetricsEvent.TYPE_CLOSE); log.setSubtype(why); MetricsLogger.action(log); EventLog.writeEvent(EventLogTags.POWER_SCREEN_STATE, 0, why, 0, 0); EventLogTags.writePowerScreenState(0, why, 0, 0, 0); mPolicy.finishedGoingToSleep(why); } }); Loading
services/core/java/com/android/server/power/PowerManagerService.java +30 −0 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ import android.hardware.SystemSensorManager; import android.hardware.display.DisplayManagerInternal; import android.hardware.display.DisplayManagerInternal.DisplayPowerRequest; import android.hardware.power.V1_0.PowerHint; import android.metrics.LogMaker; import android.net.Uri; import android.os.BatteryManager; import android.os.BatteryManagerInternal; Loading Loading @@ -75,6 +76,8 @@ import com.android.internal.annotations.VisibleForTesting; import com.android.internal.app.IAppOpsService; import com.android.internal.app.IBatteryStats; import com.android.internal.hardware.AmbientDisplayConfiguration; import com.android.internal.logging.MetricsLogger; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.internal.os.BackgroundThread; import com.android.internal.util.ArrayUtils; import com.android.internal.util.DumpUtils; Loading Loading @@ -188,6 +191,11 @@ public final class PowerManagerService extends SystemService // System property indicating that the screen should remain off until an explicit user action private static final String SYSTEM_PROPERTY_QUIESCENT = "ro.boot.quiescent"; private static final String TRACE_SCREEN_ON = "Screen turning on"; /** If turning screen on takes more than this long, we show a warning on logcat. */ private static final int SCREEN_ON_LATENCY_WARNING_MS = 200; /** Constants for {@link #shutdownOrRebootInternal} */ @Retention(RetentionPolicy.SOURCE) @IntDef({HALT_MODE_SHUTDOWN, HALT_MODE_REBOOT, HALT_MODE_REBOOT_SAFE_MODE}) Loading Loading @@ -1369,6 +1377,8 @@ public final class PowerManagerService extends SystemService return false; } Trace.asyncTraceBegin(Trace.TRACE_TAG_POWER, TRACE_SCREEN_ON, 0); Trace.traceBegin(Trace.TRACE_TAG_POWER, "wakeUp"); try { switch (mWakefulness) { Loading Loading @@ -1551,6 +1561,23 @@ public final class PowerManagerService extends SystemService } } private void logScreenOn() { Trace.asyncTraceEnd(Trace.TRACE_TAG_POWER, TRACE_SCREEN_ON, 0); final int latencyMs = (int) (SystemClock.uptimeMillis() - mLastWakeTime); LogMaker log = new LogMaker(MetricsEvent.SCREEN); log.setType(MetricsEvent.TYPE_OPEN); log.setSubtype(0); // not user initiated log.setLatency(latencyMs); // How long it took. MetricsLogger.action(log); EventLogTags.writePowerScreenState(1, 0, 0, 0, latencyMs); if (latencyMs >= SCREEN_ON_LATENCY_WARNING_MS) { Slog.w(TAG, "Screen on took " + latencyMs+ " ms"); } } private void finishWakefulnessChangeIfNeededLocked() { if (mWakefulnessChanging && mDisplayReady) { if (mWakefulness == WAKEFULNESS_DOZING Loading @@ -1560,6 +1587,9 @@ public final class PowerManagerService extends SystemService if (mWakefulness == WAKEFULNESS_DOZING || mWakefulness == WAKEFULNESS_ASLEEP) { logSleepTimeoutRecapturedLocked(); } if (mWakefulness == WAKEFULNESS_AWAKE) { logScreenOn(); } mWakefulnessChanging = false; mNotifier.onWakefulnessChangeFinished(); } Loading