Revert "bionic_systrace: moving global static variables"

This reverts commit 1e1c7845aa.

Reason for revert: makes property get/set non-reentrant

Bug: 193050299
Test: build and boot a device
Change-Id: If59e3dc25684a3c2b1d3ff74f995311afe6c6e89
Merged-In: If59e3dc25684a3c2b1d3ff74f995311afe6c6e89
(cherry picked from commit 3ec21f527a)
This commit is contained in:
Bowgo Tsai 2021-07-15 09:46:53 +00:00
parent e9b672b3e0
commit 2ebdb61620

View file

@ -31,29 +31,33 @@
#define WRITE_OFFSET 32
static Lock g_lock;
static uint64_t g_tags;
static int g_trace_marker_fd = -1;
static CachedProperty& GetTagsProp() {
static CachedProperty cached_property(kTraceTagsProp);
return cached_property;
}
bool should_trace(const uint64_t enable_tags) {
static uint64_t tags_val;
static CachedProperty tags_prop(kTraceTagsProp);
g_lock.lock();
if (tags_prop.DidChange()) {
tags_val = strtoull(tags_prop.Get(), nullptr, 0);
if (GetTagsProp().DidChange()) {
g_tags = strtoull(GetTagsProp().Get(), nullptr, 0);
}
g_lock.unlock();
return tags_val & enable_tags;
return g_tags & enable_tags;
}
int get_trace_marker_fd() {
static int opened_trace_marker_fd = -1;
g_lock.lock();
if (opened_trace_marker_fd == -1) {
opened_trace_marker_fd = open("/sys/kernel/tracing/trace_marker", O_CLOEXEC | O_WRONLY);
if (opened_trace_marker_fd == -1) {
opened_trace_marker_fd = open("/sys/kernel/debug/tracing/trace_marker", O_CLOEXEC | O_WRONLY);
if (g_trace_marker_fd == -1) {
g_trace_marker_fd = open("/sys/kernel/tracing/trace_marker", O_CLOEXEC | O_WRONLY);
if (g_trace_marker_fd == -1) {
g_trace_marker_fd = open("/sys/kernel/debug/tracing/trace_marker", O_CLOEXEC | O_WRONLY);
}
}
g_lock.unlock();
return opened_trace_marker_fd;
return g_trace_marker_fd;
}
// event could be 'B' for begin or 'E' for end.