summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libs/tracing_perfetto/tracing_perfetto.cpp3
-rw-r--r--libs/tracing_perfetto/tracing_perfetto_internal.cpp14
-rw-r--r--libs/tracing_perfetto/tracing_perfetto_internal.h2
3 files changed, 12 insertions, 7 deletions
diff --git a/libs/tracing_perfetto/tracing_perfetto.cpp b/libs/tracing_perfetto/tracing_perfetto.cpp
index c7fb8bd9a8..19d1eb639e 100644
--- a/libs/tracing_perfetto/tracing_perfetto.cpp
+++ b/libs/tracing_perfetto/tracing_perfetto.cpp
@@ -131,7 +131,8 @@ Result traceCounter(uint64_t category, const char* name, int64_t value) {
}
uint64_t getEnabledCategories() {
- if (internal::isPerfettoSdkTracingEnabled()) {
+ if (internal::isPerfettoRegistered()) {
+ // TODO(b/303199244): Return only enabled categories and not all registered ones
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 58ba428610..758ace63ab 100644
--- a/libs/tracing_perfetto/tracing_perfetto_internal.cpp
+++ b/libs/tracing_perfetto/tracing_perfetto_internal.cpp
@@ -70,6 +70,8 @@ PERFETTO_TE_CATEGORIES_DECLARE(FRAMEWORK_CATEGORIES);
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:
@@ -135,25 +137,26 @@ struct PerfettoTeCategory* toCategory(uint64_t inCategory) {
} // namespace
-bool isPerfettoSdkTracingEnabled() {
- return android::os::perfetto_sdk_tracing();
+bool isPerfettoRegistered() {
+ return is_perfetto_registered;
}
struct PerfettoTeCategory* toPerfettoCategory(uint64_t category) {
- if (!isPerfettoSdkTracingEnabled()) {
+ struct PerfettoTeCategory* perfettoCategory = toCategory(category);
+ if (perfettoCategory == nullptr) {
return nullptr;
}
- struct PerfettoTeCategory* perfettoCategory = toCategory(category);
bool enabled = PERFETTO_UNLIKELY(PERFETTO_ATOMIC_LOAD_EXPLICIT(
(*perfettoCategory).enabled, PERFETTO_MEMORY_ORDER_RELAXED));
return enabled ? perfettoCategory : nullptr;
}
void registerWithPerfetto(bool test) {
- if (!isPerfettoSdkTracingEnabled()) {
+ if (!android::os::perfetto_sdk_tracing()) {
return;
}
+
static std::once_flag registration;
std::call_once(registration, [test]() {
struct PerfettoProducerInitArgs args = PERFETTO_PRODUCER_INIT_ARGS_INIT();
@@ -161,6 +164,7 @@ void registerWithPerfetto(bool test) {
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 9a579f162a..79e4b8f1b4 100644
--- a/libs/tracing_perfetto/tracing_perfetto_internal.h
+++ b/libs/tracing_perfetto/tracing_perfetto_internal.h
@@ -26,7 +26,7 @@ namespace tracing_perfetto {
namespace internal {
-bool isPerfettoSdkTracingEnabled();
+bool isPerfettoRegistered();
struct PerfettoTeCategory* toPerfettoCategory(uint64_t category);