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

Commit ee3538b3 authored by Isak Evaldsson's avatar Isak Evaldsson Committed by Snild Dolkow
Browse files

Looper: Add sysprop for verbose slow message logging



By default, if a looper detects a slow delivery it will suppress all
further logs until it starts to deliver messages in time again. This
patch adds a verboseLogging flag, which can be enabled by a sysprop,
that disables this suppression, thereby making the slow delivery logging
more verbose.

Having the verbose logging makes it easier to understand and debug
issues related to slow delivery since it allows one to see exactly which
and how many messages get delivered slowly by a looper.

Bug: 326356810
Test: manual - Setprop log.looper.slow.verbose and observe log
Based-on-patch-by: default avatarNicklas Ekstrand <nicklas.ekstrand@sonymobile.com>
Change-Id: Ibe273c27b7e11b20aa79347e529cdec1f69e59c6
parent 2853f31d
Loading
Loading
Loading
Loading
+18 −7
Original line number Diff line number Diff line
@@ -70,6 +70,13 @@ public final class Looper {

    private static final String TAG = "Looper";

    private static class NoImagePreloadHolder {
        // Enable/Disable verbose logging with a system prop. e.g.
        // adb shell 'setprop log.looper.slow.verbose false && stop && start'
        private static final boolean sVerboseLogging =
                SystemProperties.getBoolean("log.looper.slow.verbose", false);
    }

    // sThreadLocal.get() will return null unless you've called prepare().
    @UnsupportedAppUsage
    static final ThreadLocal<Looper> sThreadLocal = new ThreadLocal<Looper>();
@@ -246,19 +253,23 @@ public final class Looper {
            }
        }
        if (logSlowDelivery) {
            boolean slow = false;

            if (!me.mSlowDeliveryDetected || NoImagePreloadHolder.sVerboseLogging) {
                slow = showSlowLog(slowDeliveryThresholdMs, msg.when, dispatchStart,
                        "delivery", msg);
            }
            if (me.mSlowDeliveryDetected) {
                if ((dispatchStart - msg.when) <= 10) {
                if (!slow && (dispatchStart - msg.when) <= 10) {
                    Slog.w(TAG, "Drained");
                    me.mSlowDeliveryDetected = false;
                }
            } else {
                if (showSlowLog(slowDeliveryThresholdMs, msg.when, dispatchStart, "delivery",
                        msg)) {
                    // Once we write a slow delivery log, suppress until the queue drains.
            } else if (slow) {
                // A slow delivery is detected, suppressing further logs unless verbose logging
                // is enabled.
                me.mSlowDeliveryDetected = true;
            }
        }
        }
        if (logSlowDispatch) {
            showSlowLog(slowDispatchThresholdMs, dispatchStart, dispatchEnd, "dispatch", msg);
        }