logd: separate LogStatistics from LogBuffer

LogStatistics is intertwined with LogBuffer, even relying on it for
thread safety.  This needs to change to have a proper
LogBufferInterface, so this CL separates them.  Specifically:

1) Adding a lock to LogStatistics and adding thread annotations to
   ensure that data structures are protected appropriately.
2) Moving prune_rows calculation into LogStatistics so it is done
   while holding this lock.
3) Using LogStatistics instead of LogBuffer where appropriate.

Note that there should not be a significant performance regression
with this lock, as it will almost always been uncontended.  If
anything, it should alleviate pressure from LogBuffer's lock.

Test: logging unit tests
Change-Id: I9d6dde2c96c9f024fa0341711c7bc63379e8e406
diff --git a/logd/LogBuffer.h b/logd/LogBuffer.h
index 3c45667..3c1ea5a 100644
--- a/logd/LogBuffer.h
+++ b/logd/LogBuffer.h
@@ -38,8 +38,6 @@
     LogBufferElementCollection mLogElements;
     pthread_rwlock_t mLogElementsLock;
 
-    LogStatistics stats;
-
     // watermark of any worst/chatty uid processing
     typedef std::unordered_map<uid_t, LogBufferElementCollection::iterator>
         LogBufferIteratorMap;
@@ -58,7 +56,7 @@
    public:
     LastLogTimes& mTimes;
 
-    LogBuffer(LastLogTimes* times, LogTags* tags, PruneList* prune);
+    LogBuffer(LastLogTimes* times, LogTags* tags, PruneList* prune, LogStatistics* stats);
     ~LogBuffer();
     void init();
 
@@ -75,22 +73,8 @@
     bool clear(log_id_t id, uid_t uid = AID_ROOT);
     unsigned long getSize(log_id_t id);
     int setSize(log_id_t id, unsigned long size);
-    unsigned long getSizeUsed(log_id_t id);
 
-    std::string formatStatistics(uid_t uid, pid_t pid, unsigned int logMask);
-
-    void enableStatistics() {
-        stats.enableStatistics();
-    }
-
-    // helper must be protected directly or implicitly by wrlock()/unlock()
-    const char* pidToName(pid_t pid) {
-        return stats.pidToName(pid);
-    }
-    uid_t pidToUid(pid_t pid) { return stats.pidToUid(pid); }
-    const char* uidToName(uid_t uid) {
-        return stats.uidToName(uid);
-    }
+  private:
     void wrlock() {
         pthread_rwlock_wrlock(&mLogElementsLock);
     }
@@ -101,10 +85,6 @@
         pthread_rwlock_unlock(&mLogElementsLock);
     }
 
-   private:
-    static constexpr size_t minPrune = 4;
-    static constexpr size_t maxPrune = 256;
-
     void maybePrune(log_id_t id);
     void kickMe(LogReaderThread* me, log_id_t id, unsigned long pruneRows);
 
@@ -118,6 +98,7 @@
 
     LogTags* tags_;
     PruneList* prune_;
+    LogStatistics* stats_;
 
     // Keeps track of the iterator to the oldest log message of a given log type, as an
     // optimization when pruning logs.  Use GetOldest() to retrieve.