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
diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java
index aae159c..14a0a58 100644
--- a/services/java/com/android/server/SystemServer.java
+++ b/services/java/com/android/server/SystemServer.java
@@ -308,6 +308,7 @@
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 @@
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 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