diff options
| author | Mark Salyzyn <salyzyn@google.com> | 2016-11-04 20:57:12 +0000 |
|---|---|---|
| committer | android-build-merger <android-build-merger@google.com> | 2016-11-04 20:57:12 +0000 |
| commit | 1970d994b679f5dbfa5bbfdaba2317266b50dd79 (patch) | |
| tree | 62f6f218a8ff95d9bc2d2504e36c3a6b2ac107c1 /logd | |
| parent | d32e7f4703d329104941828d5280f4f05438a489 (diff) | |
| parent | 6d981af12023bcaf22bfa0612a85ae4580ecb971 (diff) | |
| download | system_core-1970d994b679f5dbfa5bbfdaba2317266b50dd79.tar.gz system_core-1970d994b679f5dbfa5bbfdaba2317266b50dd79.tar.bz2 system_core-1970d994b679f5dbfa5bbfdaba2317266b50dd79.zip | |
logd: report statistics memory overhead
am: 6d981af120
Change-Id: I69376a8783867a21f0cd85eea4b299f3d2c81a95
Diffstat (limited to 'logd')
| -rw-r--r-- | logd/LogStatistics.cpp | 1 | ||||
| -rw-r--r-- | logd/LogStatistics.h | 42 |
2 files changed, 43 insertions, 0 deletions
diff --git a/logd/LogStatistics.cpp b/logd/LogStatistics.cpp index d68bfee99..d4b48ef9b 100644 --- a/logd/LogStatistics.cpp +++ b/logd/LogStatistics.cpp @@ -547,6 +547,7 @@ std::string LogStatistics::format(uid_t uid, pid_t pid, } spaces += spaces_total; } + totalSize += sizeOf(); if (spaces < 0) spaces = 0; output += android::base::StringPrintf("%*s%zu", spaces, "", totalSize); diff --git a/logd/LogStatistics.h b/logd/LogStatistics.h index bfaafa461..69fe91502 100644 --- a/logd/LogStatistics.h +++ b/logd/LogStatistics.h @@ -42,8 +42,30 @@ class LogHashtable { std::unordered_map<TKey, TEntry> map; + size_t bucket_size() const { + size_t count = 0; + for (size_t idx = 0; idx < map.bucket_count(); ++idx) { + size_t bucket_size = map.bucket_size(idx); + if (bucket_size == 0) bucket_size = 1; + count += bucket_size; + } + float load_factor = map.max_load_factor(); + if (load_factor < 1.0) return count; + return count * load_factor; + } + + static const size_t unordered_map_per_entry_overhead = sizeof(void*); + static const size_t unordered_map_bucket_overhead = sizeof(void*); + public: + // Estimate unordered_map memory usage. + size_t sizeOf() const { + return sizeof(*this) + + (map.size() * (sizeof(TEntry) + unordered_map_per_entry_overhead)) + + (bucket_size() * sizeof(size_t) + unordered_map_bucket_overhead); + } + typedef typename std::unordered_map<TKey, TEntry>::iterator iterator; typedef typename std::unordered_map<TKey, TEntry>::const_iterator const_iterator; @@ -155,6 +177,7 @@ public: } return output; } + }; namespace EntryBaseConstants { @@ -472,7 +495,26 @@ class LogStatistics { // security tag list tagTable_t securityTagTable; + size_t sizeOf() const { + size_t size = sizeof(*this) + pidTable.sizeOf() + tidTable.sizeOf() + + tagTable.sizeOf() + securityTagTable.sizeOf(); + for(auto it : pidTable) { + const char* name = it.second.getName(); + if (name) size += strlen(name) + 1; + } + for(auto it : tidTable) { + const char* name = it.second.getName(); + if (name) size += strlen(name) + 1; + } + log_id_for_each(id) { + size += uidTable[id].sizeOf(); + size += pidSystemTable[id].sizeOf(); + } + return size; + } + public: + LogStatistics(); void enableStatistics() { enable = true; } |
