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

Commit b0d5d53f authored by Zim's avatar Zim
Browse files

Populate binder trace txn names lazily

Previously, for each binder interface, we populated a cache of all
txn codes to names on the first binder txn to that interface. This
skewed the binder txn latency significantly for the first txn to an
interface.

Now, we lazily populate the cache on each new binder txn.

Test: atest open-prebuilt-calculator --rebuild-module-info
--tf-template metric_post_processor=
google/template/postprocessors/metric-file-aggregate.xml
(neglible startup time diff locally)
Bug: 246650647

Change-Id: Ib569ebe34e7ef6bb4fa6e53defedcb33ed824308
Merged-In: Ib569ebe34e7ef6bb4fa6e53defedcb33ed824308
parent 8314a3e5
Loading
Loading
Loading
Loading
+23 −18
Original line number Original line Diff line number Diff line
@@ -46,6 +46,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.PrintWriter;
import java.lang.reflect.Modifier;
import java.lang.reflect.Modifier;
import java.util.concurrent.atomic.AtomicReferenceArray;


/**
/**
 * Base class for a remotable object, the core part of a lightweight
 * Base class for a remotable object, the core part of a lightweight
@@ -313,7 +314,7 @@ public class Binder implements IBinder {
    private IInterface mOwner;
    private IInterface mOwner;
    @Nullable
    @Nullable
    private String mDescriptor;
    private String mDescriptor;
    private volatile String[] mTransactionTraceNames = null;
    private volatile AtomicReferenceArray<String> mTransactionTraceNames = null;
    private volatile String mSimpleDescriptor = null;
    private volatile String mSimpleDescriptor = null;
    private static final int TRANSACTION_TRACE_NAME_ID_LIMIT = 1024;
    private static final int TRANSACTION_TRACE_NAME_ID_LIMIT = 1024;


@@ -917,28 +918,32 @@ public class Binder implements IBinder {
    @VisibleForTesting
    @VisibleForTesting
    public final @NonNull String getTransactionTraceName(int transactionCode) {
    public final @NonNull String getTransactionTraceName(int transactionCode) {
        if (mTransactionTraceNames == null) {
        if (mTransactionTraceNames == null) {
            final String descriptor = getSimpleDescriptor();
            final int highestId = Math.min(getMaxTransactionId(), TRANSACTION_TRACE_NAME_ID_LIMIT);
            final int highestId = Math.min(getMaxTransactionId(), TRANSACTION_TRACE_NAME_ID_LIMIT);
            final String[] transactionNames = new String[highestId + 1];
            mSimpleDescriptor = getSimpleDescriptor();
            mTransactionTraceNames = new AtomicReferenceArray(highestId + 1);
        }

        final int index = transactionCode - FIRST_CALL_TRANSACTION;
        if (index < 0 || index >= mTransactionTraceNames.length()) {
            return mSimpleDescriptor + "#" + transactionCode;
        }

        String transactionTraceName = mTransactionTraceNames.getAcquire(index);
        if (transactionTraceName == null) {
            final String transactionName = getTransactionName(transactionCode);
            final StringBuffer buf = new StringBuffer();
            final StringBuffer buf = new StringBuffer();
            for (int i = 0; i <= highestId; i++) {

                String transactionName = getTransactionName(i + FIRST_CALL_TRANSACTION);
            if (transactionName != null) {
            if (transactionName != null) {
                    buf.append(descriptor).append(':').append(transactionName);
                buf.append(mSimpleDescriptor).append(":").append(transactionName);
            } else {
            } else {
                    buf.append(descriptor).append('#').append(i + FIRST_CALL_TRANSACTION);
                buf.append(mSimpleDescriptor).append("#").append(transactionCode);
            }
            }
                transactionNames[i] = buf.toString();

                buf.setLength(0);
            transactionTraceName = buf.toString();
            }
            mTransactionTraceNames.setRelease(index, transactionTraceName);
            mSimpleDescriptor = descriptor;
            mTransactionTraceNames = transactionNames;
        }
        final int index = transactionCode - FIRST_CALL_TRANSACTION;
        if (index < 0 || index >= mTransactionTraceNames.length) {
            return mSimpleDescriptor + "#" + transactionCode;
        }
        }
        return mTransactionTraceNames[index];

        return transactionTraceName;
    }
    }


    private @NonNull String getSimpleDescriptor() {
    private @NonNull String getSimpleDescriptor() {