From 7948c8737fb6e651f31c9e2166dcfbd2d1e41939 Mon Sep 17 00:00:00 2001 From: Bookatz Date: Tue, 4 Sep 2018 12:58:33 -0700 Subject: [PATCH] statsd atom: add WallClockTimeShifted In ag/4888395 we get rid of wall-clock time from EventMetrics because it is very RAM-costly. If someone needs the wall-clock time, they can get it from this atom instead. This way, the wall-clock time is only stored when interesting, instead of every single event! Bug: 113072343 Test: manual confirmation that it works Change-Id: I10c26a4fc9c73b29233108ef1fc0e9797382a8df --- cmds/statsd/src/atoms.proto | 14 +++++++++++++- .../com/android/server/AlarmManagerService.java | 3 +++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/cmds/statsd/src/atoms.proto b/cmds/statsd/src/atoms.proto index 6065bbfc3f905..82ca14df73798 100644 --- a/cmds/statsd/src/atoms.proto +++ b/cmds/statsd/src/atoms.proto @@ -89,7 +89,7 @@ message Atom { ActivityForegroundStateChanged activity_foreground_state_changed = 42; IsolatedUidChanged isolated_uid_changed = 43; PacketWakeupOccurred packet_wakeup_occurred = 44; - // 45 is available + WallClockTimeShifted wall_clock_time_shifted = 45; AnomalyDetected anomaly_detected = 46; AppBreadcrumbReported app_breadcrumb_reported = 47; AppStartOccurred app_start_occurred = 48; @@ -1433,6 +1433,18 @@ message AppBreadcrumbReported { optional State state = 3; } +/** + * Logs the wall-clock time when a significant wall-clock time shift occurs. + * For example, this could be due to the user manually changing the time. + * + * Logged from: + * frameworks/base/services/core/java/com/android/server/AlarmManagerService.java + */ +message WallClockTimeShifted { + // New wall-clock time in milliseconds, according to System.currentTimeMillis(). + optional int64 wall_clock_timestamp_millis = 1; +} + /** * Logs when statsd detects an anomaly. * diff --git a/services/core/java/com/android/server/AlarmManagerService.java b/services/core/java/com/android/server/AlarmManagerService.java index 26ef42f2b1e7e..93faa629b3077 100644 --- a/services/core/java/com/android/server/AlarmManagerService.java +++ b/services/core/java/com/android/server/AlarmManagerService.java @@ -80,6 +80,7 @@ import android.util.Slog; import android.util.SparseArray; import android.util.SparseBooleanArray; import android.util.SparseLongArray; +import android.util.StatsLog; import android.util.TimeUtils; import android.util.proto.ProtoOutputStream; @@ -3560,6 +3561,8 @@ class AlarmManagerService extends SystemService { if (DEBUG_BATCH) { Slog.v(TAG, "Time changed notification from kernel; rebatching"); } + // StatsLog requires currentTimeMillis(), which == nowRTC to within usecs. + StatsLog.write(StatsLog.WALL_CLOCK_TIME_SHIFTED, nowRTC); removeImpl(mTimeTickSender); removeImpl(mDateChangeSender); rebatchAllAlarms();