From fc0adaf89e0a4b40c0117084215379e3a9048691 Mon Sep 17 00:00:00 2001 From: Florian Mayer Date: Wed, 26 Feb 2020 11:44:04 +0000 Subject: [PATCH] Always use shared memory for atrace. Remove ATRACE_SHMEM macro. Test: atrace ss atrace wm sanity check output Bug: 137366208 Change-Id: I1b42243678b9b9a41db18e2ff8cb3cf7bde874de --- libcutils/include/cutils/trace.h | 38 ++++---------------------------- libcutils/trace-dev.cpp | 7 ------ libcutils/trace-dev.inc | 27 +++++++++-------------- libcutils/trace-host.cpp | 2 -- 4 files changed, 15 insertions(+), 59 deletions(-) diff --git a/libcutils/include/cutils/trace.h b/libcutils/include/cutils/trace.h index e12c32cff..c74ee3e9d 100644 --- a/libcutils/include/cutils/trace.h +++ b/libcutils/include/cutils/trace.h @@ -88,12 +88,6 @@ __BEGIN_DECLS #error ATRACE_TAG must be defined to be one of the tags defined in cutils/trace.h #endif -// Set this to 0 to revert to the old Binder-based atrace implementation. -// This is only here in case rollbacks do not apply cleanly. -// TODO(fmayer): Remove this once we are confident this won't need to be -// rolled back, no later than 2020-03-01. -#define ATRACE_SHMEM 1 - /** * Opens the trace file for writing and reads the property for initial tags. * The atrace.tags.enableflags property sets the tags to trace. @@ -121,15 +115,11 @@ void atrace_set_debuggable(bool debuggable); * prevent tracing within the Zygote process. */ void atrace_set_tracing_enabled(bool enabled); + /** - * If !ATRACE_SHMEM: - * Flag indicating whether setup has been completed, initialized to 0. - * Nonzero indicates setup has completed. - * Note: This does NOT indicate whether or not setup was successful. - * If ATRACE_SHMEM: - * This is always set to false. This forces code that uses an old version - * of this header to always call into atrace_setup, in which we call - * atrace_init unconditionally. + * This is always set to false. This forces code that uses an old version + * of this header to always call into atrace_setup, in which we call + * atrace_init unconditionally. */ extern atomic_bool atrace_is_ready; @@ -154,28 +144,8 @@ extern int atrace_marker_fd; #define ATRACE_INIT() atrace_init() #define ATRACE_GET_ENABLED_TAGS() atrace_get_enabled_tags() -#if ATRACE_SHMEM void atrace_init(); uint64_t atrace_get_enabled_tags(); -#else -static inline void atrace_init() -{ - if (CC_UNLIKELY(!atomic_load_explicit(&atrace_is_ready, memory_order_acquire))) { - atrace_setup(); - } -} - -/** - * Get the mask of all tags currently enabled. - * It can be used as a guard condition around more expensive trace calculations. - * Every trace function calls this, which ensures atrace_init is run. - */ -static inline uint64_t atrace_get_enabled_tags() -{ - atrace_init(); - return atrace_enabled_tags; -} -#endif /** * Test if a given tag is currently enabled. diff --git a/libcutils/trace-dev.cpp b/libcutils/trace-dev.cpp index 9ca172973..5a09a2d39 100644 --- a/libcutils/trace-dev.cpp +++ b/libcutils/trace-dev.cpp @@ -41,9 +41,6 @@ static void atrace_init_once() } else { atrace_enabled_tags = atrace_get_property(); } -#if !ATRACE_SHMEM - atomic_store_explicit(&atrace_is_ready, true, memory_order_release); -#endif } static void atrace_seq_number_changed(uint32_t prev_seq_no, uint32_t seq_no) { @@ -69,11 +66,7 @@ static void atrace_seq_number_changed(uint32_t prev_seq_no, uint32_t seq_no) { void atrace_setup() { -#if ATRACE_SHMEM atrace_init(); -#else - pthread_once(&atrace_once_control, atrace_init_once); -#endif } void atrace_begin_body(const char* name) diff --git a/libcutils/trace-dev.inc b/libcutils/trace-dev.inc index a57a4c59e..3ec98b3a6 100644 --- a/libcutils/trace-dev.inc +++ b/libcutils/trace-dev.inc @@ -71,8 +71,6 @@ alignas(uint64_t) static char empty_pi[96]; static const prop_info* atrace_property_info = reinterpret_cast(empty_pi); #endif -#if ATRACE_SHMEM - /** * This is called when the sequence number of debug.atrace.tags.enableflags * changes and we need to reload the enabled tags. @@ -96,7 +94,6 @@ uint64_t atrace_get_enabled_tags() atrace_init(); return atrace_enabled_tags; } -#endif // Set whether this process is debuggable, which determines whether // application-level tracing is allowed when the ro.debuggable system property @@ -186,19 +183,17 @@ static uint64_t atrace_get_property() void atrace_update_tags() { uint64_t tags; - if (ATRACE_SHMEM || CC_UNLIKELY(atomic_load_explicit(&atrace_is_ready, memory_order_acquire))) { - if (atomic_load_explicit(&atrace_is_enabled, memory_order_acquire)) { - 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); - } + if (atomic_load_explicit(&atrace_is_enabled, memory_order_acquire)) { + 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); } } diff --git a/libcutils/trace-host.cpp b/libcutils/trace-host.cpp index c21d0ee5e..9781ad3e4 100644 --- a/libcutils/trace-host.cpp +++ b/libcutils/trace-host.cpp @@ -30,10 +30,8 @@ void atrace_async_begin_body(const char* /*name*/, int32_t /*cookie*/) {} void atrace_async_end_body(const char* /*name*/, int32_t /*cookie*/) {} void atrace_int_body(const char* /*name*/, int32_t /*value*/) {} void atrace_int64_body(const char* /*name*/, int64_t /*value*/) {} -#if ATRACE_SHMEM void atrace_init() {} uint64_t atrace_get_enabled_tags() { return ATRACE_TAG_NOT_READY; } -#endif