Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012-2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Mark Salyzyn | 4e756fb | 2014-05-06 07:34:59 -0700 | [diff] [blame] | 17 | #include <ctype.h> |
Mark Salyzyn | 88fe7cc | 2015-02-09 08:21:05 -0800 | [diff] [blame] | 18 | #include <errno.h> |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 19 | #include <stdio.h> |
| 20 | #include <string.h> |
Mark Salyzyn | 7b85c59 | 2014-05-09 17:44:18 -0700 | [diff] [blame] | 21 | #include <sys/user.h> |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 22 | #include <time.h> |
| 23 | #include <unistd.h> |
| 24 | |
Mark Salyzyn | 6a40419 | 2015-05-19 09:12:30 -0700 | [diff] [blame] | 25 | #include <unordered_map> |
| 26 | |
Mark Salyzyn | 4e756fb | 2014-05-06 07:34:59 -0700 | [diff] [blame] | 27 | #include <cutils/properties.h> |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 28 | #include <log/logger.h> |
| 29 | |
| 30 | #include "LogBuffer.h" |
Mark Salyzyn | 2b4a763 | 2015-09-08 08:56:32 -0700 | [diff] [blame] | 31 | #include "LogKlog.h" |
Mark Salyzyn | 4e756fb | 2014-05-06 07:34:59 -0700 | [diff] [blame] | 32 | #include "LogReader.h" |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 33 | |
Mark Salyzyn | c89839a | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 34 | // Default |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 35 | #define LOG_BUFFER_SIZE (256 * 1024) // Tuned on a per-platform basis here? |
Mark Salyzyn | c89839a | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 36 | #define log_buffer_size(id) mMaxSize[id] |
Mark Salyzyn | 7b85c59 | 2014-05-09 17:44:18 -0700 | [diff] [blame] | 37 | #define LOG_BUFFER_MIN_SIZE (64 * 1024UL) |
| 38 | #define LOG_BUFFER_MAX_SIZE (256 * 1024 * 1024UL) |
| 39 | |
| 40 | static bool valid_size(unsigned long value) { |
| 41 | if ((value < LOG_BUFFER_MIN_SIZE) || (LOG_BUFFER_MAX_SIZE < value)) { |
| 42 | return false; |
| 43 | } |
| 44 | |
| 45 | long pages = sysconf(_SC_PHYS_PAGES); |
| 46 | if (pages < 1) { |
| 47 | return true; |
| 48 | } |
| 49 | |
| 50 | long pagesize = sysconf(_SC_PAGESIZE); |
| 51 | if (pagesize <= 1) { |
| 52 | pagesize = PAGE_SIZE; |
| 53 | } |
| 54 | |
| 55 | // maximum memory impact a somewhat arbitrary ~3% |
| 56 | pages = (pages + 31) / 32; |
| 57 | unsigned long maximum = pages * pagesize; |
| 58 | |
| 59 | if ((maximum < LOG_BUFFER_MIN_SIZE) || (LOG_BUFFER_MAX_SIZE < maximum)) { |
| 60 | return true; |
| 61 | } |
| 62 | |
| 63 | return value <= maximum; |
| 64 | } |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 65 | |
Mark Salyzyn | 4e756fb | 2014-05-06 07:34:59 -0700 | [diff] [blame] | 66 | static unsigned long property_get_size(const char *key) { |
| 67 | char property[PROPERTY_VALUE_MAX]; |
| 68 | property_get(key, property, ""); |
| 69 | |
| 70 | char *cp; |
| 71 | unsigned long value = strtoul(property, &cp, 10); |
| 72 | |
| 73 | switch(*cp) { |
| 74 | case 'm': |
| 75 | case 'M': |
| 76 | value *= 1024; |
| 77 | /* FALLTHRU */ |
| 78 | case 'k': |
| 79 | case 'K': |
| 80 | value *= 1024; |
| 81 | /* FALLTHRU */ |
| 82 | case '\0': |
| 83 | break; |
| 84 | |
| 85 | default: |
| 86 | value = 0; |
| 87 | } |
| 88 | |
Mark Salyzyn | 7b85c59 | 2014-05-09 17:44:18 -0700 | [diff] [blame] | 89 | if (!valid_size(value)) { |
| 90 | value = 0; |
| 91 | } |
| 92 | |
Mark Salyzyn | 4e756fb | 2014-05-06 07:34:59 -0700 | [diff] [blame] | 93 | return value; |
| 94 | } |
| 95 | |
Mark Salyzyn | 3fe2593 | 2015-03-10 16:45:17 -0700 | [diff] [blame] | 96 | void LogBuffer::init() { |
Mark Salyzyn | 7b85c59 | 2014-05-09 17:44:18 -0700 | [diff] [blame] | 97 | static const char global_tuneable[] = "persist.logd.size"; // Settings App |
| 98 | static const char global_default[] = "ro.logd.size"; // BoardConfig.mk |
| 99 | |
| 100 | unsigned long default_size = property_get_size(global_tuneable); |
| 101 | if (!default_size) { |
| 102 | default_size = property_get_size(global_default); |
Mark Salyzyn | 973d18c | 2015-12-14 13:07:12 -0800 | [diff] [blame] | 103 | if (!default_size) { |
Mark Salyzyn | e19143e | 2015-12-14 16:40:12 -0800 | [diff] [blame] | 104 | default_size = property_get_bool("ro.config.low_ram", |
| 105 | BOOL_DEFAULT_FALSE) |
| 106 | ? LOG_BUFFER_MIN_SIZE // 64K |
| 107 | : LOG_BUFFER_SIZE; // 256K |
Mark Salyzyn | 973d18c | 2015-12-14 13:07:12 -0800 | [diff] [blame] | 108 | } |
Mark Salyzyn | 7b85c59 | 2014-05-09 17:44:18 -0700 | [diff] [blame] | 109 | } |
Mark Salyzyn | 4e756fb | 2014-05-06 07:34:59 -0700 | [diff] [blame] | 110 | |
Mark Salyzyn | c89839a | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 111 | log_id_for_each(i) { |
Mark Salyzyn | 4e756fb | 2014-05-06 07:34:59 -0700 | [diff] [blame] | 112 | char key[PROP_NAME_MAX]; |
Mark Salyzyn | 4e756fb | 2014-05-06 07:34:59 -0700 | [diff] [blame] | 113 | |
Mark Salyzyn | 7b85c59 | 2014-05-09 17:44:18 -0700 | [diff] [blame] | 114 | snprintf(key, sizeof(key), "%s.%s", |
| 115 | global_tuneable, android_log_id_to_name(i)); |
| 116 | unsigned long property_size = property_get_size(key); |
| 117 | |
| 118 | if (!property_size) { |
| 119 | snprintf(key, sizeof(key), "%s.%s", |
| 120 | global_default, android_log_id_to_name(i)); |
| 121 | property_size = property_get_size(key); |
| 122 | } |
| 123 | |
| 124 | if (!property_size) { |
| 125 | property_size = default_size; |
| 126 | } |
| 127 | |
| 128 | if (!property_size) { |
| 129 | property_size = LOG_BUFFER_SIZE; |
| 130 | } |
| 131 | |
| 132 | if (setSize(i, property_size)) { |
| 133 | setSize(i, LOG_BUFFER_MIN_SIZE); |
| 134 | } |
Mark Salyzyn | c89839a | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 135 | } |
Mark Salyzyn | 2b4a763 | 2015-09-08 08:56:32 -0700 | [diff] [blame] | 136 | bool lastMonotonic = monotonic; |
Mark Salyzyn | 2d4f9bc | 2015-12-01 15:57:25 -0800 | [diff] [blame] | 137 | monotonic = android_log_clockid() == CLOCK_MONOTONIC; |
Mark Salyzyn | 552b475 | 2015-11-30 11:35:56 -0800 | [diff] [blame] | 138 | if (lastMonotonic != monotonic) { |
| 139 | // |
| 140 | // Fixup all timestamps, may not be 100% accurate, but better than |
| 141 | // throwing what we have away when we get 'surprised' by a change. |
| 142 | // In-place element fixup so no need to check reader-lock. Entries |
| 143 | // should already be in timestamp order, but we could end up with a |
| 144 | // few out-of-order entries if new monotonics come in before we |
| 145 | // are notified of the reinit change in status. A Typical example would |
| 146 | // be: |
| 147 | // --------- beginning of system |
| 148 | // 10.494082 184 201 D Cryptfs : Just triggered post_fs_data |
| 149 | // --------- beginning of kernel |
| 150 | // 0.000000 0 0 I : Initializing cgroup subsys |
| 151 | // as the act of mounting /data would trigger persist.logd.timestamp to |
| 152 | // be corrected. 1/30 corner case YMMV. |
| 153 | // |
| 154 | pthread_mutex_lock(&mLogElementsLock); |
| 155 | LogBufferElementCollection::iterator it = mLogElements.begin(); |
| 156 | while((it != mLogElements.end())) { |
| 157 | LogBufferElement *e = *it; |
| 158 | if (monotonic) { |
| 159 | if (!android::isMonotonic(e->mRealTime)) { |
| 160 | LogKlog::convertRealToMonotonic(e->mRealTime); |
| 161 | } |
| 162 | } else { |
| 163 | if (android::isMonotonic(e->mRealTime)) { |
| 164 | LogKlog::convertMonotonicToReal(e->mRealTime); |
| 165 | } |
| 166 | } |
| 167 | ++it; |
| 168 | } |
| 169 | pthread_mutex_unlock(&mLogElementsLock); |
Mark Salyzyn | 2b4a763 | 2015-09-08 08:56:32 -0700 | [diff] [blame] | 170 | } |
| 171 | |
Mark Salyzyn | 552b475 | 2015-11-30 11:35:56 -0800 | [diff] [blame] | 172 | // We may have been triggered by a SIGHUP. Release any sleeping reader |
| 173 | // threads to dump their current content. |
Mark Salyzyn | 2b4a763 | 2015-09-08 08:56:32 -0700 | [diff] [blame] | 174 | // |
Mark Salyzyn | 552b475 | 2015-11-30 11:35:56 -0800 | [diff] [blame] | 175 | // NB: this is _not_ performed in the context of a SIGHUP, it is |
| 176 | // performed during startup, and in context of reinit administrative thread |
| 177 | LogTimeEntry::lock(); |
| 178 | |
| 179 | LastLogTimes::iterator times = mTimes.begin(); |
| 180 | while(times != mTimes.end()) { |
| 181 | LogTimeEntry *entry = (*times); |
| 182 | if (entry->owned_Locked()) { |
| 183 | entry->triggerReader_Locked(); |
Mark Salyzyn | 2b4a763 | 2015-09-08 08:56:32 -0700 | [diff] [blame] | 184 | } |
Mark Salyzyn | 552b475 | 2015-11-30 11:35:56 -0800 | [diff] [blame] | 185 | times++; |
Mark Salyzyn | 2b4a763 | 2015-09-08 08:56:32 -0700 | [diff] [blame] | 186 | } |
Mark Salyzyn | 552b475 | 2015-11-30 11:35:56 -0800 | [diff] [blame] | 187 | |
| 188 | LogTimeEntry::unlock(); |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 189 | } |
| 190 | |
Mark Salyzyn | 2b4a763 | 2015-09-08 08:56:32 -0700 | [diff] [blame] | 191 | LogBuffer::LogBuffer(LastLogTimes *times): |
Mark Salyzyn | 2d4f9bc | 2015-12-01 15:57:25 -0800 | [diff] [blame] | 192 | monotonic(android_log_clockid() == CLOCK_MONOTONIC), |
Mark Salyzyn | 2b4a763 | 2015-09-08 08:56:32 -0700 | [diff] [blame] | 193 | mTimes(*times) { |
Mark Salyzyn | 3fe2593 | 2015-03-10 16:45:17 -0700 | [diff] [blame] | 194 | pthread_mutex_init(&mLogElementsLock, NULL); |
| 195 | |
| 196 | init(); |
| 197 | } |
| 198 | |
Mark Salyzyn | 88fe7cc | 2015-02-09 08:21:05 -0800 | [diff] [blame] | 199 | int LogBuffer::log(log_id_t log_id, log_time realtime, |
| 200 | uid_t uid, pid_t pid, pid_t tid, |
| 201 | const char *msg, unsigned short len) { |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 202 | if ((log_id >= LOG_ID_MAX) || (log_id < 0)) { |
Mark Salyzyn | 88fe7cc | 2015-02-09 08:21:05 -0800 | [diff] [blame] | 203 | return -EINVAL; |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 204 | } |
Mark Salyzyn | 19c9111 | 2014-10-02 13:07:05 -0700 | [diff] [blame] | 205 | |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 206 | LogBufferElement *elem = new LogBufferElement(log_id, realtime, |
Mark Salyzyn | 3661dd0 | 2014-03-20 16:09:38 -0700 | [diff] [blame] | 207 | uid, pid, tid, msg, len); |
Mark Salyzyn | 4a8d250 | 2016-01-06 21:17:43 +0000 | [diff] [blame^] | 208 | if (log_id != LOG_ID_SECURITY) { |
Mark Salyzyn | 8885daf | 2015-12-04 10:59:45 -0800 | [diff] [blame] | 209 | int prio = ANDROID_LOG_INFO; |
Mark Salyzyn | 4a8d250 | 2016-01-06 21:17:43 +0000 | [diff] [blame^] | 210 | const char *tag = NULL; |
Mark Salyzyn | 8885daf | 2015-12-04 10:59:45 -0800 | [diff] [blame] | 211 | if (log_id == LOG_ID_EVENTS) { |
Mark Salyzyn | 4a8d250 | 2016-01-06 21:17:43 +0000 | [diff] [blame^] | 212 | tag = android::tagToName(elem->getTag()); |
Mark Salyzyn | 8885daf | 2015-12-04 10:59:45 -0800 | [diff] [blame] | 213 | } else { |
| 214 | prio = *msg; |
| 215 | tag = msg + 1; |
| 216 | } |
Mark Salyzyn | 4a8d250 | 2016-01-06 21:17:43 +0000 | [diff] [blame^] | 217 | if (!__android_log_is_loggable(prio, tag, ANDROID_LOG_VERBOSE)) { |
Mark Salyzyn | 8885daf | 2015-12-04 10:59:45 -0800 | [diff] [blame] | 218 | // Log traffic received to total |
| 219 | pthread_mutex_lock(&mLogElementsLock); |
| 220 | stats.add(elem); |
| 221 | stats.subtract(elem); |
| 222 | pthread_mutex_unlock(&mLogElementsLock); |
| 223 | delete elem; |
| 224 | return -EACCES; |
| 225 | } |
Mark Salyzyn | 19c9111 | 2014-10-02 13:07:05 -0700 | [diff] [blame] | 226 | } |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 227 | |
| 228 | pthread_mutex_lock(&mLogElementsLock); |
| 229 | |
| 230 | // Insert elements in time sorted order if possible |
| 231 | // NB: if end is region locked, place element at end of list |
| 232 | LogBufferElementCollection::iterator it = mLogElements.end(); |
| 233 | LogBufferElementCollection::iterator last = it; |
Mark Salyzyn | a222a77 | 2014-10-13 16:49:47 -0700 | [diff] [blame] | 234 | while (last != mLogElements.begin()) { |
| 235 | --it; |
Mark Salyzyn | 5b7a8d8 | 2014-02-18 11:23:53 -0800 | [diff] [blame] | 236 | if ((*it)->getRealTime() <= realtime) { |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 237 | break; |
| 238 | } |
| 239 | last = it; |
| 240 | } |
Mark Salyzyn | 5b7a8d8 | 2014-02-18 11:23:53 -0800 | [diff] [blame] | 241 | |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 242 | if (last == mLogElements.end()) { |
| 243 | mLogElements.push_back(elem); |
| 244 | } else { |
Mark Salyzyn | 0aaf6cd | 2015-03-03 13:39:37 -0800 | [diff] [blame] | 245 | uint64_t end = 1; |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 246 | bool end_set = false; |
| 247 | bool end_always = false; |
| 248 | |
| 249 | LogTimeEntry::lock(); |
| 250 | |
Mark Salyzyn | 538c6a9 | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 251 | LastLogTimes::iterator times = mTimes.begin(); |
| 252 | while(times != mTimes.end()) { |
| 253 | LogTimeEntry *entry = (*times); |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 254 | if (entry->owned_Locked()) { |
| 255 | if (!entry->mNonBlock) { |
| 256 | end_always = true; |
| 257 | break; |
| 258 | } |
| 259 | if (!end_set || (end <= entry->mEnd)) { |
| 260 | end = entry->mEnd; |
| 261 | end_set = true; |
| 262 | } |
| 263 | } |
Mark Salyzyn | 538c6a9 | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 264 | times++; |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | if (end_always |
Mark Salyzyn | 0aaf6cd | 2015-03-03 13:39:37 -0800 | [diff] [blame] | 268 | || (end_set && (end >= (*last)->getSequence()))) { |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 269 | mLogElements.push_back(elem); |
| 270 | } else { |
| 271 | mLogElements.insert(last,elem); |
| 272 | } |
| 273 | |
| 274 | LogTimeEntry::unlock(); |
| 275 | } |
| 276 | |
Mark Salyzyn | 9cf5d40 | 2015-03-10 13:51:35 -0700 | [diff] [blame] | 277 | stats.add(elem); |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 278 | maybePrune(log_id); |
| 279 | pthread_mutex_unlock(&mLogElementsLock); |
Mark Salyzyn | 88fe7cc | 2015-02-09 08:21:05 -0800 | [diff] [blame] | 280 | |
| 281 | return len; |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 282 | } |
| 283 | |
Mark Salyzyn | 95ff248 | 2015-09-30 07:40:09 -0700 | [diff] [blame] | 284 | // Prune at most 10% of the log entries or maxPrune, whichever is less. |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 285 | // |
| 286 | // mLogElementsLock must be held when this function is called. |
| 287 | void LogBuffer::maybePrune(log_id_t id) { |
Mark Salyzyn | d774bce | 2014-02-06 14:48:50 -0800 | [diff] [blame] | 288 | size_t sizes = stats.sizes(id); |
Mark Salyzyn | 4436d4c | 2015-08-10 10:23:56 -0700 | [diff] [blame] | 289 | unsigned long maxSize = log_buffer_size(id); |
| 290 | if (sizes > maxSize) { |
Mark Salyzyn | 6374572 | 2015-08-19 12:20:36 -0700 | [diff] [blame] | 291 | size_t sizeOver = sizes - ((maxSize * 9) / 10); |
Mark Salyzyn | d745c72 | 2015-09-30 07:40:09 -0700 | [diff] [blame] | 292 | size_t elements = stats.realElements(id); |
| 293 | size_t minElements = elements / 100; |
| 294 | if (minElements < minPrune) { |
| 295 | minElements = minPrune; |
| 296 | } |
Mark Salyzyn | 4436d4c | 2015-08-10 10:23:56 -0700 | [diff] [blame] | 297 | unsigned long pruneRows = elements * sizeOver / sizes; |
Mark Salyzyn | 95ff248 | 2015-09-30 07:40:09 -0700 | [diff] [blame] | 298 | if (pruneRows < minElements) { |
Mark Salyzyn | 4436d4c | 2015-08-10 10:23:56 -0700 | [diff] [blame] | 299 | pruneRows = minElements; |
Mark Salyzyn | 9d4e34e | 2014-01-13 16:37:51 -0800 | [diff] [blame] | 300 | } |
Mark Salyzyn | 95ff248 | 2015-09-30 07:40:09 -0700 | [diff] [blame] | 301 | if (pruneRows > maxPrune) { |
| 302 | pruneRows = maxPrune; |
Mark Salyzyn | 6374572 | 2015-08-19 12:20:36 -0700 | [diff] [blame] | 303 | } |
Mark Salyzyn | 9d4e34e | 2014-01-13 16:37:51 -0800 | [diff] [blame] | 304 | prune(id, pruneRows); |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 305 | } |
| 306 | } |
| 307 | |
Mark Salyzyn | 57b82a6 | 2015-09-03 16:08:50 -0700 | [diff] [blame] | 308 | LogBufferElementCollection::iterator LogBuffer::erase( |
Mark Salyzyn | 95ff248 | 2015-09-30 07:40:09 -0700 | [diff] [blame] | 309 | LogBufferElementCollection::iterator it, bool coalesce) { |
Mark Salyzyn | 538c6a9 | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 310 | LogBufferElement *element = *it; |
| 311 | log_id_t id = element->getLogId(); |
Mark Salyzyn | 9cf5d40 | 2015-03-10 13:51:35 -0700 | [diff] [blame] | 312 | |
Mark Salyzyn | 538c6a9 | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 313 | { // start of scope for uid found iterator |
| 314 | LogBufferIteratorMap::iterator found = |
| 315 | mLastWorstUid[id].find(element->getUid()); |
| 316 | if ((found != mLastWorstUid[id].end()) |
| 317 | && (it == found->second)) { |
| 318 | mLastWorstUid[id].erase(found); |
| 319 | } |
Mark Salyzyn | cfcffdaf | 2015-08-19 17:06:11 -0700 | [diff] [blame] | 320 | } |
Mark Salyzyn | 538c6a9 | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 321 | |
| 322 | if (element->getUid() == AID_SYSTEM) { |
| 323 | // start of scope for pid found iterator |
| 324 | LogBufferPidIteratorMap::iterator found = |
| 325 | mLastWorstPidOfSystem[id].find(element->getPid()); |
| 326 | if ((found != mLastWorstPidOfSystem[id].end()) |
| 327 | && (it == found->second)) { |
| 328 | mLastWorstPidOfSystem[id].erase(found); |
| 329 | } |
| 330 | } |
| 331 | |
Mark Salyzyn | 9cf5d40 | 2015-03-10 13:51:35 -0700 | [diff] [blame] | 332 | it = mLogElements.erase(it); |
Mark Salyzyn | 95ff248 | 2015-09-30 07:40:09 -0700 | [diff] [blame] | 333 | if (coalesce) { |
Mark Salyzyn | 538c6a9 | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 334 | stats.erase(element); |
Mark Salyzyn | 95ff248 | 2015-09-30 07:40:09 -0700 | [diff] [blame] | 335 | } else { |
Mark Salyzyn | 538c6a9 | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 336 | stats.subtract(element); |
Mark Salyzyn | 57b82a6 | 2015-09-03 16:08:50 -0700 | [diff] [blame] | 337 | } |
Mark Salyzyn | 538c6a9 | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 338 | delete element; |
Mark Salyzyn | 9cf5d40 | 2015-03-10 13:51:35 -0700 | [diff] [blame] | 339 | |
| 340 | return it; |
| 341 | } |
| 342 | |
Mark Salyzyn | d84b27e | 2015-04-17 15:38:04 -0700 | [diff] [blame] | 343 | // Define a temporary mechanism to report the last LogBufferElement pointer |
| 344 | // for the specified uid, pid and tid. Used below to help merge-sort when |
| 345 | // pruning for worst UID. |
| 346 | class LogBufferElementKey { |
| 347 | const union { |
| 348 | struct { |
| 349 | uint16_t uid; |
| 350 | uint16_t pid; |
| 351 | uint16_t tid; |
| 352 | uint16_t padding; |
| 353 | } __packed; |
| 354 | uint64_t value; |
| 355 | } __packed; |
| 356 | |
| 357 | public: |
Mark Salyzyn | 538c6a9 | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 358 | LogBufferElementKey(uid_t uid, pid_t pid, pid_t tid): |
| 359 | uid(uid), |
| 360 | pid(pid), |
| 361 | tid(tid), |
| 362 | padding(0) { |
| 363 | } |
| 364 | LogBufferElementKey(uint64_t key):value(key) { } |
Mark Salyzyn | d84b27e | 2015-04-17 15:38:04 -0700 | [diff] [blame] | 365 | |
| 366 | uint64_t getKey() { return value; } |
| 367 | }; |
| 368 | |
Mark Salyzyn | 6a40419 | 2015-05-19 09:12:30 -0700 | [diff] [blame] | 369 | class LogBufferElementLast { |
| 370 | |
| 371 | typedef std::unordered_map<uint64_t, LogBufferElement *> LogBufferElementMap; |
| 372 | LogBufferElementMap map; |
Mark Salyzyn | d84b27e | 2015-04-17 15:38:04 -0700 | [diff] [blame] | 373 | |
| 374 | public: |
Mark Salyzyn | d84b27e | 2015-04-17 15:38:04 -0700 | [diff] [blame] | 375 | |
Mark Salyzyn | 538c6a9 | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 376 | bool coalesce(LogBufferElement *element, unsigned short dropped) { |
| 377 | LogBufferElementKey key(element->getUid(), |
| 378 | element->getPid(), |
| 379 | element->getTid()); |
Mark Salyzyn | 6a40419 | 2015-05-19 09:12:30 -0700 | [diff] [blame] | 380 | LogBufferElementMap::iterator it = map.find(key.getKey()); |
| 381 | if (it != map.end()) { |
Mark Salyzyn | 538c6a9 | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 382 | LogBufferElement *found = it->second; |
| 383 | unsigned short moreDropped = found->getDropped(); |
| 384 | if ((dropped + moreDropped) > USHRT_MAX) { |
Mark Salyzyn | 6a40419 | 2015-05-19 09:12:30 -0700 | [diff] [blame] | 385 | map.erase(it); |
Mark Salyzyn | d84b27e | 2015-04-17 15:38:04 -0700 | [diff] [blame] | 386 | } else { |
Mark Salyzyn | 538c6a9 | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 387 | found->setDropped(dropped + moreDropped); |
Mark Salyzyn | d84b27e | 2015-04-17 15:38:04 -0700 | [diff] [blame] | 388 | return true; |
| 389 | } |
| 390 | } |
| 391 | return false; |
| 392 | } |
| 393 | |
Mark Salyzyn | 538c6a9 | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 394 | void add(LogBufferElement *element) { |
| 395 | LogBufferElementKey key(element->getUid(), |
| 396 | element->getPid(), |
| 397 | element->getTid()); |
| 398 | map[key.getKey()] = element; |
Mark Salyzyn | d84b27e | 2015-04-17 15:38:04 -0700 | [diff] [blame] | 399 | } |
| 400 | |
Mark Salyzyn | be1a30c | 2015-04-20 14:08:56 -0700 | [diff] [blame] | 401 | inline void clear() { |
Mark Salyzyn | 6a40419 | 2015-05-19 09:12:30 -0700 | [diff] [blame] | 402 | map.clear(); |
Mark Salyzyn | be1a30c | 2015-04-20 14:08:56 -0700 | [diff] [blame] | 403 | } |
| 404 | |
Mark Salyzyn | 538c6a9 | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 405 | void clear(LogBufferElement *element) { |
| 406 | uint64_t current = element->getRealTime().nsec() |
Mark Salyzyn | 80c1fc6 | 2015-06-04 13:35:30 -0700 | [diff] [blame] | 407 | - (EXPIRE_RATELIMIT * NS_PER_SEC); |
Mark Salyzyn | 6a40419 | 2015-05-19 09:12:30 -0700 | [diff] [blame] | 408 | for(LogBufferElementMap::iterator it = map.begin(); it != map.end();) { |
Mark Salyzyn | 538c6a9 | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 409 | LogBufferElement *mapElement = it->second; |
| 410 | if ((mapElement->getDropped() >= EXPIRE_THRESHOLD) |
| 411 | && (current > mapElement->getRealTime().nsec())) { |
Mark Salyzyn | 6a40419 | 2015-05-19 09:12:30 -0700 | [diff] [blame] | 412 | it = map.erase(it); |
| 413 | } else { |
| 414 | ++it; |
Mark Salyzyn | be1a30c | 2015-04-20 14:08:56 -0700 | [diff] [blame] | 415 | } |
| 416 | } |
| 417 | } |
| 418 | |
Mark Salyzyn | d84b27e | 2015-04-17 15:38:04 -0700 | [diff] [blame] | 419 | }; |
| 420 | |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 421 | // prune "pruneRows" of type "id" from the buffer. |
| 422 | // |
Mark Salyzyn | 50e2108 | 2015-09-08 09:12:51 -0700 | [diff] [blame] | 423 | // This garbage collection task is used to expire log entries. It is called to |
| 424 | // remove all logs (clear), all UID logs (unprivileged clear), or every |
| 425 | // 256 or 10% of the total logs (whichever is less) to prune the logs. |
| 426 | // |
| 427 | // First there is a prep phase where we discover the reader region lock that |
| 428 | // acts as a backstop to any pruning activity to stop there and go no further. |
| 429 | // |
| 430 | // There are three major pruning loops that follow. All expire from the oldest |
| 431 | // entries. Since there are multiple log buffers, the Android logging facility |
| 432 | // will appear to drop entries 'in the middle' when looking at multiple log |
| 433 | // sources and buffers. This effect is slightly more prominent when we prune |
| 434 | // the worst offender by logging source. Thus the logs slowly loose content |
| 435 | // and value as you move back in time. This is preferred since chatty sources |
| 436 | // invariably move the logs value down faster as less chatty sources would be |
| 437 | // expired in the noise. |
| 438 | // |
| 439 | // The first loop performs blacklisting and worst offender pruning. Falling |
| 440 | // through when there are no notable worst offenders and have not hit the |
| 441 | // region lock preventing further worst offender pruning. This loop also looks |
| 442 | // after managing the chatty log entries and merging to help provide |
| 443 | // statistical basis for blame. The chatty entries are not a notification of |
| 444 | // how much logs you may have, but instead represent how much logs you would |
| 445 | // have had in a virtual log buffer that is extended to cover all the in-memory |
| 446 | // logs without loss. They last much longer than the represented pruned logs |
| 447 | // since they get multiplied by the gains in the non-chatty log sources. |
| 448 | // |
| 449 | // The second loop get complicated because an algorithm of watermarks and |
| 450 | // history is maintained to reduce the order and keep processing time |
| 451 | // down to a minimum at scale. These algorithms can be costly in the face |
| 452 | // of larger log buffers, or severly limited processing time granted to a |
| 453 | // background task at lowest priority. |
| 454 | // |
| 455 | // This second loop does straight-up expiration from the end of the logs |
| 456 | // (again, remember for the specified log buffer id) but does some whitelist |
| 457 | // preservation. Thus whitelist is a Hail Mary low priority, blacklists and |
| 458 | // spam filtration all take priority. This second loop also checks if a region |
| 459 | // lock is causing us to buffer too much in the logs to help the reader(s), |
| 460 | // and will tell the slowest reader thread to skip log entries, and if |
| 461 | // persistent and hits a further threshold, kill the reader thread. |
| 462 | // |
| 463 | // The third thread is optional, and only gets hit if there was a whitelist |
| 464 | // and more needs to be pruned against the backstop of the region lock. |
| 465 | // |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 466 | // mLogElementsLock must be held when this function is called. |
Mark Salyzyn | 50e2108 | 2015-09-08 09:12:51 -0700 | [diff] [blame] | 467 | // |
Mark Salyzyn | 7702c3e | 2015-09-16 15:34:00 -0700 | [diff] [blame] | 468 | bool LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) { |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 469 | LogTimeEntry *oldest = NULL; |
Mark Salyzyn | 7702c3e | 2015-09-16 15:34:00 -0700 | [diff] [blame] | 470 | bool busy = false; |
Mark Salyzyn | d280d81 | 2015-09-16 15:34:00 -0700 | [diff] [blame] | 471 | bool clearAll = pruneRows == ULONG_MAX; |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 472 | |
| 473 | LogTimeEntry::lock(); |
| 474 | |
| 475 | // Region locked? |
Mark Salyzyn | 538c6a9 | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 476 | LastLogTimes::iterator times = mTimes.begin(); |
| 477 | while(times != mTimes.end()) { |
| 478 | LogTimeEntry *entry = (*times); |
TraianX Schiau | 6ba427e | 2014-12-17 10:53:41 +0200 | [diff] [blame] | 479 | if (entry->owned_Locked() && entry->isWatching(id) |
Mark Salyzyn | 552b475 | 2015-11-30 11:35:56 -0800 | [diff] [blame] | 480 | && (!oldest || |
| 481 | (oldest->mStart > entry->mStart) || |
| 482 | ((oldest->mStart == entry->mStart) && |
| 483 | (entry->mTimeout.tv_sec || entry->mTimeout.tv_nsec)))) { |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 484 | oldest = entry; |
| 485 | } |
Mark Salyzyn | 538c6a9 | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 486 | times++; |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 487 | } |
| 488 | |
Mark Salyzyn | 5c06ca4 | 2014-02-06 18:11:13 -0800 | [diff] [blame] | 489 | LogBufferElementCollection::iterator it; |
| 490 | |
Mark Salyzyn | 276d535 | 2014-06-12 11:16:16 -0700 | [diff] [blame] | 491 | if (caller_uid != AID_ROOT) { |
Mark Salyzyn | d280d81 | 2015-09-16 15:34:00 -0700 | [diff] [blame] | 492 | // Only here if clearAll condition (pruneRows == ULONG_MAX) |
Mark Salyzyn | 276d535 | 2014-06-12 11:16:16 -0700 | [diff] [blame] | 493 | for(it = mLogElements.begin(); it != mLogElements.end();) { |
Mark Salyzyn | 538c6a9 | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 494 | LogBufferElement *element = *it; |
Mark Salyzyn | 276d535 | 2014-06-12 11:16:16 -0700 | [diff] [blame] | 495 | |
Mark Salyzyn | 538c6a9 | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 496 | if ((element->getLogId() != id) || (element->getUid() != caller_uid)) { |
Mark Salyzyn | d280d81 | 2015-09-16 15:34:00 -0700 | [diff] [blame] | 497 | ++it; |
| 498 | continue; |
| 499 | } |
| 500 | |
Mark Salyzyn | 538c6a9 | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 501 | if (oldest && (oldest->mStart <= element->getSequence())) { |
Mark Salyzyn | 7702c3e | 2015-09-16 15:34:00 -0700 | [diff] [blame] | 502 | busy = true; |
Mark Salyzyn | 552b475 | 2015-11-30 11:35:56 -0800 | [diff] [blame] | 503 | if (oldest->mTimeout.tv_sec || oldest->mTimeout.tv_nsec) { |
| 504 | oldest->triggerReader_Locked(); |
| 505 | } else { |
| 506 | oldest->triggerSkip_Locked(id, pruneRows); |
| 507 | } |
Mark Salyzyn | 276d535 | 2014-06-12 11:16:16 -0700 | [diff] [blame] | 508 | break; |
| 509 | } |
| 510 | |
Mark Salyzyn | d280d81 | 2015-09-16 15:34:00 -0700 | [diff] [blame] | 511 | it = erase(it); |
| 512 | pruneRows--; |
Mark Salyzyn | 276d535 | 2014-06-12 11:16:16 -0700 | [diff] [blame] | 513 | } |
| 514 | LogTimeEntry::unlock(); |
Mark Salyzyn | 7702c3e | 2015-09-16 15:34:00 -0700 | [diff] [blame] | 515 | return busy; |
Mark Salyzyn | 276d535 | 2014-06-12 11:16:16 -0700 | [diff] [blame] | 516 | } |
| 517 | |
Mark Salyzyn | 538c6a9 | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 518 | // prune by worst offenders; by blacklist, UID, and by PID of system UID |
Mark Salyzyn | 8885daf | 2015-12-04 10:59:45 -0800 | [diff] [blame] | 519 | bool hasBlacklist = (id != LOG_ID_SECURITY) && mPrune.naughty(); |
Mark Salyzyn | d280d81 | 2015-09-16 15:34:00 -0700 | [diff] [blame] | 520 | while (!clearAll && (pruneRows > 0)) { |
Mark Salyzyn | 5c06ca4 | 2014-02-06 18:11:13 -0800 | [diff] [blame] | 521 | // recalculate the worst offender on every batched pass |
| 522 | uid_t worst = (uid_t) -1; |
| 523 | size_t worst_sizes = 0; |
| 524 | size_t second_worst_sizes = 0; |
Mark Salyzyn | 538c6a9 | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 525 | pid_t worstPid = 0; // POSIX guarantees PID != 0 |
Mark Salyzyn | 5c06ca4 | 2014-02-06 18:11:13 -0800 | [diff] [blame] | 526 | |
Mark Salyzyn | 0e765c6 | 2015-03-17 17:17:25 -0700 | [diff] [blame] | 527 | if (worstUidEnabledForLogid(id) && mPrune.worstUidEnabled()) { |
Mark Salyzyn | 538c6a9 | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 528 | { // begin scope for UID sorted list |
| 529 | std::unique_ptr<const UidEntry *[]> sorted = stats.sort( |
| 530 | AID_ROOT, (pid_t)0, 2, id); |
Mark Salyzyn | 9cf5d40 | 2015-03-10 13:51:35 -0700 | [diff] [blame] | 531 | |
Mark Salyzyn | 538c6a9 | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 532 | if (sorted.get() && sorted[0] && sorted[1]) { |
Mark Salyzyn | 9cf5d40 | 2015-03-10 13:51:35 -0700 | [diff] [blame] | 533 | worst_sizes = sorted[0]->getSizes(); |
Mark Salyzyn | 84a8398 | 2015-04-20 15:36:12 -0700 | [diff] [blame] | 534 | // Calculate threshold as 12.5% of available storage |
| 535 | size_t threshold = log_buffer_size(id) / 8; |
Mark Salyzyn | 2b9465b | 2015-10-12 13:45:51 -0700 | [diff] [blame] | 536 | if ((worst_sizes > threshold) |
| 537 | // Allow time horizon to extend roughly tenfold, assume |
| 538 | // average entry length is 100 characters. |
| 539 | && (worst_sizes > (10 * sorted[0]->getDropped()))) { |
Mark Salyzyn | 84a8398 | 2015-04-20 15:36:12 -0700 | [diff] [blame] | 540 | worst = sorted[0]->getKey(); |
| 541 | second_worst_sizes = sorted[1]->getSizes(); |
| 542 | if (second_worst_sizes < threshold) { |
| 543 | second_worst_sizes = threshold; |
| 544 | } |
| 545 | } |
Mark Salyzyn | c89839a | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 546 | } |
Mark Salyzyn | 5c06ca4 | 2014-02-06 18:11:13 -0800 | [diff] [blame] | 547 | } |
Mark Salyzyn | 538c6a9 | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 548 | |
| 549 | if ((worst == AID_SYSTEM) && mPrune.worstPidOfSystemEnabled()) { |
| 550 | // begin scope of PID sorted list |
| 551 | std::unique_ptr<const PidEntry *[]> sorted = stats.sort( |
| 552 | worst, (pid_t)0, 2, id, worst); |
| 553 | if (sorted.get() && sorted[0] && sorted[1]) { |
| 554 | worstPid = sorted[0]->getKey(); |
| 555 | second_worst_sizes = worst_sizes |
| 556 | - sorted[0]->getSizes() |
| 557 | + sorted[1]->getSizes(); |
| 558 | } |
| 559 | } |
Mark Salyzyn | 5c06ca4 | 2014-02-06 18:11:13 -0800 | [diff] [blame] | 560 | } |
| 561 | |
Mark Salyzyn | 9cf5d40 | 2015-03-10 13:51:35 -0700 | [diff] [blame] | 562 | // skip if we have neither worst nor naughty filters |
| 563 | if ((worst == (uid_t) -1) && !hasBlacklist) { |
| 564 | break; |
| 565 | } |
| 566 | |
Mark Salyzyn | 5c06ca4 | 2014-02-06 18:11:13 -0800 | [diff] [blame] | 567 | bool kick = false; |
Mark Salyzyn | a69d5a4 | 2015-03-16 12:04:09 -0700 | [diff] [blame] | 568 | bool leading = true; |
Mark Salyzyn | cfcffdaf | 2015-08-19 17:06:11 -0700 | [diff] [blame] | 569 | it = mLogElements.begin(); |
Mark Salyzyn | 50e2108 | 2015-09-08 09:12:51 -0700 | [diff] [blame] | 570 | // Perform at least one mandatory garbage collection cycle in following |
| 571 | // - clear leading chatty tags |
Mark Salyzyn | 95ff248 | 2015-09-30 07:40:09 -0700 | [diff] [blame] | 572 | // - coalesce chatty tags |
Mark Salyzyn | 50e2108 | 2015-09-08 09:12:51 -0700 | [diff] [blame] | 573 | // - check age-out of preserved logs |
| 574 | bool gc = pruneRows <= 1; |
| 575 | if (!gc && (worst != (uid_t) -1)) { |
Mark Salyzyn | 538c6a9 | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 576 | { // begin scope for uid worst found iterator |
| 577 | LogBufferIteratorMap::iterator found = mLastWorstUid[id].find(worst); |
| 578 | if ((found != mLastWorstUid[id].end()) |
| 579 | && (found->second != mLogElements.end())) { |
| 580 | leading = false; |
| 581 | it = found->second; |
| 582 | } |
| 583 | } |
| 584 | if (worstPid) { |
| 585 | // begin scope for pid worst found iterator |
| 586 | LogBufferPidIteratorMap::iterator found |
| 587 | = mLastWorstPidOfSystem[id].find(worstPid); |
| 588 | if ((found != mLastWorstPidOfSystem[id].end()) |
| 589 | && (found->second != mLogElements.end())) { |
| 590 | leading = false; |
| 591 | it = found->second; |
| 592 | } |
Mark Salyzyn | cfcffdaf | 2015-08-19 17:06:11 -0700 | [diff] [blame] | 593 | } |
| 594 | } |
Mark Salyzyn | 4e29e17 | 2015-08-24 13:43:27 -0700 | [diff] [blame] | 595 | static const timespec too_old = { |
| 596 | EXPIRE_HOUR_THRESHOLD * 60 * 60, 0 |
| 597 | }; |
| 598 | LogBufferElementCollection::iterator lastt; |
| 599 | lastt = mLogElements.end(); |
| 600 | --lastt; |
Mark Salyzyn | d84b27e | 2015-04-17 15:38:04 -0700 | [diff] [blame] | 601 | LogBufferElementLast last; |
Mark Salyzyn | cfcffdaf | 2015-08-19 17:06:11 -0700 | [diff] [blame] | 602 | while (it != mLogElements.end()) { |
Mark Salyzyn | 538c6a9 | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 603 | LogBufferElement *element = *it; |
Mark Salyzyn | 5c06ca4 | 2014-02-06 18:11:13 -0800 | [diff] [blame] | 604 | |
Mark Salyzyn | 538c6a9 | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 605 | if (oldest && (oldest->mStart <= element->getSequence())) { |
Mark Salyzyn | 7702c3e | 2015-09-16 15:34:00 -0700 | [diff] [blame] | 606 | busy = true; |
Mark Salyzyn | 552b475 | 2015-11-30 11:35:56 -0800 | [diff] [blame] | 607 | if (oldest->mTimeout.tv_sec || oldest->mTimeout.tv_nsec) { |
| 608 | oldest->triggerReader_Locked(); |
| 609 | } |
Mark Salyzyn | 5c06ca4 | 2014-02-06 18:11:13 -0800 | [diff] [blame] | 610 | break; |
| 611 | } |
| 612 | |
Mark Salyzyn | 538c6a9 | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 613 | if (element->getLogId() != id) { |
Mark Salyzyn | c89839a | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 614 | ++it; |
| 615 | continue; |
| 616 | } |
| 617 | |
Mark Salyzyn | 538c6a9 | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 618 | unsigned short dropped = element->getDropped(); |
Mark Salyzyn | c89839a | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 619 | |
Mark Salyzyn | a69d5a4 | 2015-03-16 12:04:09 -0700 | [diff] [blame] | 620 | // remove any leading drops |
| 621 | if (leading && dropped) { |
| 622 | it = erase(it); |
| 623 | continue; |
| 624 | } |
| 625 | |
Mark Salyzyn | 538c6a9 | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 626 | if (dropped && last.coalesce(element, dropped)) { |
Mark Salyzyn | 95ff248 | 2015-09-30 07:40:09 -0700 | [diff] [blame] | 627 | it = erase(it, true); |
Mark Salyzyn | a69d5a4 | 2015-03-16 12:04:09 -0700 | [diff] [blame] | 628 | continue; |
| 629 | } |
| 630 | |
Mark Salyzyn | 538c6a9 | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 631 | if (hasBlacklist && mPrune.naughty(element)) { |
| 632 | last.clear(element); |
Mark Salyzyn | a69d5a4 | 2015-03-16 12:04:09 -0700 | [diff] [blame] | 633 | it = erase(it); |
| 634 | if (dropped) { |
| 635 | continue; |
| 636 | } |
| 637 | |
| 638 | pruneRows--; |
| 639 | if (pruneRows == 0) { |
| 640 | break; |
| 641 | } |
| 642 | |
Mark Salyzyn | 538c6a9 | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 643 | if (element->getUid() == worst) { |
Mark Salyzyn | a69d5a4 | 2015-03-16 12:04:09 -0700 | [diff] [blame] | 644 | kick = true; |
| 645 | if (worst_sizes < second_worst_sizes) { |
| 646 | break; |
| 647 | } |
Mark Salyzyn | 538c6a9 | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 648 | worst_sizes -= element->getMsgLen(); |
Mark Salyzyn | a69d5a4 | 2015-03-16 12:04:09 -0700 | [diff] [blame] | 649 | } |
| 650 | continue; |
| 651 | } |
| 652 | |
Mark Salyzyn | 538c6a9 | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 653 | if ((element->getRealTime() < ((*lastt)->getRealTime() - too_old)) |
| 654 | || (element->getRealTime() > (*lastt)->getRealTime())) { |
Mark Salyzyn | 4e29e17 | 2015-08-24 13:43:27 -0700 | [diff] [blame] | 655 | break; |
| 656 | } |
| 657 | |
Mark Salyzyn | a69d5a4 | 2015-03-16 12:04:09 -0700 | [diff] [blame] | 658 | if (dropped) { |
Mark Salyzyn | 538c6a9 | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 659 | last.add(element); |
| 660 | if (worstPid |
| 661 | && ((!gc && (element->getPid() == worstPid)) |
| 662 | || (mLastWorstPidOfSystem[id].find(element->getPid()) |
| 663 | == mLastWorstPidOfSystem[id].end()))) { |
| 664 | mLastWorstPidOfSystem[id][element->getUid()] = it; |
| 665 | } |
| 666 | if ((!gc && !worstPid && (element->getUid() == worst)) |
| 667 | || (mLastWorstUid[id].find(element->getUid()) |
Mark Salyzyn | cb15c7c | 2015-08-24 13:43:27 -0700 | [diff] [blame] | 668 | == mLastWorstUid[id].end())) { |
Mark Salyzyn | 538c6a9 | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 669 | mLastWorstUid[id][element->getUid()] = it; |
Mark Salyzyn | cb15c7c | 2015-08-24 13:43:27 -0700 | [diff] [blame] | 670 | } |
Mark Salyzyn | 5c06ca4 | 2014-02-06 18:11:13 -0800 | [diff] [blame] | 671 | ++it; |
Mark Salyzyn | 9cf5d40 | 2015-03-10 13:51:35 -0700 | [diff] [blame] | 672 | continue; |
Mark Salyzyn | 5c06ca4 | 2014-02-06 18:11:13 -0800 | [diff] [blame] | 673 | } |
Mark Salyzyn | 9cf5d40 | 2015-03-10 13:51:35 -0700 | [diff] [blame] | 674 | |
Mark Salyzyn | 538c6a9 | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 675 | if ((element->getUid() != worst) |
| 676 | || (worstPid && (element->getPid() != worstPid))) { |
Mark Salyzyn | fd318a8 | 2015-06-01 09:41:19 -0700 | [diff] [blame] | 677 | leading = false; |
Mark Salyzyn | 538c6a9 | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 678 | last.clear(element); |
Mark Salyzyn | a69d5a4 | 2015-03-16 12:04:09 -0700 | [diff] [blame] | 679 | ++it; |
| 680 | continue; |
| 681 | } |
| 682 | |
Mark Salyzyn | 9cf5d40 | 2015-03-10 13:51:35 -0700 | [diff] [blame] | 683 | pruneRows--; |
| 684 | if (pruneRows == 0) { |
| 685 | break; |
| 686 | } |
| 687 | |
Mark Salyzyn | 9cf5d40 | 2015-03-10 13:51:35 -0700 | [diff] [blame] | 688 | kick = true; |
Mark Salyzyn | a69d5a4 | 2015-03-16 12:04:09 -0700 | [diff] [blame] | 689 | |
Mark Salyzyn | 538c6a9 | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 690 | unsigned short len = element->getMsgLen(); |
Mark Salyzyn | 65ec860 | 2015-05-22 10:03:31 -0700 | [diff] [blame] | 691 | |
| 692 | // do not create any leading drops |
| 693 | if (leading) { |
| 694 | it = erase(it); |
Mark Salyzyn | a69d5a4 | 2015-03-16 12:04:09 -0700 | [diff] [blame] | 695 | } else { |
Mark Salyzyn | 538c6a9 | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 696 | stats.drop(element); |
| 697 | element->setDropped(1); |
| 698 | if (last.coalesce(element, 1)) { |
Mark Salyzyn | 95ff248 | 2015-09-30 07:40:09 -0700 | [diff] [blame] | 699 | it = erase(it, true); |
Mark Salyzyn | 65ec860 | 2015-05-22 10:03:31 -0700 | [diff] [blame] | 700 | } else { |
Mark Salyzyn | 538c6a9 | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 701 | last.add(element); |
| 702 | if (worstPid && (!gc |
| 703 | || (mLastWorstPidOfSystem[id].find(worstPid) |
| 704 | == mLastWorstPidOfSystem[id].end()))) { |
| 705 | mLastWorstPidOfSystem[id][worstPid] = it; |
| 706 | } |
| 707 | if ((!gc && !worstPid) || (mLastWorstUid[id].find(worst) |
Mark Salyzyn | 50e2108 | 2015-09-08 09:12:51 -0700 | [diff] [blame] | 708 | == mLastWorstUid[id].end())) { |
| 709 | mLastWorstUid[id][worst] = it; |
| 710 | } |
Mark Salyzyn | 65ec860 | 2015-05-22 10:03:31 -0700 | [diff] [blame] | 711 | ++it; |
| 712 | } |
Mark Salyzyn | a69d5a4 | 2015-03-16 12:04:09 -0700 | [diff] [blame] | 713 | } |
Mark Salyzyn | 9cf5d40 | 2015-03-10 13:51:35 -0700 | [diff] [blame] | 714 | if (worst_sizes < second_worst_sizes) { |
| 715 | break; |
| 716 | } |
| 717 | worst_sizes -= len; |
Mark Salyzyn | 5c06ca4 | 2014-02-06 18:11:13 -0800 | [diff] [blame] | 718 | } |
Mark Salyzyn | d84b27e | 2015-04-17 15:38:04 -0700 | [diff] [blame] | 719 | last.clear(); |
Mark Salyzyn | 5c06ca4 | 2014-02-06 18:11:13 -0800 | [diff] [blame] | 720 | |
Mark Salyzyn | c402bc7 | 2014-04-01 17:19:47 -0700 | [diff] [blame] | 721 | if (!kick || !mPrune.worstUidEnabled()) { |
Mark Salyzyn | 5c06ca4 | 2014-02-06 18:11:13 -0800 | [diff] [blame] | 722 | break; // the following loop will ask bad clients to skip/drop |
| 723 | } |
| 724 | } |
| 725 | |
Mark Salyzyn | c89839a | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 726 | bool whitelist = false; |
Mark Salyzyn | 8885daf | 2015-12-04 10:59:45 -0800 | [diff] [blame] | 727 | bool hasWhitelist = (id != LOG_ID_SECURITY) && mPrune.nice() && !clearAll; |
Mark Salyzyn | 5c06ca4 | 2014-02-06 18:11:13 -0800 | [diff] [blame] | 728 | it = mLogElements.begin(); |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 729 | while((pruneRows > 0) && (it != mLogElements.end())) { |
Mark Salyzyn | 538c6a9 | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 730 | LogBufferElement *element = *it; |
Mark Salyzyn | 9cf5d40 | 2015-03-10 13:51:35 -0700 | [diff] [blame] | 731 | |
Mark Salyzyn | 538c6a9 | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 732 | if (element->getLogId() != id) { |
Mark Salyzyn | 9cf5d40 | 2015-03-10 13:51:35 -0700 | [diff] [blame] | 733 | it++; |
| 734 | continue; |
| 735 | } |
| 736 | |
Mark Salyzyn | 538c6a9 | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 737 | if (oldest && (oldest->mStart <= element->getSequence())) { |
Mark Salyzyn | 7702c3e | 2015-09-16 15:34:00 -0700 | [diff] [blame] | 738 | busy = true; |
Mark Salyzyn | 9cf5d40 | 2015-03-10 13:51:35 -0700 | [diff] [blame] | 739 | if (whitelist) { |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 740 | break; |
| 741 | } |
Mark Salyzyn | c402bc7 | 2014-04-01 17:19:47 -0700 | [diff] [blame] | 742 | |
Mark Salyzyn | 9cf5d40 | 2015-03-10 13:51:35 -0700 | [diff] [blame] | 743 | if (stats.sizes(id) > (2 * log_buffer_size(id))) { |
| 744 | // kick a misbehaving log reader client off the island |
| 745 | oldest->release_Locked(); |
Mark Salyzyn | 552b475 | 2015-11-30 11:35:56 -0800 | [diff] [blame] | 746 | } else if (oldest->mTimeout.tv_sec || oldest->mTimeout.tv_nsec) { |
| 747 | oldest->triggerReader_Locked(); |
Mark Salyzyn | 9cf5d40 | 2015-03-10 13:51:35 -0700 | [diff] [blame] | 748 | } else { |
| 749 | oldest->triggerSkip_Locked(id, pruneRows); |
Mark Salyzyn | c89839a | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 750 | } |
Mark Salyzyn | 9cf5d40 | 2015-03-10 13:51:35 -0700 | [diff] [blame] | 751 | break; |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 752 | } |
Mark Salyzyn | 9cf5d40 | 2015-03-10 13:51:35 -0700 | [diff] [blame] | 753 | |
Mark Salyzyn | 538c6a9 | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 754 | if (hasWhitelist && !element->getDropped() && mPrune.nice(element)) { |
| 755 | // WhiteListed |
Mark Salyzyn | 9cf5d40 | 2015-03-10 13:51:35 -0700 | [diff] [blame] | 756 | whitelist = true; |
| 757 | it++; |
| 758 | continue; |
| 759 | } |
| 760 | |
| 761 | it = erase(it); |
| 762 | pruneRows--; |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 763 | } |
| 764 | |
Mark Salyzyn | 9cf5d40 | 2015-03-10 13:51:35 -0700 | [diff] [blame] | 765 | // Do not save the whitelist if we are reader range limited |
Mark Salyzyn | c89839a | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 766 | if (whitelist && (pruneRows > 0)) { |
| 767 | it = mLogElements.begin(); |
| 768 | while((it != mLogElements.end()) && (pruneRows > 0)) { |
Mark Salyzyn | 538c6a9 | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 769 | LogBufferElement *element = *it; |
Mark Salyzyn | 9cf5d40 | 2015-03-10 13:51:35 -0700 | [diff] [blame] | 770 | |
Mark Salyzyn | 538c6a9 | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 771 | if (element->getLogId() != id) { |
Mark Salyzyn | 9cf5d40 | 2015-03-10 13:51:35 -0700 | [diff] [blame] | 772 | ++it; |
| 773 | continue; |
Mark Salyzyn | c89839a | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 774 | } |
Mark Salyzyn | 9cf5d40 | 2015-03-10 13:51:35 -0700 | [diff] [blame] | 775 | |
Mark Salyzyn | 538c6a9 | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 776 | if (oldest && (oldest->mStart <= element->getSequence())) { |
Mark Salyzyn | 7702c3e | 2015-09-16 15:34:00 -0700 | [diff] [blame] | 777 | busy = true; |
Mark Salyzyn | 9cf5d40 | 2015-03-10 13:51:35 -0700 | [diff] [blame] | 778 | if (stats.sizes(id) > (2 * log_buffer_size(id))) { |
| 779 | // kick a misbehaving log reader client off the island |
| 780 | oldest->release_Locked(); |
Mark Salyzyn | 552b475 | 2015-11-30 11:35:56 -0800 | [diff] [blame] | 781 | } else if (oldest->mTimeout.tv_sec || oldest->mTimeout.tv_nsec) { |
| 782 | oldest->triggerReader_Locked(); |
Mark Salyzyn | 9cf5d40 | 2015-03-10 13:51:35 -0700 | [diff] [blame] | 783 | } else { |
| 784 | oldest->triggerSkip_Locked(id, pruneRows); |
| 785 | } |
| 786 | break; |
| 787 | } |
| 788 | |
| 789 | it = erase(it); |
| 790 | pruneRows--; |
Mark Salyzyn | c89839a | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 791 | } |
| 792 | } |
Mark Salyzyn | c89839a | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 793 | |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 794 | LogTimeEntry::unlock(); |
Mark Salyzyn | 7702c3e | 2015-09-16 15:34:00 -0700 | [diff] [blame] | 795 | |
| 796 | return (pruneRows > 0) && busy; |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | // clear all rows of type "id" from the buffer. |
Mark Salyzyn | 7702c3e | 2015-09-16 15:34:00 -0700 | [diff] [blame] | 800 | bool LogBuffer::clear(log_id_t id, uid_t uid) { |
| 801 | bool busy = true; |
| 802 | // If it takes more than 4 tries (seconds) to clear, then kill reader(s) |
| 803 | for (int retry = 4;;) { |
| 804 | if (retry == 1) { // last pass |
| 805 | // Check if it is still busy after the sleep, we say prune |
| 806 | // one entry, not another clear run, so we are looking for |
| 807 | // the quick side effect of the return value to tell us if |
| 808 | // we have a _blocked_ reader. |
| 809 | pthread_mutex_lock(&mLogElementsLock); |
| 810 | busy = prune(id, 1, uid); |
| 811 | pthread_mutex_unlock(&mLogElementsLock); |
| 812 | // It is still busy, blocked reader(s), lets kill them all! |
| 813 | // otherwise, lets be a good citizen and preserve the slow |
| 814 | // readers and let the clear run (below) deal with determining |
| 815 | // if we are still blocked and return an error code to caller. |
| 816 | if (busy) { |
| 817 | LogTimeEntry::lock(); |
| 818 | LastLogTimes::iterator times = mTimes.begin(); |
| 819 | while (times != mTimes.end()) { |
| 820 | LogTimeEntry *entry = (*times); |
| 821 | // Killer punch |
| 822 | if (entry->owned_Locked() && entry->isWatching(id)) { |
| 823 | entry->release_Locked(); |
| 824 | } |
| 825 | times++; |
| 826 | } |
| 827 | LogTimeEntry::unlock(); |
| 828 | } |
| 829 | } |
| 830 | pthread_mutex_lock(&mLogElementsLock); |
| 831 | busy = prune(id, ULONG_MAX, uid); |
| 832 | pthread_mutex_unlock(&mLogElementsLock); |
| 833 | if (!busy || !--retry) { |
| 834 | break; |
| 835 | } |
| 836 | sleep (1); // Let reader(s) catch up after notification |
| 837 | } |
| 838 | return busy; |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 839 | } |
| 840 | |
| 841 | // get the used space associated with "id". |
| 842 | unsigned long LogBuffer::getSizeUsed(log_id_t id) { |
| 843 | pthread_mutex_lock(&mLogElementsLock); |
Mark Salyzyn | d774bce | 2014-02-06 14:48:50 -0800 | [diff] [blame] | 844 | size_t retval = stats.sizes(id); |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 845 | pthread_mutex_unlock(&mLogElementsLock); |
| 846 | return retval; |
| 847 | } |
| 848 | |
Mark Salyzyn | c89839a | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 849 | // set the total space allocated to "id" |
| 850 | int LogBuffer::setSize(log_id_t id, unsigned long size) { |
| 851 | // Reasonable limits ... |
Mark Salyzyn | 7b85c59 | 2014-05-09 17:44:18 -0700 | [diff] [blame] | 852 | if (!valid_size(size)) { |
Mark Salyzyn | c89839a | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 853 | return -1; |
| 854 | } |
| 855 | pthread_mutex_lock(&mLogElementsLock); |
| 856 | log_buffer_size(id) = size; |
| 857 | pthread_mutex_unlock(&mLogElementsLock); |
| 858 | return 0; |
| 859 | } |
| 860 | |
| 861 | // get the total space allocated to "id" |
| 862 | unsigned long LogBuffer::getSize(log_id_t id) { |
| 863 | pthread_mutex_lock(&mLogElementsLock); |
| 864 | size_t retval = log_buffer_size(id); |
| 865 | pthread_mutex_unlock(&mLogElementsLock); |
| 866 | return retval; |
| 867 | } |
| 868 | |
Mark Salyzyn | 0aaf6cd | 2015-03-03 13:39:37 -0800 | [diff] [blame] | 869 | uint64_t LogBuffer::flushTo( |
| 870 | SocketClient *reader, const uint64_t start, bool privileged, |
| 871 | int (*filter)(const LogBufferElement *element, void *arg), void *arg) { |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 872 | LogBufferElementCollection::iterator it; |
Mark Salyzyn | 0aaf6cd | 2015-03-03 13:39:37 -0800 | [diff] [blame] | 873 | uint64_t max = start; |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 874 | uid_t uid = reader->getUid(); |
| 875 | |
| 876 | pthread_mutex_lock(&mLogElementsLock); |
Dragoslav Mitrinovic | 81624f2 | 2015-01-15 09:29:43 -0600 | [diff] [blame] | 877 | |
Mark Salyzyn | 0aaf6cd | 2015-03-03 13:39:37 -0800 | [diff] [blame] | 878 | if (start <= 1) { |
Dragoslav Mitrinovic | 81624f2 | 2015-01-15 09:29:43 -0600 | [diff] [blame] | 879 | // client wants to start from the beginning |
| 880 | it = mLogElements.begin(); |
| 881 | } else { |
| 882 | // Client wants to start from some specified time. Chances are |
| 883 | // we are better off starting from the end of the time sorted list. |
| 884 | for (it = mLogElements.end(); it != mLogElements.begin(); /* do nothing */) { |
| 885 | --it; |
| 886 | LogBufferElement *element = *it; |
Mark Salyzyn | 0aaf6cd | 2015-03-03 13:39:37 -0800 | [diff] [blame] | 887 | if (element->getSequence() <= start) { |
Dragoslav Mitrinovic | 81624f2 | 2015-01-15 09:29:43 -0600 | [diff] [blame] | 888 | it++; |
| 889 | break; |
| 890 | } |
| 891 | } |
| 892 | } |
| 893 | |
| 894 | for (; it != mLogElements.end(); ++it) { |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 895 | LogBufferElement *element = *it; |
| 896 | |
| 897 | if (!privileged && (element->getUid() != uid)) { |
| 898 | continue; |
| 899 | } |
| 900 | |
Mark Salyzyn | 0aaf6cd | 2015-03-03 13:39:37 -0800 | [diff] [blame] | 901 | if (element->getSequence() <= start) { |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 902 | continue; |
| 903 | } |
| 904 | |
| 905 | // NB: calling out to another object with mLogElementsLock held (safe) |
Mark Salyzyn | 0aaf6cd | 2015-03-03 13:39:37 -0800 | [diff] [blame] | 906 | if (filter) { |
| 907 | int ret = (*filter)(element, arg); |
| 908 | if (ret == false) { |
| 909 | continue; |
| 910 | } |
| 911 | if (ret != true) { |
| 912 | break; |
| 913 | } |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 914 | } |
| 915 | |
| 916 | pthread_mutex_unlock(&mLogElementsLock); |
| 917 | |
| 918 | // range locking in LastLogTimes looks after us |
Mark Salyzyn | 3443fda | 2015-12-03 15:38:35 -0800 | [diff] [blame] | 919 | max = element->flushTo(reader, this, privileged); |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 920 | |
| 921 | if (max == element->FLUSH_ERROR) { |
| 922 | return max; |
| 923 | } |
| 924 | |
| 925 | pthread_mutex_lock(&mLogElementsLock); |
| 926 | } |
| 927 | pthread_mutex_unlock(&mLogElementsLock); |
| 928 | |
| 929 | return max; |
| 930 | } |
Mark Salyzyn | d774bce | 2014-02-06 14:48:50 -0800 | [diff] [blame] | 931 | |
Mark Salyzyn | b921ab5 | 2015-12-17 09:58:43 -0800 | [diff] [blame] | 932 | std::string LogBuffer::formatStatistics(uid_t uid, pid_t pid, |
| 933 | unsigned int logMask) { |
Mark Salyzyn | d774bce | 2014-02-06 14:48:50 -0800 | [diff] [blame] | 934 | pthread_mutex_lock(&mLogElementsLock); |
| 935 | |
Mark Salyzyn | b921ab5 | 2015-12-17 09:58:43 -0800 | [diff] [blame] | 936 | std::string ret = stats.format(uid, pid, logMask); |
Mark Salyzyn | d774bce | 2014-02-06 14:48:50 -0800 | [diff] [blame] | 937 | |
| 938 | pthread_mutex_unlock(&mLogElementsLock); |
Mark Salyzyn | 1c7b6fb | 2015-08-20 10:01:44 -0700 | [diff] [blame] | 939 | |
| 940 | return ret; |
Mark Salyzyn | d774bce | 2014-02-06 14:48:50 -0800 | [diff] [blame] | 941 | } |