diff options
author | 2024-03-14 17:18:09 +0000 | |
---|---|---|
committer | 2024-03-14 17:18:09 +0000 | |
commit | cd6024fb88e4fef7843110f91108ae89789114e7 (patch) | |
tree | 92d4e130d400ab462f9e20b2373ce5a099679507 | |
parent | 70c5c4b0910dbd32fc76e62b65c9a12dd8245e4c (diff) |
Fix check for whether a trace tag is enabled
With the introduction of libperfetto_tracing, we need to check both
perfetto track_events and atrace categories to determine if a trace
tag is enabled. Perfetto SDK doesn't expose a list (or bitmask) of
all enabled categories, but we can check if a specific category is
enabled.
Rewrote the internal impl for Trace#isTagEnabled to pass the tag into
native and return a boolean instead of getting all the enabled tags
from native and checking in Java.
Test: atest libtracing_perfetto_tests
Bug: 303199244
Change-Id: I175deb4d03fef486e4a2d571c8a8f1fbde220f36
-rw-r--r-- | libs/tracing_perfetto/include/tracing_perfetto.h | 2 | ||||
-rw-r--r-- | libs/tracing_perfetto/tracing_perfetto.cpp | 11 |
2 files changed, 7 insertions, 6 deletions
diff --git a/libs/tracing_perfetto/include/tracing_perfetto.h b/libs/tracing_perfetto/include/tracing_perfetto.h index 4e3c83fca3..2c1c2a49e7 100644 --- a/libs/tracing_perfetto/include/tracing_perfetto.h +++ b/libs/tracing_perfetto/include/tracing_perfetto.h @@ -46,7 +46,7 @@ Result traceInstantForTrack(uint64_t category, const char* trackName, Result traceCounter(uint64_t category, const char* name, int64_t value); -uint64_t getEnabledCategories(); +bool isTagEnabled(uint64_t category); } // namespace tracing_perfetto diff --git a/libs/tracing_perfetto/tracing_perfetto.cpp b/libs/tracing_perfetto/tracing_perfetto.cpp index 19d1eb639e..6f716eea9a 100644 --- a/libs/tracing_perfetto/tracing_perfetto.cpp +++ b/libs/tracing_perfetto/tracing_perfetto.cpp @@ -130,12 +130,13 @@ Result traceCounter(uint64_t category, const char* name, int64_t value) { } } -uint64_t getEnabledCategories() { - if (internal::isPerfettoRegistered()) { - // TODO(b/303199244): Return only enabled categories and not all registered ones - return internal::getDefaultCategories(); +bool isTagEnabled(uint64_t category) { + struct PerfettoTeCategory* perfettoTeCategory = + internal::toPerfettoCategory(category); + if (perfettoTeCategory != nullptr) { + return true; } else { - return atrace_get_enabled_tags(); + return (atrace_get_enabled_tags() & category) != 0; } } |