diff options
| author | Mark Salyzyn <salyzyn@google.com> | 2016-12-02 10:08:48 -0800 |
|---|---|---|
| committer | Mark Salyzyn <salyzyn@google.com> | 2016-12-09 12:40:17 -0800 |
| commit | 0eeb06b932f185e10377e4494475d2cdd6adfa1b (patch) | |
| tree | 70b797c0f3f752a6a76e9818640b1fadf06ca189 /logd | |
| parent | aece425166b1636de79efbddb5997ecdcea2ce03 (diff) | |
| download | system_core-0eeb06b932f185e10377e4494475d2cdd6adfa1b.tar.gz system_core-0eeb06b932f185e10377e4494475d2cdd6adfa1b.tar.bz2 system_core-0eeb06b932f185e10377e4494475d2cdd6adfa1b.zip | |
utils: Add FastStrcmp.h
Move existing fast<str*cmp> templates for general use, pulled from
the implementation used in logd that dealt with speed through cache
locality and subroutine call mitigation. Rename to fastcmp.
Test: logd-benchmarks and based on manual profiling from the past
Bug: 31456426
Change-Id: Ic62f4a437fc3e06ffdeaae73a6f34e197957a6b0
Diffstat (limited to 'logd')
| -rw-r--r-- | logd/LogBufferElement.cpp | 2 | ||||
| -rw-r--r-- | logd/LogKlog.cpp | 20 | ||||
| -rw-r--r-- | logd/LogReader.cpp | 2 | ||||
| -rw-r--r-- | logd/LogStatistics.cpp | 4 | ||||
| -rw-r--r-- | logd/LogStatistics.h | 4 | ||||
| -rw-r--r-- | logd/LogUtils.h | 18 |
6 files changed, 17 insertions, 33 deletions
diff --git a/logd/LogBufferElement.cpp b/logd/LogBufferElement.cpp index f5c60c72b..ec91f2a83 100644 --- a/logd/LogBufferElement.cpp +++ b/logd/LogBufferElement.cpp @@ -89,7 +89,7 @@ char *android::tidToName(pid_t tid) { size_t name_len = strlen(name); // KISS: ToDo: Only checks prefix truncated, not suffix, or both if ((retval_len < name_len) - && !fast<strcmp>(retval, name + name_len - retval_len)) { + && !fastcmp<strcmp>(retval, name + name_len - retval_len)) { free(retval); retval = name; } else { diff --git a/logd/LogKlog.cpp b/logd/LogKlog.cpp index 707353562..0b49fc1b3 100644 --- a/logd/LogKlog.cpp +++ b/logd/LogKlog.cpp @@ -321,7 +321,7 @@ static const char *strnstr(const char *s, size_t len, const char *needle) { } --len; } while (*s++ != c); - } while (fast<memcmp>(s, needle, needleLen)); + } while (fastcmp<memcmp>(s, needle, needleLen)); s--; } return s; @@ -640,7 +640,7 @@ int LogKlog::log(const char *buf, size_t len) { static const char infoBrace[] = "[INFO]"; static const size_t infoBraceLen = strlen(infoBrace); - if ((taglen >= infoBraceLen) && !fast<strncmp>(p, infoBrace, infoBraceLen)) { + if ((taglen >= infoBraceLen) && !fastcmp<strncmp>(p, infoBrace, infoBraceLen)) { // <PRI>[<TIME>] "[INFO]"<tag> ":" message bt = p + infoBraceLen; taglen -= infoBraceLen; @@ -675,7 +675,7 @@ int LogKlog::log(const char *buf, size_t len) { p = cp + 1; } else if ((taglen > size) && (tolower(*bt) == tolower(*cp))) { // clean up any tag stutter - if (!fast<strncasecmp>(bt + 1, cp + 1, size - 1)) { // no match + if (!fastcmp<strncasecmp>(bt + 1, cp + 1, size - 1)) { // no match // <PRI>[<TIME>] <tag> <tag> : message // <PRI>[<TIME>] <tag> <tag>: message // <PRI>[<TIME>] <tag> '<tag>.<num>' : message @@ -697,8 +697,8 @@ int LogKlog::log(const char *buf, size_t len) { static const char host[] = "_host"; static const size_t hostlen = strlen(host); if ((size > hostlen) && - !fast<strncmp>(bt + size - hostlen, host, hostlen) && - !fast<strncmp>(bt + 1, cp + 1, size - hostlen - 1)) { + !fastcmp<strncmp>(bt + size - hostlen, host, hostlen) && + !fastcmp<strncmp>(bt + 1, cp + 1, size - hostlen - 1)) { const char *b = cp; cp += size - hostlen; taglen -= size - hostlen; @@ -746,10 +746,10 @@ twoWord: while (--taglen && !isspace(*++cp) && (*cp != ':')); // register names like x18 but not driver names like en0 || ((size == 3) && (isdigit(tag[1]) && isdigit(tag[2]))) // blacklist - || ((size == cpuLen) && !fast<strncmp>(tag, cpu, cpuLen)) - || ((size == warningLen) && !fast<strncasecmp>(tag, warning, warningLen)) - || ((size == errorLen) && !fast<strncasecmp>(tag, error, errorLen)) - || ((size == infoLen) && !fast<strncasecmp>(tag, info, infoLen))) { + || ((size == cpuLen) && !fastcmp<strncmp>(tag, cpu, cpuLen)) + || ((size == warningLen) && !fastcmp<strncasecmp>(tag, warning, warningLen)) + || ((size == errorLen) && !fastcmp<strncasecmp>(tag, error, errorLen)) + || ((size == infoLen) && !fastcmp<strncasecmp>(tag, info, infoLen))) { p = start; etag = tag = ""; } @@ -761,7 +761,7 @@ twoWord: while (--taglen && !isspace(*++cp) && (*cp != ':')); const char *mp = strnrchr(tag, ']', taglen); if (mp && (++mp < etag)) { size_t s = etag - mp; - if (((s + s) < taglen) && !fast<memcmp>(mp, mp - 1 - s, s)) { + if (((s + s) < taglen) && !fastcmp<memcmp>(mp, mp - 1 - s, s)) { taglen = mp - tag; } } diff --git a/logd/LogReader.cpp b/logd/LogReader.cpp index 61d4c49f3..1b50b4ef2 100644 --- a/logd/LogReader.cpp +++ b/logd/LogReader.cpp @@ -108,7 +108,7 @@ bool LogReader::onDataAvailable(SocketClient *cli) { } bool nonBlock = false; - if (!fast<strncmp>(buffer, "dumpAndClose", 12)) { + if (!fastcmp<strncmp>(buffer, "dumpAndClose", 12)) { // Allow writer to get some cycles, and wait for pending notifications sched_yield(); LogTimeEntry::lock(); diff --git a/logd/LogStatistics.cpp b/logd/LogStatistics.cpp index d4b48ef9b..bab87bad9 100644 --- a/logd/LogStatistics.cpp +++ b/logd/LogStatistics.cpp @@ -53,7 +53,7 @@ char *pidToName(pid_t pid) { if (ret > 0) { buffer[sizeof(buffer)-1] = '\0'; // frameworks intermediate state - if (fast<strcmp>(buffer, "<pre-initialized>")) { + if (fastcmp<strcmp>(buffer, "<pre-initialized>")) { retval = strdup(buffer); } } @@ -209,7 +209,7 @@ const char *LogStatistics::uidToName(uid_t uid) const { if (nameTmp) { if (!name) { name = strdup(nameTmp); - } else if (fast<strcmp>(name, nameTmp)) { + } else if (fastcmp<strcmp>(name, nameTmp)) { free(const_cast<char *>(name)); name = NULL; break; diff --git a/logd/LogStatistics.h b/logd/LogStatistics.h index 1f598af8a..cb7ae2b69 100644 --- a/logd/LogStatistics.h +++ b/logd/LogStatistics.h @@ -307,7 +307,7 @@ struct PidEntry : public EntryBaseDropped { const char*getName() const { return name; } inline void add(pid_t newPid) { - if (name && !fast<strncmp>(name, "zygote", 6)) { + if (name && !fastcmp<strncmp>(name, "zygote", 6)) { free(name); name = NULL; } @@ -368,7 +368,7 @@ struct TidEntry : public EntryBaseDropped { const char*getName() const { return name; } inline void add(pid_t incomingTid) { - if (name && !fast<strncmp>(name, "zygote", 6)) { + if (name && !fastcmp<strncmp>(name, "zygote", 6)) { free(name); name = NULL; } diff --git a/logd/LogUtils.h b/logd/LogUtils.h index 44ac742f0..ec6806225 100644 --- a/logd/LogUtils.h +++ b/logd/LogUtils.h @@ -20,6 +20,7 @@ #include <sys/cdefs.h> #include <sys/types.h> +#include <utils/FastStrcmp.h> #include <private/android_logger.h> #include <sysutils/SocketClient.h> @@ -50,21 +51,4 @@ static inline bool worstUidEnabledForLogid(log_id_t id) { (id == LOG_ID_RADIO) || (id == LOG_ID_EVENTS); } -template <int (*cmp)(const char *l, const char *r, const size_t s)> -static inline int fast(const char *l, const char *r, const size_t s) { - return (*l != *r) || cmp(l + 1, r + 1, s - 1); -} - -template <int (*cmp)(const void *l, const void *r, const size_t s)> -static inline int fast(const void *lv, const void *rv, const size_t s) { - const char *l = static_cast<const char *>(lv); - const char *r = static_cast<const char *>(rv); - return (*l != *r) || cmp(l + 1, r + 1, s - 1); -} - -template <int (*cmp)(const char *l, const char *r)> -static inline int fast(const char *l, const char *r) { - return (*l != *r) || cmp(l + 1, r + 1); -} - #endif // _LOGD_LOG_UTILS_H__ |
