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

Commit 25ee0bc6 authored by Jorim Jaggi's avatar Jorim Jaggi
Browse files

Add traces to systrace when binder tracing is enabled

If binder tracing is enabled, we also output the class/method name
to systrace. This is the first step toward a system in which we could
show the full stack trace in systrace.

Test:
adb shell am trace-ipc start
python systrace.py
adb shell am trace-ipc stop

Change-Id: I6d0354c9560c4518c84fb3fdb66219b460e69f67
parent 46fff5e9
Loading
Loading
Loading
Loading
+23 −2
Original line number Diff line number Diff line
@@ -563,7 +563,11 @@ public class Binder implements IBinder {
        boolean res;
        // Log any exceptions as warnings, don't silently suppress them.
        // If the call was FLAG_ONEWAY then these exceptions disappear into the ether.
        final boolean tracingEnabled = Binder.isTracingEnabled();
        try {
            if (tracingEnabled) {
                Trace.traceBegin(Trace.TRACE_TAG_ALWAYS, getClass().getName() + ":" + code);
            }
            res = onTransact(code, data, reply, flags);
        } catch (RemoteException|RuntimeException e) {
            if (LOG_RUNTIME_EXCEPTION) {
@@ -587,6 +591,10 @@ public class Binder implements IBinder {
            reply.setDataPosition(0);
            reply.writeException(re);
            res = true;
        } finally {
            if (tracingEnabled) {
                Trace.traceEnd(Trace.TRACE_TAG_ALWAYS);
            }
        }
        checkParcel(this, code, reply, "Unreasonably large binder reply buffer");
        reply.recycle();
@@ -613,8 +621,21 @@ final class BinderProxy implements IBinder {

    public boolean transact(int code, Parcel data, Parcel reply, int flags) throws RemoteException {
        Binder.checkParcel(this, code, data, "Unreasonably large binder buffer");
        if (Binder.isTracingEnabled()) { Binder.getTransactionTracker().addTrace(); }
        final boolean tracingEnabled = Binder.isTracingEnabled();
        if (tracingEnabled) {
            final Throwable tr = new Throwable();
            Binder.getTransactionTracker().addTrace(tr);
            StackTraceElement stackTraceElement = tr.getStackTrace()[1];
            Trace.traceBegin(Trace.TRACE_TAG_ALWAYS,
                    stackTraceElement.getClassName() + "." + stackTraceElement.getMethodName());
        }
        try {
            return transactNative(code, data, reply, flags);
        } finally {
            if (tracingEnabled) {
                Trace.traceEnd(Trace.TRACE_TAG_ALWAYS);
            }
        }
    }

    public native String getInterfaceDescriptor() throws RemoteException;
+2 −2
Original line number Diff line number Diff line
@@ -43,8 +43,8 @@ public class TransactionTracker {
        resetTraces();
    }

    public void addTrace() {
        String trace = Log.getStackTraceString(new Throwable());
    public void addTrace(Throwable tr) {
        String trace = Log.getStackTraceString(tr);
        synchronized (this) {
            if (mTraces.containsKey(trace)) {
                mTraces.put(trace, mTraces.get(trace) + 1);