Merge "Enable perfetto tracing for non-autogenerated AIDL names" into main
This commit is contained in:
@@ -943,16 +943,19 @@ public class Binder implements IBinder {
|
|||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public final @NonNull String getTransactionTraceName(int transactionCode) {
|
public final @Nullable String getTransactionTraceName(int transactionCode) {
|
||||||
|
final boolean isInterfaceUserDefined = getMaxTransactionId() == 0;
|
||||||
if (mTransactionTraceNames == null) {
|
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();
|
mSimpleDescriptor = getSimpleDescriptor();
|
||||||
mTransactionTraceNames = new AtomicReferenceArray(highestId + 1);
|
mTransactionTraceNames = new AtomicReferenceArray(highestId + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
final int index = transactionCode - FIRST_CALL_TRANSACTION;
|
final int index = isInterfaceUserDefined
|
||||||
if (index < 0 || index >= mTransactionTraceNames.length()) {
|
? transactionCode : transactionCode - FIRST_CALL_TRANSACTION;
|
||||||
return mSimpleDescriptor + "#" + transactionCode;
|
if (index >= mTransactionTraceNames.length() || index < 0) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
String transactionTraceName = mTransactionTraceNames.getAcquire(index);
|
String transactionTraceName = mTransactionTraceNames.getAcquire(index);
|
||||||
@@ -1317,19 +1320,9 @@ public class Binder implements IBinder {
|
|||||||
final boolean hasFullyQualifiedName = getMaxTransactionId() > 0;
|
final boolean hasFullyQualifiedName = getMaxTransactionId() > 0;
|
||||||
final String transactionTraceName;
|
final String transactionTraceName;
|
||||||
|
|
||||||
if (tagEnabled && hasFullyQualifiedName) {
|
if (tagEnabled) {
|
||||||
// If tracing enabled and we have a fully qualified name, fetch the name
|
// If tracing enabled and we have a fully qualified name, fetch the name
|
||||||
transactionTraceName = getTransactionTraceName(code);
|
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 {
|
} else {
|
||||||
transactionTraceName = null;
|
transactionTraceName = null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,12 +28,14 @@ public class AidlTest extends TestCase {
|
|||||||
|
|
||||||
private IAidlTest mRemote;
|
private IAidlTest mRemote;
|
||||||
private AidlObject mLocal;
|
private AidlObject mLocal;
|
||||||
|
private NonAutoGeneratedObject mNonAutoGenerated;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
mLocal = new AidlObject();
|
mLocal = new AidlObject();
|
||||||
mRemote = IAidlTest.Stub.asInterface(mLocal);
|
mRemote = IAidlTest.Stub.asInterface(mLocal);
|
||||||
|
mNonAutoGenerated = new NonAutoGeneratedObject("NonAutoGeneratedObject");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean check(TestParcelable p, int n, String s) {
|
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 {
|
private static class AidlObject extends IAidlTest.Stub {
|
||||||
public IInterface queryLocalInterface(String descriptor) {
|
public IInterface queryLocalInterface(String descriptor) {
|
||||||
// overriding this to return null makes asInterface always
|
// overriding this to return null makes asInterface always
|
||||||
@@ -420,7 +428,7 @@ public class AidlTest extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SmallTest
|
@SmallTest
|
||||||
public void testGetTransactionName() throws Exception {
|
public void testGetTransactionNameAutoGenerated() throws Exception {
|
||||||
assertEquals(15, mLocal.getMaxTransactionId());
|
assertEquals(15, mLocal.getMaxTransactionId());
|
||||||
|
|
||||||
assertEquals("booleanArray",
|
assertEquals("booleanArray",
|
||||||
@@ -430,12 +438,21 @@ public class AidlTest extends TestCase {
|
|||||||
assertEquals("parcelableIn",
|
assertEquals("parcelableIn",
|
||||||
mLocal.getTransactionName(IAidlTest.Stub.TRANSACTION_parcelableIn));
|
mLocal.getTransactionName(IAidlTest.Stub.TRANSACTION_parcelableIn));
|
||||||
|
|
||||||
assertEquals("IAidlTest:booleanArray",
|
assertEquals("AIDL::java::IAidlTest::booleanArray::server",
|
||||||
mLocal.getTransactionTraceName(IAidlTest.Stub.TRANSACTION_booleanArray));
|
mLocal.getTransactionTraceName(IAidlTest.Stub.TRANSACTION_booleanArray));
|
||||||
assertEquals("IAidlTest:voidSecurityException",
|
assertEquals("AIDL::java::IAidlTest::voidSecurityException::server",
|
||||||
mLocal.getTransactionTraceName(IAidlTest.Stub.TRANSACTION_voidSecurityException));
|
mLocal.getTransactionTraceName(IAidlTest.Stub.TRANSACTION_voidSecurityException));
|
||||||
assertEquals("IAidlTest:parcelableIn",
|
assertEquals("AIDL::java::IAidlTest::parcelableIn::server",
|
||||||
mLocal.getTransactionTraceName(IAidlTest.Stub.TRANSACTION_parcelableIn));
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user