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

Commit fcc32aa4 authored by Zim's avatar Zim
Browse files

Enable perfetto tracing for non-autogenerated AIDL names

Since we added AIDL name tracing globally, it's been a very powerfull
tool to root cause issues in the field. One gap is non-autogenerated
AIDL interfaces like ContentProvider and Cursor. This was explicitly
disabled in aosp/2254719 to workaround some unrealistic perf startup
issue. Given the gap in identifying more important issues in the field
it's worth enabling this so we can fix 'real' problems.

Enabled caching of the non-autogenerated AIDLs and also added the
'AIDL::java' prefix to the name of the non-autogenerated AIDL names
to be consistent with the autogenerated ones.

Bug: 288578300
Bug: 270044534
Test: atest AidlTest
Change-Id: I96633ec976db01991620b43d7a7e9528ea22de1f
parent c3199051
Loading
Loading
Loading
Loading
+9 −16
Original line number Diff line number Diff line
@@ -943,16 +943,19 @@ public class Binder implements IBinder {
     * @hide
     */
    @VisibleForTesting
    public final @NonNull String getTransactionTraceName(int transactionCode) {
    public final @Nullable String getTransactionTraceName(int transactionCode) {
        final boolean isInterfaceUserDefined = getMaxTransactionId() == 0;
        if (mTransactionTraceNames == null) {
            final int highestId = Math.min(getMaxTransactionId(), TRANSACTION_TRACE_NAME_ID_LIMIT);
            final int highestId = isInterfaceUserDefined ? TRANSACTION_TRACE_NAME_ID_LIMIT
                    : Math.min(getMaxTransactionId(), TRANSACTION_TRACE_NAME_ID_LIMIT);
            mSimpleDescriptor = getSimpleDescriptor();
            mTransactionTraceNames = new AtomicReferenceArray(highestId + 1);
        }

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

        String transactionTraceName = mTransactionTraceNames.getAcquire(index);
@@ -1317,19 +1320,9 @@ public class Binder implements IBinder {
        final boolean hasFullyQualifiedName = getMaxTransactionId() > 0;
        final String transactionTraceName;

        if (tagEnabled && hasFullyQualifiedName) {
        if (tagEnabled) {
            // If tracing enabled and we have a fully qualified name, fetch the name
            transactionTraceName = getTransactionTraceName(code);
        } else if (tagEnabled && isStackTrackingEnabled()) {
            // If tracing is enabled and we *don't* have a fully qualified name, fetch the
            // 'best effort' name only for stack tracking. This works around noticeable perf impact
            // on low latency binder calls (<100us). The tracing call itself is between (1-10us) and
            // the perf impact can be quite noticeable while benchmarking such binder calls.
            // The primary culprits are ContentProviders and Cursors which convenienty don't
            // autogenerate their AIDL and hence will not have a fully qualified name.
            //
            // TODO(b/253426478): Relax this constraint after a more robust fix
            transactionTraceName = getTransactionTraceName(code);
        } else {
            transactionTraceName = null;
        }
+25 −8
Original line number Diff line number Diff line
@@ -28,12 +28,14 @@ public class AidlTest extends TestCase {

    private IAidlTest mRemote;
    private AidlObject mLocal;
    private NonAutoGeneratedObject mNonAutoGenerated;

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        mLocal = new AidlObject();
        mRemote = IAidlTest.Stub.asInterface(mLocal);
        mNonAutoGenerated = new NonAutoGeneratedObject("NonAutoGeneratedObject");
    }

    private static boolean check(TestParcelable p, int n, String s) {
@@ -84,6 +86,12 @@ public class AidlTest extends TestCase {
        }
    }

    private static class NonAutoGeneratedObject extends Binder {
        NonAutoGeneratedObject(String descriptor) {
            super(descriptor);
        }
    }

    private static class AidlObject extends IAidlTest.Stub {
        public IInterface queryLocalInterface(String descriptor) {
            // overriding this to return null makes asInterface always
@@ -420,7 +428,7 @@ public class AidlTest extends TestCase {
    }

    @SmallTest
    public void testGetTransactionName() throws Exception {
    public void testGetTransactionNameAutoGenerated() throws Exception {
        assertEquals(15, mLocal.getMaxTransactionId());

        assertEquals("booleanArray",
@@ -430,12 +438,21 @@ public class AidlTest extends TestCase {
        assertEquals("parcelableIn",
                mLocal.getTransactionName(IAidlTest.Stub.TRANSACTION_parcelableIn));

        assertEquals("IAidlTest:booleanArray",
        assertEquals("AIDL::java::IAidlTest::booleanArray::server",
                mLocal.getTransactionTraceName(IAidlTest.Stub.TRANSACTION_booleanArray));
        assertEquals("IAidlTest:voidSecurityException",
        assertEquals("AIDL::java::IAidlTest::voidSecurityException::server",
                mLocal.getTransactionTraceName(IAidlTest.Stub.TRANSACTION_voidSecurityException));
        assertEquals("IAidlTest:parcelableIn",
        assertEquals("AIDL::java::IAidlTest::parcelableIn::server",
                mLocal.getTransactionTraceName(IAidlTest.Stub.TRANSACTION_parcelableIn));
    }
}

    @SmallTest
    public void testGetTransactionNameNonAutoGenerated() throws Exception {
        assertEquals(0, mNonAutoGenerated.getMaxTransactionId());

        assertEquals("AIDL::java::NonAutoGeneratedObject::#0::server",
                mNonAutoGenerated.getTransactionTraceName(0));
        assertEquals("AIDL::java::NonAutoGeneratedObject::#1::server",
                mNonAutoGenerated.getTransactionTraceName(1));
    }
}