summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHao Wang2017-12-04 00:10:40 -0600
committerliuchao2017-12-05 04:46:24 -0600
commitf6e229695375bda653a7f1b6f2470e054dc2d6bf (patch)
tree7c1a1e1f0facc2857425e6c81272cef15dd78de1 /logd/LogListener.cpp
parentebca57adecb3521d78e4e1e5c220df897f84e336 (diff)
downloadplatform-system-core-f6e229695375bda653a7f1b6f2470e054dc2d6bf.tar.gz
platform-system-core-f6e229695375bda653a7f1b6f2470e054dc2d6bf.tar.xz
platform-system-core-f6e229695375bda653a7f1b6f2470e054dc2d6bf.zip
logd: enhance multiple blocking readers performance
logd suffers performance degradation when multiple blocking readers connect to it. Each time when the writer thread log new entries, all of the readers are notified regardless of which log id they are watching. In this case, only give notification to the readers who are actually watching new entries' log id. This decreases logd CPU consumption by skipping unnecessary LogBuffer::flushTo loops. Test: liblog-unit-tests, logd-unit-tests & CtsLiblogTestCases logcat-unit-tests Test: manual: 1.'logcat –b all' at constant heavy logging load level 2.simultaneously 'logcat –b crash' in another session, a healthy crash buffer usually keep empty 3.logd CPU consumption doesn't increase after step 2 Change-Id: I4ffc045c9feb7a0998f7e47ae2173f8f6aa28e8a
Diffstat (limited to 'logd/LogListener.cpp')
-rwxr-xr-x[-rw-r--r--]logd/LogListener.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/logd/LogListener.cpp b/logd/LogListener.cpp
index fcf2cd8a1..fc51dcf08 100644..100755
--- a/logd/LogListener.cpp
+++ b/logd/LogListener.cpp
@@ -94,12 +94,13 @@ bool LogListener::onDataAvailable(SocketClient* cli) {
94 94
95 android_log_header_t* header = 95 android_log_header_t* header =
96 reinterpret_cast<android_log_header_t*>(buffer); 96 reinterpret_cast<android_log_header_t*>(buffer);
97 if (/* header->id < LOG_ID_MIN || */ header->id >= LOG_ID_MAX || 97 log_id_t logId = static_cast<log_id_t>(header->id);
98 header->id == LOG_ID_KERNEL) { 98 if (/* logId < LOG_ID_MIN || */ logId >= LOG_ID_MAX ||
99 logId == LOG_ID_KERNEL) {
99 return false; 100 return false;
100 } 101 }
101 102
102 if ((header->id == LOG_ID_SECURITY) && 103 if ((logId == LOG_ID_SECURITY) &&
103 (!__android_log_security() || 104 (!__android_log_security() ||
104 !clientHasLogCredentials(cred->uid, cred->gid, cred->pid))) { 105 !clientHasLogCredentials(cred->uid, cred->gid, cred->pid))) {
105 return false; 106 return false;
@@ -134,11 +135,10 @@ bool LogListener::onDataAvailable(SocketClient* cli) {
134 135
135 if (logbuf != nullptr) { 136 if (logbuf != nullptr) {
136 int res = logbuf->log( 137 int res = logbuf->log(
137 (log_id_t)header->id, header->realtime, cred->uid, cred->pid, 138 logId, header->realtime, cred->uid, cred->pid, header->tid, msg,
138 header->tid, msg,
139 ((size_t)n <= USHRT_MAX) ? (unsigned short)n : USHRT_MAX); 139 ((size_t)n <= USHRT_MAX) ? (unsigned short)n : USHRT_MAX);
140 if (res > 0 && reader != nullptr) { 140 if (res > 0 && reader != nullptr) {
141 reader->notifyNewLog(); 141 reader->notifyNewLog(static_cast<log_mask_t>(1 << logId));
142 } 142 }
143 } 143 }
144 144