Loading cmds/app_process/app_main.cpp +4 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ #include <utils/Log.h> #include <cutils/process_name.h> #include <cutils/memory.h> #include <cutils/trace.h> #include <android_runtime/AndroidRuntime.h> #include <sys/personality.h> Loading Loading @@ -95,6 +96,9 @@ public: virtual void onZygoteInit() { // Re-enable tracing now that we're no longer in Zygote. atrace_set_tracing_enabled(true); sp<ProcessState> proc = ProcessState::self(); ALOGV("App process: starting thread pool.\n"); proc->startThreadPool(); Loading core/java/android/os/Trace.java +17 −4 Original line number Diff line number Diff line Loading @@ -79,6 +79,7 @@ public final class Trace { private static native void nativeAsyncTraceBegin(long tag, String name, int cookie); private static native void nativeAsyncTraceEnd(long tag, String name, int cookie); private static native void nativeSetAppTracingAllowed(boolean allowed); private static native void nativeSetTracingEnabled(boolean allowed); static { // We configure two separate change callbacks, one in Trace.cpp and one here. The Loading Loading @@ -115,10 +116,6 @@ public final class Trace { */ private static long cacheEnabledTags() { long tags = nativeGetEnabledTags(); if (tags == TRACE_TAG_NOT_READY) { Log.w(TAG, "Unexpected value from nativeGetEnabledTags: " + tags); // keep going } sEnabledTags = tags; return tags; } Loading Loading @@ -168,6 +165,22 @@ public final class Trace { cacheEnabledTags(); } /** * Set whether tracing is enabled in this process. Tracing is disabled shortly after Zygote * initializes and re-enabled after processes fork from Zygote. This is done because Zygote * has no way to be notified about changes to the tracing tags, and if Zygote ever reads and * caches the tracing tags, forked processes will inherit those stale tags. * * @hide */ public static void setTracingEnabled(boolean enabled) { nativeSetTracingEnabled(enabled); // Setting whether tracing is enabled may change the tags, so we update the cached tags // here. cacheEnabledTags(); } /** * Writes a trace message to indicate that a given section of code has * begun. Must be followed by a call to {@link #traceEnd} using the same Loading core/java/com/android/internal/os/ZygoteInit.java +5 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import android.net.LocalServerSocket; import android.os.Debug; import android.os.Process; import android.os.SystemClock; import android.os.Trace; import android.util.EventLog; import android.util.Log; Loading Loading @@ -528,6 +529,10 @@ public class ZygoteInit { // Do an initial gc to clean up after startup gc(); // Disable tracing so that forked processes do not inherit stale tracing tags from // Zygote. Trace.setTracingEnabled(false); // If requested, start system server directly from Zygote if (argv.length != 2) { throw new RuntimeException(argv[0] + USAGE_STRING); Loading core/jni/android_os_Trace.cpp +8 −0 Original line number Diff line number Diff line Loading @@ -86,6 +86,11 @@ static void android_os_Trace_nativeSetAppTracingAllowed(JNIEnv* env, atrace_set_debuggable(allowed); } static void android_os_Trace_nativeSetTracingEnabled(JNIEnv* env, jclass clazz, jboolean enabled) { atrace_set_tracing_enabled(enabled); } static JNINativeMethod gTraceMethods[] = { /* name, signature, funcPtr */ { "nativeGetEnabledTags", Loading @@ -109,6 +114,9 @@ static JNINativeMethod gTraceMethods[] = { { "nativeSetAppTracingAllowed", "(Z)V", (void*)android_os_Trace_nativeSetAppTracingAllowed }, { "nativeSetTracingEnabled", "(Z)V", (void*)android_os_Trace_nativeSetTracingEnabled }, }; int register_android_os_Trace(JNIEnv* env) { Loading Loading
cmds/app_process/app_main.cpp +4 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ #include <utils/Log.h> #include <cutils/process_name.h> #include <cutils/memory.h> #include <cutils/trace.h> #include <android_runtime/AndroidRuntime.h> #include <sys/personality.h> Loading Loading @@ -95,6 +96,9 @@ public: virtual void onZygoteInit() { // Re-enable tracing now that we're no longer in Zygote. atrace_set_tracing_enabled(true); sp<ProcessState> proc = ProcessState::self(); ALOGV("App process: starting thread pool.\n"); proc->startThreadPool(); Loading
core/java/android/os/Trace.java +17 −4 Original line number Diff line number Diff line Loading @@ -79,6 +79,7 @@ public final class Trace { private static native void nativeAsyncTraceBegin(long tag, String name, int cookie); private static native void nativeAsyncTraceEnd(long tag, String name, int cookie); private static native void nativeSetAppTracingAllowed(boolean allowed); private static native void nativeSetTracingEnabled(boolean allowed); static { // We configure two separate change callbacks, one in Trace.cpp and one here. The Loading Loading @@ -115,10 +116,6 @@ public final class Trace { */ private static long cacheEnabledTags() { long tags = nativeGetEnabledTags(); if (tags == TRACE_TAG_NOT_READY) { Log.w(TAG, "Unexpected value from nativeGetEnabledTags: " + tags); // keep going } sEnabledTags = tags; return tags; } Loading Loading @@ -168,6 +165,22 @@ public final class Trace { cacheEnabledTags(); } /** * Set whether tracing is enabled in this process. Tracing is disabled shortly after Zygote * initializes and re-enabled after processes fork from Zygote. This is done because Zygote * has no way to be notified about changes to the tracing tags, and if Zygote ever reads and * caches the tracing tags, forked processes will inherit those stale tags. * * @hide */ public static void setTracingEnabled(boolean enabled) { nativeSetTracingEnabled(enabled); // Setting whether tracing is enabled may change the tags, so we update the cached tags // here. cacheEnabledTags(); } /** * Writes a trace message to indicate that a given section of code has * begun. Must be followed by a call to {@link #traceEnd} using the same Loading
core/java/com/android/internal/os/ZygoteInit.java +5 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import android.net.LocalServerSocket; import android.os.Debug; import android.os.Process; import android.os.SystemClock; import android.os.Trace; import android.util.EventLog; import android.util.Log; Loading Loading @@ -528,6 +529,10 @@ public class ZygoteInit { // Do an initial gc to clean up after startup gc(); // Disable tracing so that forked processes do not inherit stale tracing tags from // Zygote. Trace.setTracingEnabled(false); // If requested, start system server directly from Zygote if (argv.length != 2) { throw new RuntimeException(argv[0] + USAGE_STRING); Loading
core/jni/android_os_Trace.cpp +8 −0 Original line number Diff line number Diff line Loading @@ -86,6 +86,11 @@ static void android_os_Trace_nativeSetAppTracingAllowed(JNIEnv* env, atrace_set_debuggable(allowed); } static void android_os_Trace_nativeSetTracingEnabled(JNIEnv* env, jclass clazz, jboolean enabled) { atrace_set_tracing_enabled(enabled); } static JNINativeMethod gTraceMethods[] = { /* name, signature, funcPtr */ { "nativeGetEnabledTags", Loading @@ -109,6 +114,9 @@ static JNINativeMethod gTraceMethods[] = { { "nativeSetAppTracingAllowed", "(Z)V", (void*)android_os_Trace_nativeSetAppTracingAllowed }, { "nativeSetTracingEnabled", "(Z)V", (void*)android_os_Trace_nativeSetTracingEnabled }, }; int register_android_os_Trace(JNIEnv* env) { Loading