Merge "Always use shared memory for atrace." am: 2ddc5a1932

Change-Id: I178514bd3d57cd406f2e243a1856a2a13d0326f8
This commit is contained in:
Automerger Merge Worker 2020-02-27 10:49:04 +00:00
commit 3d9c20fefd
4 changed files with 15 additions and 59 deletions

View file

@ -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.

View file

@ -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)

View file

@ -71,8 +71,6 @@ alignas(uint64_t) static char empty_pi[96];
static const prop_info* atrace_property_info = reinterpret_cast<const prop_info*>(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);
}
}

View file

@ -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