Moved dump from NBLog to ReportPerformance
Minor cleanup
Test: dumpsys media.log
Change-Id: Ib4d12f6e20c04ecb3344290083ea65a3fe1e47e0
diff --git a/media/libnbaio/NBLog.cpp b/media/libnbaio/NBLog.cpp
index f00d86f..0adeb46 100644
--- a/media/libnbaio/NBLog.cpp
+++ b/media/libnbaio/NBLog.cpp
@@ -92,7 +92,6 @@
#include <climits>
#include <deque>
#include <fstream>
-// #include <inttypes.h>
#include <iostream>
#include <math.h>
#include <numeric>
@@ -941,22 +940,8 @@
getAndProcessSnapshot(*snap);
}
-// TODO: move this function to a different class than NBLog::Reader
-// writes summary of performance to the console
-void NBLog::MergeReader::dump(int fd, size_t indent)
-{
- mFd = fd;
- mIndent = indent;
- String8 body, timestamp;
- // TODO: check: is the FIXME below still a problem?
- // FIXME: this is not thread safe
- for (auto & threadReport : mThreadPerformanceAnalysis) {
- threadReport.second.reportPerformance(&body);
- }
- if (!body.isEmpty()) {
- ALOGD("body is not empty");
- dumpLine(timestamp, body);
- }
+void NBLog::MergeReader::dump(int fd, int indent) {
+ ReportPerformance::dump(fd, indent, mThreadPerformanceAnalysis);
}
// Writes a string to the console
diff --git a/media/libnbaio/PerformanceAnalysis.cpp b/media/libnbaio/PerformanceAnalysis.cpp
index 41184a6..37d6d9f 100644
--- a/media/libnbaio/PerformanceAnalysis.cpp
+++ b/media/libnbaio/PerformanceAnalysis.cpp
@@ -36,7 +36,6 @@
#include <media/nbaio/NBLog.h>
#include <media/nbaio/PerformanceAnalysis.h>
#include <media/nbaio/ReportPerformance.h>
-// #include <utils/CallStack.h> // used to print callstack
#include <utils/Log.h>
#include <utils/String8.h>
@@ -242,7 +241,7 @@
// TODO Make it return a std::string instead of modifying body --> is this still relevant?
// TODO consider changing all ints to uint32_t or uint64_t
// TODO: move this to ReportPerformance, probably make it a friend function of PerformanceAnalysis
-void PerformanceAnalysis::reportPerformance(String8 *body, int maxHeight) {
+void PerformanceAnalysis::reportPerformance(String8 *body, int maxHeight) const {
if (mHists.empty()) {
ALOGD("reportPerformance: mHists is empty");
return;
@@ -346,6 +345,26 @@
return;
}
+//------------------------------------------------------------------------------
+
+// writes summary of performance into specified file descriptor
+void dump(int fd, int indent, const std::map<int, PerformanceAnalysis>
+ &threadPerformanceAnalysis) {
+ String8 body;
+ for (auto & thread : threadPerformanceAnalysis) {
+ thread.second.reportPerformance(&body);
+ }
+ if (!body.isEmpty()) {
+ dumpLine(fd, indent, body);
+ body.clear();
+ }
+}
+
+// Writes a string into specified file descriptor
+void dumpLine(int fd, int indent, const String8 &body) {
+ dprintf(fd, "%.*s%s \n", indent, "", body.string());
+}
+
} // namespace ReportPerformance
} // namespace android
diff --git a/media/libnbaio/include/media/nbaio/NBLog.h b/media/libnbaio/include/media/nbaio/NBLog.h
index 1504f81..b4af58b 100644
--- a/media/libnbaio/include/media/nbaio/NBLog.h
+++ b/media/libnbaio/include/media/nbaio/NBLog.h
@@ -452,10 +452,11 @@
// get snapshot of readers fifo buffer, effectively consuming the buffer
std::unique_ptr<Snapshot> getSnapshot();
- // print a summary of the performance to the console
+
bool isIMemory(const sp<IMemory>& iMemory) const;
protected:
+ // print a summary of the performance to the console
void dumpLine(const String8& timestamp, String8& body);
EntryIterator handleFormat(const FormatEntry &fmtEntry,
String8 *timestamp,
@@ -544,8 +545,7 @@
public:
MergeReader(const void *shared, size_t size, Merger &merger);
- // TODO: consider moving dump to ReportPerformance
- void dump(int fd, size_t indent = 0);
+ void dump(int fd, int indent = 0);
// process a particular snapshot of the reader
void getAndProcessSnapshot(Snapshot & snap);
// call getSnapshot of the content of the reader's buffer and process the data
diff --git a/media/libnbaio/include/media/nbaio/PerformanceAnalysis.h b/media/libnbaio/include/media/nbaio/PerformanceAnalysis.h
index 0f47619..67bd3ac 100644
--- a/media/libnbaio/include/media/nbaio/PerformanceAnalysis.h
+++ b/media/libnbaio/include/media/nbaio/PerformanceAnalysis.h
@@ -73,7 +73,7 @@
// input: series of short histograms. Generates a string of analysis of the buffer periods
// TODO: WIP write more detailed analysis
// FIXME: move this data visualization to a separate class. Model/view/controller
- void reportPerformance(String8 *body, int maxHeight = 10);
+ void reportPerformance(String8 *body, int maxHeight = 10) const;
// TODO: delete this. temp for testing
void testFunction();
@@ -134,6 +134,11 @@
};
+void dump(int fd, int indent, const std::map<int, PerformanceAnalysis>
+ &threadPerformanceAnalysis);
+
+void dumpLine(int fd, int indent, const String8 &body);
+
} // namespace ReportPerformance
} // namespace android