From b4739d9d14d55ce6193f54b3cb248196facf947f Mon Sep 17 00:00:00 2001 From: Makoto Onuki Date: Fri, 15 Feb 2019 15:22:04 -0800 Subject: Add runtime restart information to sysprops and eventlog Added 3 more system props: - sys.system_server.start_count How many times the system server has started, 1-based. - sys.system_server.start_elapsed Elapsed time when the system server started most recently - sys.system_server.start_uptime Uptime when the system server started most recently Also log the same information on event log, as 'system_server_start'. Bug: 124022170 Test: manual $ adb logcat -b events -s system_server_start 02-15 23:35:06.151 1222 1222 I system_server_start: [1,4714,4714] (killed the system server) 02-15 23:35:24.673 4209 4209 I system_server_start: [2,23236,23236] $ getprop | grep system_server [sys.system_server.start_count]: [2] [sys.system_server.start_elapsed]: [23236] [sys.system_server.start_uptime]: [23236] Change-Id: Ie3e77903e723eb5b7e79b545d4287d9b07c4b379 --- services/java/com/android/server/SystemServer.java | 25 ++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'services/java/com') diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java index aae159c2edcb..14a0a58ccfbc 100644 --- a/services/java/com/android/server/SystemServer.java +++ b/services/java/com/android/server/SystemServer.java @@ -308,6 +308,7 @@ public final class SystemServer { private boolean mOnlyCore; private boolean mFirstBoot; + private final int mStartCount; private final boolean mRuntimeRestart; private final long mRuntimeStartElapsedTime; private final long mRuntimeStartUptime; @@ -315,6 +316,9 @@ public final class SystemServer { private static final String START_SENSOR_SERVICE = "StartSensorService"; private static final String START_HIDL_SERVICES = "StartHidlServices"; + private static final String SYSPROP_START_COUNT = "sys.system_server.start_count"; + private static final String SYSPROP_START_ELAPSED = "sys.system_server.start_elapsed"; + private static final String SYSPROP_START_UPTIME = "sys.system_server.start_uptime"; private Future mSensorServiceStart; private Future mZygotePreload; @@ -344,16 +348,33 @@ public final class SystemServer { public SystemServer() { // Check for factory test mode. mFactoryTestMode = FactoryTest.getMode(); - // Remember if it's runtime restart(when sys.boot_completed is already set) or reboot - mRuntimeRestart = "1".equals(SystemProperties.get("sys.boot_completed")); + // Record process start information. + // Note SYSPROP_START_COUNT will increment by *2* on a FDE device when it fully boots; + // one for the password screen, second for the actual boot. + mStartCount = SystemProperties.getInt(SYSPROP_START_COUNT, 0) + 1; mRuntimeStartElapsedTime = SystemClock.elapsedRealtime(); mRuntimeStartUptime = SystemClock.uptimeMillis(); + + // Remember if it's runtime restart(when sys.boot_completed is already set) or reboot + // We don't use "mStartCount > 1" here because it'll be wrong on a FDE device. + // TODO: mRuntimeRestart will *not* be set to true if the proccess crashes before + // sys.boot_completed is set. Fix it. + mRuntimeRestart = "1".equals(SystemProperties.get("sys.boot_completed")); } private void run() { try { traceBeginAndSlog("InitBeforeStartServices"); + + // Record the process start information in sys props. + SystemProperties.set(SYSPROP_START_COUNT, String.valueOf(mStartCount)); + SystemProperties.set(SYSPROP_START_ELAPSED, String.valueOf(mRuntimeStartElapsedTime)); + SystemProperties.set(SYSPROP_START_UPTIME, String.valueOf(mRuntimeStartUptime)); + + EventLog.writeEvent(EventLogTags.SYSTEM_SERVER_START, + mStartCount, mRuntimeStartUptime, mRuntimeStartElapsedTime); + // If a device's clock is before 1970 (before 0), a lot of // APIs crash dealing with negative numbers, notably // java.io.File#setLastModified, so instead we fake it and -- cgit v1.2.3-59-g8ed1b