TimeCheck: Track audio Hidl hwbinder calls
DeviceHalHidl, StreamInHalHidl, StreamOutHalHidl
Test: adb shell dumpsys media.audio_flinger
Bug: 219958414
Change-Id: I3ff630983bdca6c8fd9ba9868e831cb063afdadc
diff --git a/media/utils/include/mediautils/MethodStatistics.h b/media/utils/include/mediautils/MethodStatistics.h
index 7d8061d..700fbaa 100644
--- a/media/utils/include/mediautils/MethodStatistics.h
+++ b/media/utils/include/mediautils/MethodStatistics.h
@@ -19,6 +19,7 @@
#include <map>
#include <mutex>
#include <string>
+#include <vector>
#include <android-base/thread_annotations.h>
#include <audio_utils/Statistics.h>
@@ -91,9 +92,16 @@
std::string dump() const {
std::stringstream ss;
std::lock_guard lg(mLock);
- for (const auto &[code, stats] : mStatisticsMap) {
- ss << int(code) << " " << getMethodForCode(code) <<
- " n=" << stats.getN() << " " << stats.toString() << "\n";
+ if constexpr (std::is_same_v<Code, std::string>) {
+ for (const auto &[code, stats] : mStatisticsMap) {
+ ss << code <<
+ " n=" << stats.getN() << " " << stats.toString() << "\n";
+ }
+ } else /* constexpr */ {
+ for (const auto &[code, stats] : mStatisticsMap) {
+ ss << int(code) << " " << getMethodForCode(code) <<
+ " n=" << stats.getN() << " " << stats.toString() << "\n";
+ }
}
return ss.str();
}
@@ -104,6 +112,18 @@
std::map<Code, StatsType> mStatisticsMap GUARDED_BY(mLock);
};
+// Managed Statistics support.
+// Supported Modules
+#define METHOD_STATISTICS_MODULE_NAME_AUDIO_HIDL "AudioHidl"
+
+// Returns a vector of class names for the module, or a nullptr if module not found.
+std::shared_ptr<std::vector<std::string>>
+getStatisticsClassesForModule(std::string_view moduleName);
+
+// Returns a statistics object for that class, or a nullptr if class not found.
+std::shared_ptr<MethodStatistics<std::string>>
+getStatisticsForClass(std::string_view className);
+
// Only if used, requires IBinder.h to be included at the location of invocation.
#define METHOD_STATISTICS_BINDER_CODE_NAMES(CODE_TYPE) \
{(CODE_TYPE)IBinder::PING_TRANSACTION , "ping"}, \
diff --git a/media/utils/include/mediautils/TimeCheck.h b/media/utils/include/mediautils/TimeCheck.h
index d5130b0..ef03aef 100644
--- a/media/utils/include/mediautils/TimeCheck.h
+++ b/media/utils/include/mediautils/TimeCheck.h
@@ -99,4 +99,9 @@
const TimerThread::Handle mTimerHandle = TimerThread::INVALID_HANDLE;
};
+// Returns a TimeCheck object that sends info to MethodStatistics
+// obtained from getStatisticsForClass(className).
+TimeCheck makeTimeCheckStatsForClassMethod(
+ std::string_view className, std::string_view methodName);
+
} // namespace android::mediautils