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

Commit e4a23a99 authored by Dominik Laskowski's avatar Dominik Laskowski
Browse files

gui: Evaluate ATRACE_FORMAT arguments lazily

Avoid evaluation unless tracing is enabled.

Bug: 241285473
Test: Perfetto
Change-Id: I41c446995dd37a68063d65307031ff543ee51354
parent fdff5cde
Loading
Loading
Loading
Loading
+10 −14
Original line number Diff line number Diff line
@@ -22,12 +22,13 @@
#include <utils/Trace.h>

#define ATRACE_FORMAT(fmt, ...)                                                 \
    TraceUtils::TraceEnder __traceEnder = \
            (TraceUtils::atraceFormatBegin(fmt, ##__VA_ARGS__), TraceUtils::TraceEnder())
    TraceUtils::TraceEnder traceEnder =                                         \
            (CC_UNLIKELY(ATRACE_ENABLED()) &&                                   \
                     (TraceUtils::atraceFormatBegin(fmt, ##__VA_ARGS__), true), \
             TraceUtils::TraceEnder())

#define ATRACE_FORMAT_BEGIN(fmt, ...) TraceUtils::atraceFormatBegin(fmt, ##__VA_ARGS__)

#define ATRACE_FORMAT_INSTANT(fmt, ...) TraceUtils::intantFormat(fmt, ##__VA_ARGS__)
#define ATRACE_FORMAT_INSTANT(fmt, ...) \
    (CC_UNLIKELY(ATRACE_ENABLED()) && (TraceUtils::instantFormat(fmt, ##__VA_ARGS__), true))

namespace android {

@@ -39,8 +40,6 @@ public:
    };

    static void atraceFormatBegin(const char* fmt, ...) {
        if (CC_LIKELY(!ATRACE_ENABLED())) return;

        const int BUFFER_SIZE = 256;
        va_list ap;
        char buf[BUFFER_SIZE];
@@ -52,9 +51,7 @@ public:
        ATRACE_BEGIN(buf);
    }

    static void intantFormat(const char* fmt, ...) {
        if (CC_LIKELY(!ATRACE_ENABLED())) return;

    static void instantFormat(const char* fmt, ...) {
        const int BUFFER_SIZE = 256;
        va_list ap;
        char buf[BUFFER_SIZE];
@@ -65,7 +62,6 @@ public:

        ATRACE_INSTANT(buf);
    }
};

}; // class TraceUtils

} /* namespace android */
} // namespace android