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

Commit bb902b81 authored by Andy Hung's avatar Andy Hung Committed by Android (Google) Code Review
Browse files

Merge "StreamHalAidl: Dump audio HAL time to complete sendCommand (start)" into main

parents fc1b27c8 0d734832
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -659,6 +659,13 @@ status_t StreamHalAidl::sendCommand(
        const ::aidl::android::hardware::audio::core::StreamDescriptor::Command& command,
        ::aidl::android::hardware::audio::core::StreamDescriptor::Reply* reply,
        bool safeFromNonWorkerThread, StatePositions* statePositions) {

    // Add timeCheck only for start command (pause, flush checked at caller).
    std::unique_ptr<mediautils::TimeCheck> timeCheck;
    if (command.getTag() == StreamDescriptor::Command::start) {
        timeCheck = mediautils::makeTimeCheckStatsForClassMethodUniquePtr(
                getClassName(), "sendCommand_start");
    }
    // TIME_CHECK();  // TODO(b/243839867) reenable only when optimized.
    if (!safeFromNonWorkerThread) {
        const pid_t workerTid = mWorkerTid.load(std::memory_order_acquire);
+42 −10
Original line number Diff line number Diff line
@@ -368,24 +368,56 @@ void TimeCheck::TimeCheckHandler::onTimeout(TimerThread::Handle timerHandle) con
    }
}

template <typename T>
concept is_ptr = requires(T t) { *t; t.operator->(); };

// Automatically create a TimeCheck class for a class and method.
// This is used for Audio HAL support.
mediautils::TimeCheck makeTimeCheckStatsForClassMethod(
template <typename T>
T makeTimeCheckStatsForClassMethodGeneric(
        std::string_view className, std::string_view methodName) {
    std::shared_ptr<MethodStatistics<std::string>> statistics =
            mediautils::getStatisticsForClass(className);
    if (!statistics) return {}; // empty TimeCheck.
    return mediautils::TimeCheck(

    if constexpr (is_ptr<T>) {
        if (!statistics) return T(new TimeCheck{}); // empty TimeCheck
        return T(new TimeCheck{
                FixedString62(className).append("::").append(methodName),
                [safeMethodName = FixedString30(methodName),
                        stats = std::move(statistics)]
                        (bool timeout, float elapsedMs) {
                    if (timeout) { ; // ignored, there is no timeout value.
                    } else {
                        stats->event(safeMethodName.asStringView(), elapsedMs);
                    }
                }, {} /* timeoutDuration */, {} /* secondChanceDuration */,
                false /* crashOnTimeout */});
    } else /* constexpr */ {
        if (!statistics) return TimeCheck{}; // empty TimeCheck
        return TimeCheck{
                FixedString62(className).append("::").append(methodName),
                [safeMethodName = FixedString30(methodName),
                        stats = std::move(statistics)]
                        (bool timeout, float elapsedMs) {
                    if (timeout) {
                        ; // ignored, there is no timeout value.
                    if (timeout) { ; // ignored, there is no timeout value.
                    } else {
                        stats->event(safeMethodName.asStringView(), elapsedMs);
                    }
            }, {} /* timeoutDuration */, {} /* secondChanceDuration */, false /* crashOnTimeout */);
                }, {} /* timeoutDuration */, {} /* secondChanceDuration */,
                false /* crashOnTimeout */};

    }
}

mediautils::TimeCheck makeTimeCheckStatsForClassMethod(
        std::string_view className, std::string_view methodName) {
    return makeTimeCheckStatsForClassMethodGeneric<mediautils::TimeCheck>(className, methodName);
}

std::unique_ptr<mediautils::TimeCheck> makeTimeCheckStatsForClassMethodUniquePtr(
        std::string_view className, std::string_view methodName) {
    return makeTimeCheckStatsForClassMethodGeneric<std::unique_ptr<mediautils::TimeCheck>>(
            className, methodName);
}

}  // namespace android::mediautils
+3 −0
Original line number Diff line number Diff line
@@ -159,6 +159,9 @@ class TimeCheck {
TimeCheck makeTimeCheckStatsForClassMethod(
        std::string_view className, std::string_view methodName);

std::unique_ptr<TimeCheck> makeTimeCheckStatsForClassMethodUniquePtr(
            std::string_view className, std::string_view methodName);

// A handy statement-like macro to put at the beginning of almost every method
// which calls into HAL. Note that it requires the class to implement 'getClassName'.
#define TIME_CHECK() auto timeCheck = \