Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1ab43d59 authored by Yasuhiro Matsuda's avatar Yasuhiro Matsuda
Browse files

Add trace code to system server.

- Add TRACE_TAG_SYSTEM_SERVER for tracing system server code.
- Add a few more tracing code to the code paths related to boot.

BUG: 21739901
BUG: 22207144
Change-Id: I08b424d2f83783f512c3818394099909cd55f327
parent bd4c482b
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -77,6 +77,8 @@ public final class Trace {
    public static final long TRACE_TAG_POWER = 1L << 17;
    /** @hide */
    public static final long TRACE_TAG_PACKAGE_MANAGER = 1L << 18;
    /** @hide */
    public static final long TRACE_TAG_SYSTEM_SERVER = 1L << 19;

    private static final long TRACE_TAG_NOT_READY = 1L << 63;
    private static final int MAX_SECTION_NAME_LEN = 127;
+59 −29
Original line number Diff line number Diff line
@@ -182,8 +182,18 @@ public class ZygoteInit {

    static void preload() {
        Log.d(TAG, "begin preload");
        try {
            Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadClasses");
            preloadClasses();
        } finally {
            Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
        }
        try {
            Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadResources");
            preloadResources();
        } finally {
            Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
        }
        preloadOpenGL();
        preloadSharedLibraries();
        // Ask the WebViewFactory to do any initialization that must run in the zygote process,
@@ -264,6 +274,7 @@ public class ZygoteInit {
                }

                try {
                    Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadClass " + line);
                    if (false) {
                        Log.v(TAG, "Preloading " + line + "...");
                    }
@@ -287,6 +298,8 @@ public class ZygoteInit {
                        throw (RuntimeException) t;
                    }
                    throw new RuntimeException(t);
                } finally {
                    Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
                }
            }

@@ -300,7 +313,9 @@ public class ZygoteInit {
            runtime.setTargetHeapUtilization(defaultUtilization);

            // Fill in dex caches with classes, fields, and methods brought in by preloading.
            Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadDexCaches");
            runtime.preloadDexCaches();
            Trace.traceEnd(Trace.TRACE_TAG_DALVIK);

            // Bring back root. We'll need it later if we're in the zygote.
            if (droppedPriviliges) {
@@ -561,13 +576,15 @@ public class ZygoteInit {

    public static void main(String argv[]) {
        try {
            boolean startSystemServer = false;
            String socketName = "zygote";
            String abiList = null;
            try {
                Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "ZygoteInit");
                RuntimeInit.enableDdms();
                // Start profiling the zygote initialization.
                SamplingProfilerIntegration.start();

            boolean startSystemServer = false;
            String socketName = "zygote";
            String abiList = null;
                for (int i = 1; i < argv.length; i++) {
                    if ("start-system-server".equals(argv[i])) {
                        startSystemServer = true;
@@ -585,17 +602,30 @@ public class ZygoteInit {
                }

                registerZygoteSocket(socketName);
                try {
                    Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "ZygotePreload");
                    EventLog.writeEvent(LOG_BOOT_PROGRESS_PRELOAD_START,
                            SystemClock.uptimeMillis());
                    preload();
                    EventLog.writeEvent(LOG_BOOT_PROGRESS_PRELOAD_END,
                            SystemClock.uptimeMillis());
                } finally {
                    Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
                }

                // Finish profiling the zygote initialization.
                SamplingProfilerIntegration.writeZygoteSnapshot();

                // Do an initial gc to clean up after startup
                try {
                    Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PostZygoteInitGC");
                    gcAndFinalize();
                } finally {
                    Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
                }
            } finally {
                Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
            }

            // Disable tracing so that forked processes do not inherit stale tracing tags from
            // Zygote.
+3 −0
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@
 * limitations under the License.
 */

#define ATRACE_TAG ATRACE_TAG_DALVIK
#define LOG_TAG "AndroidRuntime"
//#define LOG_NDEBUG 0

@@ -23,6 +24,7 @@
#include <binder/IServiceManager.h>
#include <utils/Log.h>
#include <utils/misc.h>
#include <utils/Trace.h>
#include <binder/Parcel.h>
#include <utils/threads.h>
#include <cutils/properties.h>
@@ -1400,6 +1402,7 @@ static const RegJNIRec gRegJNI[] = {
 */
/*static*/ int AndroidRuntime::startReg(JNIEnv* env)
{
    ATRACE_NAME("RegisterAndroidNatives");
    /*
     * This hook causes all future threads created in this process to be
     * attached to the JavaVM.  (This needs to go away in favor of JNI
+54 −44
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.server;

import android.content.Context;
import android.os.Trace;
import android.util.Slog;

import java.lang.reflect.Constructor;
@@ -75,8 +76,10 @@ public class SystemServiceManager {
     */
    @SuppressWarnings("unchecked")
    public <T extends SystemService> T startService(Class<T> serviceClass) {
        try {
            final String name = serviceClass.getName();
            Slog.i(TAG, "Starting " + name);
            Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "StartService " + name);

            // Create the service.
            if (!SystemService.class.isAssignableFrom(serviceClass)) {
@@ -112,6 +115,9 @@ public class SystemServiceManager {
                        + ": onStart threw an exception", ex);
            }
            return service;
        } finally {
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
    }

    /**
@@ -127,7 +133,8 @@ public class SystemServiceManager {
        mCurrentPhase = phase;

        Slog.i(TAG, "Starting phase " + mCurrentPhase);

        try {
            Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "OnBootPhase " + phase);
            final int serviceLen = mServices.size();
            for (int i = 0; i < serviceLen; i++) {
                final SystemService service = mServices.get(i);
@@ -140,6 +147,9 @@ public class SystemServiceManager {
                            + mCurrentPhase, ex);
                }
            }
        } finally {
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
    }

    public void startUser(final int userHandle) {
+7 −0
Original line number Diff line number Diff line
@@ -186,6 +186,7 @@ import android.os.ServiceManager;
import android.os.StrictMode;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.os.Trace;
import android.os.UpdateLock;
import android.os.UserHandle;
import android.os.UserManager;
@@ -1780,7 +1781,9 @@ public final class ActivityManagerService extends ActivityManagerNative
            }
            case FINISH_BOOTING_MSG: {
                if (msg.arg1 != 0) {
                    Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "FinishBooting");
                    finishBooting();
                    Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
                }
                if (msg.arg2 != 0) {
                    enableScreenAfterBoot();
@@ -6285,7 +6288,9 @@ public final class ActivityManagerService extends ActivityManagerNative
            mBootAnimationComplete = true;
        }
        if (callFinishBooting) {
            Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "FinishBooting");
            finishBooting();
            Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
        }
    }
@@ -6311,7 +6316,9 @@ public final class ActivityManagerService extends ActivityManagerNative
        }
        if (booting) {
            Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "FinishBooting");
            finishBooting();
            Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
        }
        if (enableScreen) {
Loading