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

Commit 0d4dced8 authored by Zimuzo Ezeozue's avatar Zimuzo Ezeozue
Browse files

Remove addFlow/TerminatingFlow

setFlow and setTerminatingFlow had been added in previous cl
to replace the addFlow methods. In practice, addFlow is very
unlikely to be used to add more than one edge to an event. In
these cases, there's a noticeable performance improvement when
using setFlow which avoids the call through to Pool of Flows.

Also fixed setFlow to accept long instead of int. The underlying
structs in the C SDK support uint64_t and this was just an
oversight.

Test: atest PerfettoTraceTest
Bug: 303199244
Flag: android.os.perfetto_sdk_tracing_v2
Change-Id: I3fdcbbd09921e865052bdca359a5ffb0cfe18900
parent 139fadb0
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -147,7 +147,7 @@ public class TracePerfTest {
                .addField(1 /* sending_thread_name */, "foo")
                .endNested()
                .endProto()
                .addTerminatingFlow(5)
                .setTerminatingFlow(5)
                .emit();

        BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
@@ -158,7 +158,7 @@ public class TracePerfTest {
                    .addField(1 /* sending_thread_name */, "foo")
                    .endNested()
                    .endProto()
                    .addTerminatingFlow(5)
                    .setTerminatingFlow(5)
                    .emit();
        }
    }
+1 −1
Original line number Diff line number Diff line
@@ -232,7 +232,7 @@ public final class MessageQueue {

        traceMessageCount();
        PerfettoTrace.instant(PerfettoTrace.MQ_CATEGORY, "message_queue_send")
                .addFlow(msg.mEventId.get())
                .setFlow(msg.mEventId.get())
                .beginProto()
                .beginNested(2004 /* message_queue */)
                .addField(2 /* receiving_thread_name */, mThread.getName())
+1 −1
Original line number Diff line number Diff line
@@ -205,7 +205,7 @@ public final class Looper {
                .addField(1 /* sending_thread_name */, msg.mSendingThreadName)
                .endNested()
                .endProto()
                .addTerminatingFlow(msg.mEventId.get())
                .setTerminatingFlow(msg.mEventId.get())
                .emit();

        // This must be in a local variabe, in case a UI event sets the logger
+2 −2
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ import android.util.proto.ProtoOutputStream;

import com.android.internal.annotations.VisibleForTesting;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

/**
 *
@@ -43,7 +43,7 @@ public final class Message implements Parcelable {
     *
     * @hide Only for use within the system server.
     */
    public final AtomicInteger mEventId = new AtomicInteger();
    public final AtomicLong mEventId = new AtomicLong();

    /**
     * User-defined message code so that the recipient can identify
+2 −38
Original line number Diff line number Diff line
@@ -172,7 +172,6 @@ public final class PerfettoTrackEventExtra {
        private final Pool<FieldDouble> mFieldDoubleCache;
        private final Pool<FieldString> mFieldStringCache;
        private final Pool<FieldNested> mFieldNestedCache;
        private final Pool<Flow> mFlowCache;
        private final Pool<Builder> mBuilderCache;

        private Builder() {
@@ -187,7 +186,6 @@ public final class PerfettoTrackEventExtra {
            mFieldDoubleCache = mExtra.mFieldDoubleCache;
            mFieldStringCache = mExtra.mFieldStringCache;
            mFieldNestedCache = mExtra.mFieldNestedCache;
            mFlowCache = mExtra.mFlowCache;
            mBuilderCache = mExtra.mBuilderCache;

            mCounterInt64 = mExtra.getCounterInt64();
@@ -227,7 +225,6 @@ public final class PerfettoTrackEventExtra {
            mFieldStringCache.reset();
            mFieldNestedCache.reset();
            mBuilderCache.reset();
            mFlowCache.reset();

            mExtra.reset();
            // Reset after on init in case the thread created builders without calling emit
@@ -325,39 +322,7 @@ public final class PerfettoTrackEventExtra {
        /**
         * Adds a flow with {@code id}.
         */
        public Builder addFlow(int id) {
            if (!mIsCategoryEnabled) {
                return this;
            }
            if (DEBUG) {
                checkParent();
            }
            Flow flow = mFlowCache.get(sFlowSupplier);
            flow.setProcessFlow(id);
            mExtra.addPerfettoPointer(flow);
            return this;
        }

        /**
         * Adds a terminating flow with {@code id}.
         */
        public Builder addTerminatingFlow(int id) {
            if (!mIsCategoryEnabled) {
                return this;
            }
            if (DEBUG) {
                checkParent();
            }
            Flow flow = mFlowCache.get(sFlowSupplier);
            flow.setProcessTerminatingFlow(id);
            mExtra.addPerfettoPointer(flow);
            return this;
        }

        /**
         * Adds a flow with {@code id}.
         */
        public Builder setFlow(int id) {
        public Builder setFlow(long id) {
            if (!mIsCategoryEnabled) {
                return this;
            }
@@ -372,7 +337,7 @@ public final class PerfettoTrackEventExtra {
        /**
         * Adds a terminating flow with {@code id}.
         */
        public Builder setTerminatingFlow(int id) {
        public Builder setTerminatingFlow(long id) {
            if (!mIsCategoryEnabled) {
                return this;
            }
@@ -670,7 +635,6 @@ public final class PerfettoTrackEventExtra {
    private final Pool<FieldDouble> mFieldDoubleCache = new Pool(DEFAULT_EXTRA_CACHE_SIZE);
    private final Pool<FieldString> mFieldStringCache = new Pool(DEFAULT_EXTRA_CACHE_SIZE);
    private final Pool<FieldNested> mFieldNestedCache = new Pool(DEFAULT_EXTRA_CACHE_SIZE);
    private final Pool<Flow> mFlowCache = new Pool(DEFAULT_EXTRA_CACHE_SIZE);
    private final Pool<Builder> mBuilderCache = new Pool(DEFAULT_EXTRA_CACHE_SIZE);

    private static final NativeAllocationRegistry sRegistry =