diff options
author | Jamie Gennis <jgennis@google.com> | 2013-04-15 18:53:24 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2013-04-16 22:15:21 +0000 |
commit | 6ad0452e6301c0650f58f3991f7c523f6f279ddb (patch) | |
tree | 0f116a6253e62bd96a4deb02c137461516cf6266 | |
parent | d12a7645a3bf3ffa83b8041bf343f1dc12a2381f (diff) | |
download | frameworks_base-6ad0452e6301c0650f58f3991f7c523f6f279ddb.zip frameworks_base-6ad0452e6301c0650f58f3991f7c523f6f279ddb.tar.gz frameworks_base-6ad0452e6301c0650f58f3991f7c523f6f279ddb.tar.bz2 |
Disable tracing from Zygote
This change disables all atrace tracing in Zygote immediately after it is
initialized. This is necessary because Zygote has no way to receive
notifications that the enabled trace tags have been changed. Tracing is
re-enabled when other processes fork from Zygote.
Change-Id: If2983858fb0c4890ba9ab041849b1c4d98f66c13
-rw-r--r-- | cmds/app_process/app_main.cpp | 4 | ||||
-rw-r--r-- | core/java/android/os/Trace.java | 21 | ||||
-rw-r--r-- | core/java/com/android/internal/os/ZygoteInit.java | 5 | ||||
-rw-r--r-- | core/jni/android_os_Trace.cpp | 8 |
4 files changed, 34 insertions, 4 deletions
diff --git a/cmds/app_process/app_main.cpp b/cmds/app_process/app_main.cpp index 0668be6..90bcb0f 100644 --- a/cmds/app_process/app_main.cpp +++ b/cmds/app_process/app_main.cpp @@ -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> @@ -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(); diff --git a/core/java/android/os/Trace.java b/core/java/android/os/Trace.java index 617f490..3307a8c 100644 --- a/core/java/android/os/Trace.java +++ b/core/java/android/os/Trace.java @@ -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 @@ -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; } @@ -169,6 +166,22 @@ public final class Trace { } /** + * 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 * tag. diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java index 7eddc9c..2184fd2 100644 --- a/core/java/com/android/internal/os/ZygoteInit.java +++ b/core/java/com/android/internal/os/ZygoteInit.java @@ -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; @@ -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); diff --git a/core/jni/android_os_Trace.cpp b/core/jni/android_os_Trace.cpp index 1315291..01d02c5 100644 --- a/core/jni/android_os_Trace.cpp +++ b/core/jni/android_os_Trace.cpp @@ -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", @@ -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) { |