logd: liblog: logcat: Add Statistics

- logd add statistical collection and formatting
- liblog add android_logger_get_statistics call
- logcat add -S flag
- logcat add -b all

(cherry picked from commit 51a29c8dc445e4fb89860561933e54a231e6ffb4)

Change-Id: I521753b1969ecd4590c956aeeb1557d101059d67
diff --git a/logd/LogBuffer.h b/logd/LogBuffer.h
index 1b50a8f..92dd107 100644
--- a/logd/LogBuffer.h
+++ b/logd/LogBuffer.h
@@ -25,6 +25,7 @@
 
 #include "LogBufferElement.h"
 #include "LogTimes.h"
+#include "LogStatistics.h"
 
 typedef android::List<LogBufferElement *> LogBufferElementCollection;
 
@@ -32,8 +33,7 @@
     LogBufferElementCollection mLogElements;
     pthread_mutex_t mLogElementsLock;
 
-    unsigned long mSizes[LOG_ID_MAX];
-    unsigned long mElements[LOG_ID_MAX];
+    LogStatistics stats;
 
 public:
     LastLogTimes &mTimes;
@@ -50,6 +50,8 @@
     void clear(log_id_t id);
     unsigned long getSize(log_id_t id);
     unsigned long getSizeUsed(log_id_t id);
+    // *strp uses malloc, use free to release.
+    size_t formatStatistics(char **strp, uid_t uid, unsigned int logMask);
 
 private:
     void maybePrune(log_id_t id);
@@ -57,4 +59,4 @@
 
 };
 
-#endif
+#endif // _LOGD_LOG_BUFFER_H__