diff options
| author | Felipe Leme <felipeal@google.com> | 2020-10-19 15:18:19 -0700 |
|---|---|---|
| committer | Felipe Leme <felipeal@google.com> | 2020-10-23 11:40:06 -0700 |
| commit | c60be18878b58eeaa10a9086d1ea7950f6a2fd81 (patch) | |
| tree | 6919ab7bd05e5728605cca7a8fe5c0055c0eaa3b /services/java/com/android/server | |
| parent | 8c7bfcd5ab9b7ed4dcfd660557aaa99ea1e72a80 (diff) | |
Created a mechanism to dump service-less SystemServer state.
SystemServer has classes (like SystemServerInitThreadPool,
SystemServiceManager, and even SystemServer itself) that are
not associated with a service; hence, the state of these classes
are not dumped in a bugreport.
Test: adb shell dumpsys system_server_dumper
Test: adb shell dumpsys system_server_dumper --list
Test: adb shell dumpsys system_server_dumper --name SystemServer
Bug: 159831354
Fixes: 163921395
Change-Id: I5719f7cd3a9022dc0ab12a3b3b22487e2b4866e0
Diffstat (limited to 'services/java/com/android/server')
| -rw-r--r-- | services/java/com/android/server/SystemServer.java | 100 |
1 files changed, 97 insertions, 3 deletions
diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java index 975e2265b60c..e116a353c723 100644 --- a/services/java/com/android/server/SystemServer.java +++ b/services/java/com/android/server/SystemServer.java @@ -76,14 +76,18 @@ import android.provider.Settings; import android.server.ServerProtoEnums; import android.sysprop.VoldProperties; import android.text.TextUtils; +import android.util.ArrayMap; import android.util.DisplayMetrics; import android.util.EventLog; +import android.util.IndentingPrintWriter; import android.util.Pair; import android.util.Slog; +import android.util.TimeUtils; import android.view.contentcapture.ContentCaptureManager; import com.android.i18n.timezone.ZoneInfoDb; import com.android.internal.R; +import com.android.internal.annotations.GuardedBy; import com.android.internal.notification.SystemNotificationChannels; import com.android.internal.os.BinderInternal; import com.android.internal.os.RuntimeInit; @@ -188,14 +192,20 @@ import dalvik.system.VMRuntime; import com.google.android.startop.iorap.IorapForwardingService; import java.io.File; +import java.io.FileDescriptor; import java.io.IOException; +import java.io.PrintWriter; +import java.util.Arrays; import java.util.LinkedList; import java.util.Locale; import java.util.Timer; import java.util.concurrent.CountDownLatch; import java.util.concurrent.Future; -public final class SystemServer { +/** + * Entry point to {@code system_server}. + */ +public final class SystemServer implements Dumpable { private static final String TAG = "SystemServer"; @@ -384,6 +394,9 @@ public final class SystemServer { private Future<?> mZygotePreload; private Future<?> mBlobStoreServiceStart; + private final SystemServerDumper mDumper = new SystemServerDumper(); + + /** * The pending WTF to be logged into dropbox. */ @@ -446,6 +459,75 @@ public final class SystemServer { mRuntimeRestart = "1".equals(SystemProperties.get("sys.boot_completed")); } + @Override + public void dump(IndentingPrintWriter pw, String[] args) { + pw.printf("Runtime restart: %b\n", mRuntimeRestart); + pw.printf("Start count: %d\n", mStartCount); + pw.print("Runtime start-up time: "); + TimeUtils.formatDuration(mRuntimeStartUptime, pw); pw.println(); + pw.print("Runtime start-elapsed time: "); + TimeUtils.formatDuration(mRuntimeStartElapsedTime, pw); pw.println(); + } + + private final class SystemServerDumper extends Binder { + + @GuardedBy("mDumpables") + private final ArrayMap<String, Dumpable> mDumpables = new ArrayMap<>(4); + + @Override + protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { + final boolean hasArgs = args != null && args.length > 0; + + synchronized (mDumpables) { + if (hasArgs && "--list".equals(args[0])) { + final int dumpablesSize = mDumpables.size(); + for (int i = 0; i < dumpablesSize; i++) { + pw.println(mDumpables.keyAt(i)); + } + return; + } + + if (hasArgs && "--name".equals(args[0])) { + if (args.length < 2) { + pw.println("Must pass at least one argument to --name"); + return; + } + final String name = args[1]; + final Dumpable dumpable = mDumpables.get(name); + if (dumpable == null) { + pw.printf("No dummpable named %s\n", name); + return; + } + + try (IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " ")) { + // Strip --name DUMPABLE from args + final String[] actualArgs = Arrays.copyOfRange(args, 2, args.length); + dumpable.dump(ipw, actualArgs); + } + return; + } + + final int dumpablesSize = mDumpables.size(); + try (IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " ")) { + for (int i = 0; i < dumpablesSize; i++) { + final Dumpable dumpable = mDumpables.valueAt(i); + ipw.printf("%s:\n", dumpable.getDumpableName()); + ipw.increaseIndent(); + dumpable.dump(ipw, args); + ipw.decreaseIndent(); + ipw.println(); + } + } + } + } + + private void addDumpable(@NonNull Dumpable dumpable) { + synchronized (mDumpables) { + mDumpables.put(dumpable.getDumpableName(), dumpable); + } + } + } + private void run() { TimingsTraceAndSlog t = new TimingsTraceAndSlog(); try { @@ -572,13 +654,21 @@ public final class SystemServer { // Call per-process mainline module initialization. ActivityThread.initializeMainlineModules(); + // Sets the dumper service + ServiceManager.addService("system_server_dumper", mDumper); + mDumper.addDumpable(this); + // Create the system service manager. mSystemServiceManager = new SystemServiceManager(mSystemContext); mSystemServiceManager.setStartInfo(mRuntimeRestart, mRuntimeStartElapsedTime, mRuntimeStartUptime); + mDumper.addDumpable(mSystemServiceManager); + LocalServices.addService(SystemServiceManager.class, mSystemServiceManager); // Prepare the thread pool for init tasks that can be parallelized - SystemServerInitThreadPool.start(); + SystemServerInitThreadPool tp = SystemServerInitThreadPool.start(); + mDumper.addDumpable(tp); + // Attach JVMTI agent if this is a debuggable build and the system property is set. if (Build.IS_DEBUGGABLE) { // Property is of the form "library_path=parameters". @@ -2321,7 +2411,11 @@ public final class SystemServer { if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE)) { t.traceBegin("StartCarServiceHelperService"); - mSystemServiceManager.startService(CAR_SERVICE_HELPER_SERVICE_CLASS); + final SystemService cshs = mSystemServiceManager + .startService(CAR_SERVICE_HELPER_SERVICE_CLASS); + if (cshs instanceof Dumpable) { + mDumper.addDumpable((Dumpable) cshs); + } t.traceEnd(); } |
