Merge "Revert "Fix libtracing_perfetto performance impact"" into main
diff --git a/libs/tracing_perfetto/tracing_perfetto.cpp b/libs/tracing_perfetto/tracing_perfetto.cpp
index 19d1eb6..c7fb8bd 100644
--- a/libs/tracing_perfetto/tracing_perfetto.cpp
+++ b/libs/tracing_perfetto/tracing_perfetto.cpp
@@ -131,8 +131,7 @@
}
uint64_t getEnabledCategories() {
- if (internal::isPerfettoRegistered()) {
- // TODO(b/303199244): Return only enabled categories and not all registered ones
+ if (internal::isPerfettoSdkTracingEnabled()) {
return internal::getDefaultCategories();
} else {
return atrace_get_enabled_tags();
diff --git a/libs/tracing_perfetto/tracing_perfetto_internal.cpp b/libs/tracing_perfetto/tracing_perfetto_internal.cpp
index 976db7e..58ba428 100644
--- a/libs/tracing_perfetto/tracing_perfetto_internal.cpp
+++ b/libs/tracing_perfetto/tracing_perfetto_internal.cpp
@@ -70,8 +70,6 @@
PERFETTO_TE_CATEGORIES_DEFINE(FRAMEWORK_CATEGORIES);
-std::atomic_bool is_perfetto_registered = false;
-
struct PerfettoTeCategory* toCategory(uint64_t inCategory) {
switch (inCategory) {
case TRACE_CATEGORY_ALWAYS:
@@ -137,11 +135,15 @@
} // namespace
-bool isPerfettoRegistered() {
- return is_perfetto_registered;
+bool isPerfettoSdkTracingEnabled() {
+ return android::os::perfetto_sdk_tracing();
}
struct PerfettoTeCategory* toPerfettoCategory(uint64_t category) {
+ if (!isPerfettoSdkTracingEnabled()) {
+ return nullptr;
+ }
+
struct PerfettoTeCategory* perfettoCategory = toCategory(category);
bool enabled = PERFETTO_UNLIKELY(PERFETTO_ATOMIC_LOAD_EXPLICIT(
(*perfettoCategory).enabled, PERFETTO_MEMORY_ORDER_RELAXED));
@@ -149,10 +151,9 @@
}
void registerWithPerfetto(bool test) {
- if (!android::os::perfetto_sdk_tracing()) {
+ if (!isPerfettoSdkTracingEnabled()) {
return;
}
-
static std::once_flag registration;
std::call_once(registration, [test]() {
struct PerfettoProducerInitArgs args = PERFETTO_PRODUCER_INIT_ARGS_INIT();
@@ -160,7 +161,6 @@
PerfettoProducerInit(args);
PerfettoTeInit();
PERFETTO_TE_REGISTER_CATEGORIES(FRAMEWORK_CATEGORIES);
- is_perfetto_registered = true;
});
}
diff --git a/libs/tracing_perfetto/tracing_perfetto_internal.h b/libs/tracing_perfetto/tracing_perfetto_internal.h
index 79e4b8f..9a579f1 100644
--- a/libs/tracing_perfetto/tracing_perfetto_internal.h
+++ b/libs/tracing_perfetto/tracing_perfetto_internal.h
@@ -26,7 +26,7 @@
namespace internal {
-bool isPerfettoRegistered();
+bool isPerfettoSdkTracingEnabled();
struct PerfettoTeCategory* toPerfettoCategory(uint64_t category);