Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 81deab75 authored by Zim's avatar Zim
Browse files

Fix libtracing_perfetto performance impact

1. Avoided checking isPerfettoSdkTracingEnabled on each tracing call.

We already checked that before registering perfetto and if the flag was
false, toPerfettoCategory will never return a valid category hence we'll
fallback to atrace.

2. Added an isPerfettoRegistered check that encapsulates the sdk check
for use in getEnabledCategories. This allows us skip the sdk check there

We'll need to fix result of getEnabledCategories to only return enabled
categories and not just registered ones, but since the flag is off this
it's fine for now and can address in a separate cl.

Test: atest libtracing_perfetto_tests
Bug: 328942318
Bug: 303199244
Change-Id: Ic8fdebd20aba4ac75566c1a1590667891745b92a
parent b8aebd57
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -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();
+7 −7
Original line number Diff line number Diff line
@@ -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,15 +137,11 @@ 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()) {
    return nullptr;
  }

  struct PerfettoTeCategory* perfettoCategory = toCategory(category);
  bool enabled = PERFETTO_UNLIKELY(PERFETTO_ATOMIC_LOAD_EXPLICIT(
      (*perfettoCategory).enabled, PERFETTO_MEMORY_ORDER_RELAXED));
@@ -151,9 +149,10 @@ struct PerfettoTeCategory* toPerfettoCategory(uint64_t category) {
}

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 +160,7 @@ void registerWithPerfetto(bool test) {
    PerfettoProducerInit(args);
    PerfettoTeInit();
    PERFETTO_TE_REGISTER_CATEGORIES(FRAMEWORK_CATEGORIES);
    is_perfetto_registered = true;
  });
}

+1 −1
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ namespace tracing_perfetto {

namespace internal {

bool isPerfettoSdkTracingEnabled();
bool isPerfettoRegistered();

struct PerfettoTeCategory* toPerfettoCategory(uint64_t category);