diff options
author | Jamie Gennis <jgennis@google.com> | 2013-04-15 18:50:22 -0700 |
---|---|---|
committer | Jamie Gennis <jgennis@google.com> | 2013-04-15 18:50:22 -0700 |
commit | b13ea45a04a463646a7098b03f9f64d91b29d2b9 (patch) | |
tree | 324e55f069a345d493d4513d3121ed8305e2f549 /libcutils | |
parent | c796ed97466510dd5239008554decbe72825e19c (diff) | |
download | system_core-b13ea45a04a463646a7098b03f9f64d91b29d2b9.zip system_core-b13ea45a04a463646a7098b03f9f64d91b29d2b9.tar.gz system_core-b13ea45a04a463646a7098b03f9f64d91b29d2b9.tar.bz2 |
cutils: add a way to disable tracing for a process
This change adds the atrace_set_tracing_enabled call to libcutils. The call
can be used to disable all tracing (of the atrace variety) for the current
process. This is to be used to disable tracing in the Zygote process, as there
is no way for Zygote to be notified of changes to the enabled trace tags.
Change-Id: I0b691cc0dcfc65b16e3d17e1db2866a4deb253a7
Diffstat (limited to 'libcutils')
-rw-r--r-- | libcutils/trace.c | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/libcutils/trace.c b/libcutils/trace.c index 047f889..9754a44 100644 --- a/libcutils/trace.c +++ b/libcutils/trace.c @@ -30,12 +30,13 @@ #define LOG_TAG "cutils-trace" #include <cutils/log.h> -int32_t atrace_is_ready = 0; -int atrace_marker_fd = -1; -uint64_t atrace_enabled_tags = ATRACE_TAG_NOT_READY; -static bool atrace_is_debuggable = false; -static pthread_once_t atrace_once_control = PTHREAD_ONCE_INIT; -static pthread_mutex_t atrace_tags_mutex = PTHREAD_MUTEX_INITIALIZER; +volatile int32_t atrace_is_ready = 0; +int atrace_marker_fd = -1; +uint64_t atrace_enabled_tags = ATRACE_TAG_NOT_READY; +static bool atrace_is_debuggable = false; +static volatile int32_t atrace_is_enabled = 1; +static pthread_once_t atrace_once_control = PTHREAD_ONCE_INIT; +static pthread_mutex_t atrace_tags_mutex = PTHREAD_MUTEX_INITIALIZER; // Set whether this process is debuggable, which determines whether // application-level tracing is allowed when the ro.debuggable system property @@ -46,9 +47,18 @@ void atrace_set_debuggable(bool debuggable) atrace_update_tags(); } +// Set whether tracing is enabled in this process. This is used to prevent +// the Zygote process from tracing. +void atrace_set_tracing_enabled(bool enabled) +{ + android_atomic_release_store(enabled ? 1 : 0, &atrace_is_enabled); + atrace_update_tags(); +} + // Check whether the given command line matches one of the comma-separated // values listed in the app_cmdlines property. -static bool atrace_is_cmdline_match(const char* cmdline) { +static bool atrace_is_cmdline_match(const char* cmdline) +{ char value[PROPERTY_VALUE_MAX]; char* start = value; @@ -140,10 +150,18 @@ void atrace_update_tags() { uint64_t tags; if (CC_UNLIKELY(android_atomic_acquire_load(&atrace_is_ready))) { - tags = atrace_get_property(); - pthread_mutex_lock(&atrace_tags_mutex); - atrace_enabled_tags = tags; - pthread_mutex_unlock(&atrace_tags_mutex); + if (android_atomic_acquire_load(&atrace_is_enabled)) { + tags = atrace_get_property(); + pthread_mutex_lock(&atrace_tags_mutex); + atrace_enabled_tags = tags; + pthread_mutex_unlock(&atrace_tags_mutex); + } else { + // Tracing is disabled for this process, so we simply don't + // initialize the tags. + pthread_mutex_lock(&atrace_tags_mutex); + atrace_enabled_tags = ATRACE_TAG_NOT_READY; + pthread_mutex_unlock(&atrace_tags_mutex); + } } } |