Moved dump from NBLog to ReportPerformance

Minor cleanup

Test: dumpsys media.log
Change-Id: Ib4d12f6e20c04ecb3344290083ea65a3fe1e47e0
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