diff --git a/logd/LogStatistics.cpp b/logd/LogStatistics.cpp
index accd660..6e5454a 100644
--- a/logd/LogStatistics.cpp
+++ b/logd/LogStatistics.cpp
@@ -17,7 +17,6 @@
 #include <algorithm> // std::max
 #include <fcntl.h>
 #include <stdio.h>
-#include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 
@@ -27,7 +26,8 @@
 
 #include "LogStatistics.h"
 
-LogStatistics::LogStatistics() {
+LogStatistics::LogStatistics()
+        : enable(false) {
     log_id_for_each(id) {
         mSizes[id] = 0;
         mElements[id] = 0;
@@ -36,8 +36,10 @@
     }
 }
 
+namespace android {
+
 // caller must own and free character string
-char *LogStatistics::pidToName(pid_t pid) {
+static char *pidToName(pid_t pid) {
     char *retval = NULL;
     if (pid == 0) { // special case from auditd for kernel
         retval = strdup("logd.auditd");
@@ -60,6 +62,8 @@
     return retval;
 }
 
+}
+
 void LogStatistics::add(LogBufferElement *e) {
     log_id_t log_id = e->getLogId();
     unsigned short size = e->getMsgLen();
@@ -81,6 +85,31 @@
 
     mSizesTotal[log_id] += size;
     ++mElementsTotal[log_id];
+
+    if (!enable) {
+        return;
+    }
+
+    pid_t pid = e->getPid();
+    hash = android::hash_type(pid);
+    index = pidTable.find(-1, hash, pid);
+    if (index == -1) {
+        PidEntry initEntry(pid, uid, android::pidToName(pid));
+        initEntry.add(size);
+        pidTable.add(hash, initEntry);
+    } else {
+        PidEntry &entry = pidTable.editEntryAt(index);
+        if (entry.getUid() != uid) {
+            entry.setUid(uid);
+            entry.setName(android::pidToName(pid));
+        } else if (!entry.getName()) {
+            char *name = android::pidToName(pid);
+            if (name) {
+                entry.setName(name);
+            }
+        }
+        entry.add(size);
+    }
 }
 
 void LogStatistics::subtract(LogBufferElement *e) {
@@ -99,33 +128,20 @@
             table.removeAt(index);
         }
     }
-}
 
-// caller must own and delete UidEntry array
-const UidEntry **LogStatistics::sort(size_t n, log_id id) {
-    if (!n) {
-        return NULL;
+    if (!enable) {
+        return;
     }
 
-    const UidEntry **retval = new const UidEntry* [n];
-    memset(retval, 0, sizeof(*retval) * n);
-
-    uidTable_t &table = uidTable[id];
-    ssize_t index = -1;
-    while ((index = table.next(index)) >= 0) {
-        const UidEntry &entry = table.entryAt(index);
-        size_t s = entry.getSizes();
-        ssize_t i = n - 1;
-        while ((!retval[i] || (s > retval[i]->getSizes())) && (--i >= 0));
-        if (++i < (ssize_t)n) {
-            size_t b = n - i - 1;
-            if (b) {
-                memmove(&retval[i+1], &retval[i], b * sizeof(retval[0]));
-            }
-            retval[i] = &entry;
+    pid_t pid = e->getPid();
+    hash = android::hash_type(pid);
+    index = pidTable.find(-1, hash, pid);
+    if (index != -1) {
+        PidEntry &entry = pidTable.editEntryAt(index);
+        if (entry.subtract(size)) {
+            pidTable.removeAt(index);
         }
     }
-    return retval;
 }
 
 // caller must own and free character string
@@ -145,8 +161,29 @@
         ++info;
     }
 
+    char *name = NULL;
+
+    // report uid -> pid(s) -> pidToName if unique
+    ssize_t index = -1;
+    while ((index = pidTable.next(index)) != -1) {
+        const PidEntry &entry = pidTable.entryAt(index);
+
+        if (entry.getUid() == uid) {
+            const char *n = entry.getName();
+
+            if (n) {
+                if (!name) {
+                    name = strdup(n);
+                } else if (strcmp(name, n)) {
+                    free(name);
+                    return NULL;
+                }
+            }
+        }
+    }
+
     // No one
-    return NULL;
+    return name;
 }
 
 static void format_line(android::String8 &output,
@@ -223,37 +260,23 @@
     // Report on Chattiest
 
     // Chattiest by application (UID)
+    static const size_t maximum_sorted_entries = 32;
     log_id_for_each(id) {
         if (!(logMask & (1 << id))) {
             continue;
         }
 
-        static const size_t maximum_sorted_entries = 32;
-        const UidEntry **sorted = sort(maximum_sorted_entries, id);
-
-        if (!sorted) {
-            continue;
-        }
-
-        bool print = false;
-        for(size_t index = 0; index < maximum_sorted_entries; ++index) {
+        bool headerPrinted = false;
+        std::unique_ptr<const UidEntry *[]> sorted = sort(maximum_sorted_entries, id);
+        ssize_t index = -1;
+        while ((index = uidTable_t::next(index, sorted, maximum_sorted_entries)) >= 0) {
             const UidEntry *entry = sorted[index];
-
-            if (!entry) {
-                break;
-            }
-
-            size_t sizes = entry->getSizes();
-            if (sizes < (65536/100)) {
-                break;
-            }
-
             uid_t u = entry->getKey();
             if ((uid != AID_ROOT) && (u != uid)) {
                 continue;
             }
 
-            if (!print) {
+            if (!headerPrinted) {
                 if (uid == AID_ROOT) {
                     output.appendFormat(
                         "\n\nChattiest UIDs in %s:\n",
@@ -266,7 +289,7 @@
                         "\n\nLogging for your UID in %s:\n",
                         android_log_id_to_name(id));
                 }
-                print = true;
+                headerPrinted = true;
             }
 
             android::String8 name("");
@@ -278,18 +301,62 @@
             }
 
             android::String8 size("");
-            size.appendFormat("%zu", sizes);
+            size.appendFormat("%zu", entry->getSizes());
 
             format_line(output, name, size);
         }
+    }
 
-        delete [] sorted;
+    if (enable) {
+        bool headerPrinted = false;
+        std::unique_ptr<const PidEntry *[]> sorted = pidTable.sort(maximum_sorted_entries);
+        ssize_t index = -1;
+        while ((index = pidTable.next(index, sorted, maximum_sorted_entries)) >= 0) {
+            const PidEntry *entry = sorted[index];
+            uid_t u = entry->getUid();
+            if ((uid != AID_ROOT) && (u != uid)) {
+                continue;
+            }
+
+            if (!headerPrinted) {
+                if (uid == AID_ROOT) {
+                    output.appendFormat("\n\nChattiest PIDs:\n");
+                } else {
+                    output.appendFormat("\n\nLogging for this PID:\n");
+                }
+                android::String8 name("  PID/UID");
+                android::String8 size("Size");
+                android::String8 pruned("Pruned");
+                format_line(output, name, size, pruned);
+                headerPrinted = true;
+            }
+
+            android::String8 name("");
+            name.appendFormat("%5u/%u", entry->getKey(), u);
+            const char *n = entry->getName();
+            if (n) {
+                name.appendFormat("%*s%s", (int)std::max(12 - name.length(), (size_t)1), "", n);
+            } else {
+                char *un = uidToName(u);
+                if (un) {
+                    name.appendFormat("%*s%s", (int)std::max(12 - name.length(), (size_t)1), "", un);
+                    free(un);
+                }
+            }
+
+            android::String8 size("");
+            size.appendFormat("%zu", entry->getSizes());
+
+            format_line(output, name, size);
+        }
     }
 
     *buf = strdup(output.string());
 }
 
-uid_t LogStatistics::pidToUid(pid_t pid) {
+namespace android {
+
+uid_t pidToUid(pid_t pid) {
     char buffer[512];
     snprintf(buffer, sizeof(buffer), "/proc/%u/status", pid);
     FILE *fp = fopen(buffer, "r");
@@ -305,3 +372,52 @@
     }
     return getuid(); // associate this with the logger
 }
+
+}
+
+uid_t LogStatistics::pidToUid(pid_t pid) {
+    uid_t uid;
+    android::hash_t hash = android::hash_type(pid);
+    ssize_t index = pidTable.find(-1, hash, pid);
+    if (index == -1) {
+        uid = android::pidToUid(pid);
+        PidEntry initEntry(pid, uid, android::pidToName(pid));
+        pidTable.add(hash, initEntry);
+    } else {
+        PidEntry &entry = pidTable.editEntryAt(index);
+        if (!entry.getName()) {
+            char *name = android::pidToName(pid);
+            if (name) {
+                entry.setName(name);
+            }
+        }
+        uid = entry.getUid();
+    }
+    return uid;
+}
+
+// caller must free character string
+char *LogStatistics::pidToName(pid_t pid) {
+    char *name;
+
+    android::hash_t hash = android::hash_type(pid);
+    ssize_t index = pidTable.find(-1, hash, pid);
+    if (index == -1) {
+        name = android::pidToName(pid);
+        PidEntry initEntry(pid, android::pidToUid(pid), name ? strdup(name) : NULL);
+        pidTable.add(hash, initEntry);
+    } else {
+        PidEntry &entry = pidTable.editEntryAt(index);
+        const char *n = entry.getName();
+        if (n) {
+            name = strdup(n);
+        } else {
+            name = android::pidToName(pid);
+            if (name) {
+                entry.setName(strdup(name));
+            }
+        }
+    }
+
+    return name;
+}
