summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Biswarup Pal <biswarupp@google.com> 2024-03-13 22:40:41 +0000
committer Biswarup Pal <biswarupp@google.com> 2024-03-13 22:41:46 +0000
commitc289da6c3aa4022fd92004e263e7f2554fef01a9 (patch)
tree6f6a07f83715ee639be3011864651e7dabaf2161
parenta3d2ec8a4c9b51494425d751870620e682d31eb8 (diff)
Revert^2 "Fix libtracing_perfetto performance impact"
This reverts commit a3d2ec8a4c9b51494425d751870620e682d31eb8. Reason for revert: Fix missing null check Change-Id: Iafa241f158bbf59e1c81cb06ee587de7458750cf
-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);