diff options
author | Mark Salyzyn <salyzyn@google.com> | 2015-05-19 09:12:30 -0700 |
---|---|---|
committer | Mark Salyzyn <salyzyn@google.com> | 2015-06-04 11:03:37 -0700 |
commit | 6f1457adc58644f7c68829fd0872947bd7e63bfd (patch) | |
tree | 2e39d69d7ee3e3a3126202efa6e7bb9539c75291 /logd/LogBuffer.cpp | |
parent | 5d332907f0f845227847c31a122578dc910f1072 (diff) | |
download | system_core-6f1457adc58644f7c68829fd0872947bd7e63bfd.zip system_core-6f1457adc58644f7c68829fd0872947bd7e63bfd.tar.gz system_core-6f1457adc58644f7c68829fd0872947bd7e63bfd.tar.bz2 |
logd: switch to unordered_map from BasicHashtable
(charry pick from commit 511338dd575572d567c04d69eaea60627b6c3452)
BasicHashtable is relatively untested, move over to
a C++ template library that has more bake time.
Bug: 20419786
Bug: 21590652
Bug: 20500228
Change-Id: I926aaecdc8345eca75c08fdd561b0473504c5d95
Diffstat (limited to 'logd/LogBuffer.cpp')
-rw-r--r-- | logd/LogBuffer.cpp | 46 |
1 files changed, 18 insertions, 28 deletions
diff --git a/logd/LogBuffer.cpp b/logd/LogBuffer.cpp index 1da52d8..80fc9f5 100644 --- a/logd/LogBuffer.cpp +++ b/logd/LogBuffer.cpp @@ -22,6 +22,8 @@ #include <time.h> #include <unistd.h> +#include <unordered_map> + #include <cutils/properties.h> #include <log/logger.h> @@ -246,31 +248,21 @@ public: uint64_t getKey() { return value; } }; -class LogBufferElementEntry { - const uint64_t key; - LogBufferElement *last; - -public: - LogBufferElementEntry(const uint64_t &k, LogBufferElement *e):key(k),last(e) { } +class LogBufferElementLast { - const uint64_t&getKey() const { return key; } - - LogBufferElement *getLast() { return last; } -}; - -class LogBufferElementLast : public android::BasicHashtable<uint64_t, LogBufferElementEntry> { + typedef std::unordered_map<uint64_t, LogBufferElement *> LogBufferElementMap; + LogBufferElementMap map; public: + bool merge(LogBufferElement *e, unsigned short dropped) { LogBufferElementKey key(e->getUid(), e->getPid(), e->getTid()); - android::hash_t hash = android::hash_type(key.getKey()); - ssize_t index = find(-1, hash, key.getKey()); - if (index != -1) { - LogBufferElementEntry &entry = editEntryAt(index); - LogBufferElement *l = entry.getLast(); + LogBufferElementMap::iterator it = map.find(key.getKey()); + if (it != map.end()) { + LogBufferElement *l = it->second; unsigned short d = l->getDropped(); if ((dropped + d) > USHRT_MAX) { - removeAt(index); + map.erase(it); } else { l->setDropped(dropped + d); return true; @@ -279,26 +271,24 @@ public: return false; } - size_t add(LogBufferElement *e) { + void add(LogBufferElement *e) { LogBufferElementKey key(e->getUid(), e->getPid(), e->getTid()); - android::hash_t hash = android::hash_type(key.getKey()); - return android::BasicHashtable<uint64_t, LogBufferElementEntry>:: - add(hash, LogBufferElementEntry(key.getKey(), e)); + map[key.getKey()] = e; } inline void clear() { - android::BasicHashtable<uint64_t, LogBufferElementEntry>::clear(); + map.clear(); } void clear(LogBufferElement *e) { uint64_t current = e->getRealTime().nsec() - NS_PER_SEC; - ssize_t index = -1; - while((index = next(index)) >= 0) { - LogBufferElement *l = editEntryAt(index).getLast(); + for(LogBufferElementMap::iterator it = map.begin(); it != map.end();) { + LogBufferElement *l = it->second; if ((l->getDropped() >= EXPIRE_THRESHOLD) && (current > l->getRealTime().nsec())) { - removeAt(index); - index = -1; + it = map.erase(it); + } else { + ++it; } } } |