NBLog: add retroactive dump and standard printing format
The retroactive dump outputs historical snapshots of data that
correspond to important NBLog Events at the time they were read.
The standard printing format added is as follows: for each line, the
first column is the NBLog Event as a string, and the following columns
correspond to each field of the struct, or the type, that the NBLog
Event maps to. All columns are separated by commas.
Other changes:
Added option to Reader::getSnapshot() for flushing the buffer. This
makes it possible to always read the full buffer contents when doing a
dump of the raw log contents.
Test: dumpsys media.log with -r and --retro options
Bug: 68148948
Change-Id: I4bbbf6e2f9a3a86fae976986ac35a7eef79520de
diff --git a/media/libnblog/ReportPerformance.cpp b/media/libnblog/ReportPerformance.cpp
index 7e40947..f632e40 100644
--- a/media/libnblog/ReportPerformance.cpp
+++ b/media/libnblog/ReportPerformance.cpp
@@ -113,6 +113,41 @@
}
}
+static std::string dumpRetroString(const PerformanceData& data, int64_t now)
+{
+ std::stringstream ss;
+ ss << NBLog::threadTypeToString(data.threadInfo.type) << "," << data.threadInfo.id << "\n";
+ for (const auto &item : data.snapshots) {
+ // TODO use an enum to string conversion method. One good idea:
+ // https://stackoverflow.com/a/238157
+ if (item.first == NBLog::EVENT_UNDERRUN) {
+ ss << "EVENT_UNDERRUN,";
+ } else if (item.first == NBLog::EVENT_OVERRUN) {
+ ss << "EVENT_OVERRUN,";
+ }
+ ss << now - item.second << "\n";
+ }
+ ss << "\n";
+ return ss.str();
+}
+
+void dumpRetro(int fd, const std::map<int, PerformanceData>& threadDataMap)
+{
+ if (fd < 0) {
+ return;
+ }
+
+ const nsecs_t now = systemTime();
+ for (const auto &item : threadDataMap) {
+ const ReportPerformance::PerformanceData& data = item.second;
+ if (data.snapshots.empty()) {
+ continue;
+ }
+ const std::string retroStr = dumpRetroString(data, now);
+ write(fd, retroStr.c_str(), retroStr.size());
+ }
+}
+
bool sendToMediaMetrics(const PerformanceData& data)
{
// See documentation for these metrics here: