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

Commit 555c7b32 authored by Zimuzo Ezeozue's avatar Zimuzo Ezeozue
Browse files

Wrapped mq tracing in explicit tracing enabled checks

There's a tiny performance hit when tracing protos even when disabled.
Calling into the no-op builders has some costs so now we return early
if tracing disabled.

Test: Manual
Flag: android.os.perfetto_sdk_tracing_v2
Bug: 303199244
Change-Id: I8a8433a5f4c9e12ba6299d356dabe55fc4488ffe
parent 48cbafb9
Loading
Loading
Loading
Loading
+19 −15
Original line number Diff line number Diff line
@@ -222,11 +222,14 @@ public final class MessageQueue {

    private void decAndTraceMessageCount() {
        mMessageCount.decrementAndGet();
        if (PerfettoTrace.MQ_CATEGORY.isEnabled()) {
            traceMessageCount();
        }
    }

    private void incAndTraceMessageCount(Message msg, long when) {
        mMessageCount.incrementAndGet();
        if (PerfettoTrace.MQ_CATEGORY.isEnabled()) {
            msg.mSendingThreadName = Thread.currentThread().getName();
            msg.mEventId.set(PerfettoTrace.getFlowId());

@@ -242,6 +245,7 @@ public final class MessageQueue {
                    .endProto()
                    .emit();
        }
    }

    /** @hide */
    private void traceMessageCount() {
+13 −9
Original line number Diff line number Diff line
@@ -199,6 +199,7 @@ public final class Looper {
            return false;
        }

        if (PerfettoTrace.MQ_CATEGORY.isEnabled()) {
            PerfettoTrace.begin(PerfettoTrace.MQ_CATEGORY, "message_queue_receive")
                    .beginProto()
                    .beginNested(2004 /* message_queue */)
@@ -207,6 +208,7 @@ public final class Looper {
                    .endProto()
                    .setTerminatingFlow(msg.mEventId.get())
                    .emit();
        }

        // This must be in a local variabe, in case a UI event sets the logger
        final Printer logging = me.mLogging;
@@ -297,8 +299,10 @@ public final class Looper {
                    + msg.target.getClass().getName() + " "
                    + msg.callback + " what=" + msg.what);
        }

        if (PerfettoTrace.MQ_CATEGORY.isEnabled()) {
            PerfettoTrace.end(PerfettoTrace.MQ_CATEGORY).emit();
        }

        msg.recycleUnchecked();

        return true;