From b7cdc3b1d1bc7e0bbd2a1dc5f03bcd6fbd033a55 Mon Sep 17 00:00:00 2001 From: Zim Date: Tue, 4 Oct 2022 19:40:19 +0100 Subject: Skip tracing missing binder txn names This works around b/156126072 which introduces app startup latencies that are multiplied with binder txn tracing enabled. Skiping tracing interfaces without binder txn names avoids tracing interfaces like ContentProviders and app-defined interfaces. This is still an improvement on the status quo since we still trace the auto-generated framework interfaces. When we fix sporadic binder calls in the app-startup critical path, we can remove the restriction and enable tracing more broadly. Note that we still keep the old behavior of 'best effort' trace names when binder call stack sampling tracing is enabled Test: Manual Bug: 246650647 Change-Id: Id04b701f97241cbd5d14bbb368fdd8527b6f8c93 --- core/java/android/os/Binder.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/core/java/android/os/Binder.java b/core/java/android/os/Binder.java index 9d90e174b470..80b34a107a25 100644 --- a/core/java/android/os/Binder.java +++ b/core/java/android/os/Binder.java @@ -1241,8 +1241,21 @@ public class Binder implements IBinder { // If the call was {@link IBinder#FLAG_ONEWAY} then these exceptions // disappear into the ether. final boolean tagEnabled = Trace.isTagEnabled(Trace.TRACE_TAG_AIDL); + final boolean hasFullyQualifiedName = getMaxTransactionId() > 0; final String transactionTraceName; - if (tagEnabled) { + + if (tagEnabled && hasFullyQualifiedName) { + // 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; -- cgit v1.2.3-59-g8ed1b