Loading media/libaudiohal/impl/StreamHalAidl.cpp +7 −0 Original line number Diff line number Diff line Loading @@ -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); Loading media/utils/TimeCheck.cpp +42 −10 Original line number Diff line number Diff line Loading @@ -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 media/utils/include/mediautils/TimeCheck.h +3 −0 Original line number Diff line number Diff line Loading @@ -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 = \ Loading Loading
media/libaudiohal/impl/StreamHalAidl.cpp +7 −0 Original line number Diff line number Diff line Loading @@ -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); Loading
media/utils/TimeCheck.cpp +42 −10 Original line number Diff line number Diff line Loading @@ -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
media/utils/include/mediautils/TimeCheck.h +3 −0 Original line number Diff line number Diff line Loading @@ -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 = \ Loading