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

Commit 38b96ebe authored by Milo Sredkov's avatar Milo Sredkov
Browse files

Throttle logging in BBinder::getInterfaceDescriptor()

Currently getInterfaceDescriptor() logs a warning when it is not
implemented. In some cases it may be invoked frequently, and this
logging adds overhead.

Limit the warning to at most once per second. This makes the
binderAddInts benchmark run three times faster.

Bug: 429079371
Test: m binderAddInts && adb push out/soong/.intermediates/system/extras/tests/binder/benchmarks/binderAddInts /data/local/tmp/binderAddInts && adb shell /data/local//tmp/binderAddInts/android_arm64_armv8-2a_cortex-a55/binderAddInts
Flag: build.RELEASE_LIBBINDER_BINDER_OBSERVER
Change-Id: I046adba2dbe32e55fd0a9e4d676106a60bfaa4bf
parent 9d8e8aa6
Loading
Loading
Loading
Loading
+17 −1
Original line number Diff line number Diff line
@@ -385,8 +385,24 @@ status_t BBinder::stopRecordingTransactions() {

const String16& BBinder::getInterfaceDescriptor() const
{
    // Throttle logging because getInterfaceDescriptor can be invoked a lot.
    static std::atomic<std::chrono::steady_clock::time_point> sLastLogTime = {
            std::chrono::steady_clock::time_point::min()};

    auto lastLogTime = sLastLogTime.load(std::memory_order_acquire);
    auto currentTime = std::chrono::steady_clock::now();
    // Don't log more than once per second. The check is not strict, since it may happen that
    // multiple theads read lastLogTime at the same time  but we don't want it to be strict
    // for performance reasons.
    // Note: Do not subtract time_point::min(), that would cause an arithmetic overflow.
    if (lastLogTime == std::chrono::steady_clock::time_point::min() ||
        to_ms(currentTime - lastLogTime) >= 1000) {
        ALOGW("BBinder::getInterfaceDescriptor (this=%p). Override?", this);

        sLastLogTime.store(currentTime, std::memory_order_release);
    }

    [[clang::no_destroy]] static StaticString16 sBBinder(u"BBinder");
    ALOGW("Reached BBinder::getInterfaceDescriptor (this=%p). Override?", this);
    return sBBinder;
}