periodically push AudioFlinger thread statistics to media metrics
Test: dumpsys media.metrics
Bug: 68148948
Change-Id: I9b1538a8cff3f89f4689dceda800132349338a0d
diff --git a/media/libnblog/NBLog.cpp b/media/libnblog/NBLog.cpp
index cd967e4..aee0ea3 100644
--- a/media/libnblog/NBLog.cpp
+++ b/media/libnblog/NBLog.cpp
@@ -788,7 +788,7 @@
// writes the data to a map of class PerformanceAnalysis, based on their thread ID.
void NBLog::MergeReader::processSnapshot(NBLog::Snapshot &snapshot, int author)
{
- PerformanceData& data = mThreadPerformanceData[author];
+ ReportPerformance::PerformanceData& data = mThreadPerformanceData[author];
// We don't do "auto it" because it reduces readability in this case.
for (EntryIterator it = snapshot.begin(); it != snapshot.end(); ++it) {
switch (it->type) {
@@ -856,6 +856,19 @@
processSnapshot(*(snapshots[i]), i);
}
}
+ checkPushToMediaMetrics();
+}
+
+void NBLog::MergeReader::checkPushToMediaMetrics()
+{
+ const nsecs_t now = systemTime();
+ for (auto& item : mThreadPerformanceData) {
+ ReportPerformance::PerformanceData& data = item.second;
+ if (now - data.start >= kPeriodicMediaMetricsPush) {
+ (void)ReportPerformance::sendToMediaMetrics(data);
+ data.reset(); // data is persistent per thread
+ }
+ }
}
void NBLog::MergeReader::dump(int fd, int indent)
@@ -864,8 +877,8 @@
ReportPerformance::dump(fd, indent, mThreadPerformanceAnalysis);
Json::Value root(Json::arrayValue);
for (const auto& item : mThreadPerformanceData) {
- const PerformanceData& data = item.second;
- std::unique_ptr<Json::Value> threadData = dumpToJson(data);
+ const ReportPerformance::PerformanceData& data = item.second;
+ std::unique_ptr<Json::Value> threadData = ReportPerformance::dumpToJson(data);
if (threadData == nullptr) {
continue;
}