Tom Cherry | d5b3838 | 2020-05-12 13:16:41 -0700 | [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 | |
| 17 | #pragma once |
| 18 | |
| 19 | #include <sys/types.h> |
| 20 | |
| 21 | #include <list> |
| 22 | #include <optional> |
| 23 | #include <string> |
| 24 | |
Tom Cherry | 0b01ff0 | 2020-05-21 10:37:22 -0700 | [diff] [blame] | 25 | #include <android-base/thread_annotations.h> |
Tom Cherry | d5b3838 | 2020-05-12 13:16:41 -0700 | [diff] [blame] | 26 | #include <android/log.h> |
| 27 | #include <private/android_filesystem_config.h> |
Tom Cherry | d5b3838 | 2020-05-12 13:16:41 -0700 | [diff] [blame] | 28 | |
| 29 | #include "LogBuffer.h" |
| 30 | #include "LogBufferElement.h" |
Tom Cherry | 283c9a1 | 2020-05-14 19:25:05 -0700 | [diff] [blame] | 31 | #include "LogReaderList.h" |
| 32 | #include "LogReaderThread.h" |
Tom Cherry | d5b3838 | 2020-05-12 13:16:41 -0700 | [diff] [blame] | 33 | #include "LogStatistics.h" |
| 34 | #include "LogTags.h" |
Tom Cherry | 283c9a1 | 2020-05-14 19:25:05 -0700 | [diff] [blame] | 35 | #include "LogWriter.h" |
Tom Cherry | 0efb410 | 2020-06-16 10:14:09 -0700 | [diff] [blame] | 36 | #include "PruneList.h" |
Tom Cherry | 8f61346 | 2020-05-12 12:46:43 -0700 | [diff] [blame] | 37 | #include "SimpleLogBuffer.h" |
Tom Cherry | 0b01ff0 | 2020-05-21 10:37:22 -0700 | [diff] [blame] | 38 | #include "rwlock.h" |
Tom Cherry | d5b3838 | 2020-05-12 13:16:41 -0700 | [diff] [blame] | 39 | |
Tom Cherry | 1322472 | 2020-05-19 18:02:00 -0700 | [diff] [blame] | 40 | typedef std::list<LogBufferElement> LogBufferElementCollection; |
Tom Cherry | d5b3838 | 2020-05-12 13:16:41 -0700 | [diff] [blame] | 41 | |
Tom Cherry | 8f61346 | 2020-05-12 12:46:43 -0700 | [diff] [blame] | 42 | class ChattyLogBuffer : public SimpleLogBuffer { |
Tom Cherry | d5b3838 | 2020-05-12 13:16:41 -0700 | [diff] [blame] | 43 | // watermark of any worst/chatty uid processing |
| 44 | typedef std::unordered_map<uid_t, LogBufferElementCollection::iterator> LogBufferIteratorMap; |
Tom Cherry | 0b01ff0 | 2020-05-21 10:37:22 -0700 | [diff] [blame] | 45 | LogBufferIteratorMap mLastWorst[LOG_ID_MAX] GUARDED_BY(lock_); |
Tom Cherry | d5b3838 | 2020-05-12 13:16:41 -0700 | [diff] [blame] | 46 | // watermark of any worst/chatty pid of system processing |
| 47 | typedef std::unordered_map<pid_t, LogBufferElementCollection::iterator> LogBufferPidIteratorMap; |
Tom Cherry | 0b01ff0 | 2020-05-21 10:37:22 -0700 | [diff] [blame] | 48 | LogBufferPidIteratorMap mLastWorstPidOfSystem[LOG_ID_MAX] GUARDED_BY(lock_); |
Tom Cherry | d5b3838 | 2020-05-12 13:16:41 -0700 | [diff] [blame] | 49 | |
Tom Cherry | d5b3838 | 2020-05-12 13:16:41 -0700 | [diff] [blame] | 50 | public: |
| 51 | ChattyLogBuffer(LogReaderList* reader_list, LogTags* tags, PruneList* prune, |
| 52 | LogStatistics* stats); |
| 53 | ~ChattyLogBuffer(); |
Tom Cherry | d5b3838 | 2020-05-12 13:16:41 -0700 | [diff] [blame] | 54 | |
Tom Cherry | 8f61346 | 2020-05-12 12:46:43 -0700 | [diff] [blame] | 55 | protected: |
| 56 | bool Prune(log_id_t id, unsigned long pruneRows, uid_t uid) REQUIRES(lock_) override; |
| 57 | void LogInternal(LogBufferElement&& elem) REQUIRES(lock_) override; |
Tom Cherry | a3c5ff5 | 2020-05-21 13:56:33 -0700 | [diff] [blame] | 58 | |
Tom Cherry | d5b3838 | 2020-05-12 13:16:41 -0700 | [diff] [blame] | 59 | private: |
Tom Cherry | 8f61346 | 2020-05-12 12:46:43 -0700 | [diff] [blame] | 60 | LogBufferElementCollection::iterator Erase(LogBufferElementCollection::iterator it, |
Tom Cherry | 0b01ff0 | 2020-05-21 10:37:22 -0700 | [diff] [blame] | 61 | bool coalesce = false) REQUIRES(lock_); |
Tom Cherry | d5b3838 | 2020-05-12 13:16:41 -0700 | [diff] [blame] | 62 | |
Tom Cherry | d5b3838 | 2020-05-12 13:16:41 -0700 | [diff] [blame] | 63 | PruneList* prune_; |
Tom Cherry | a3c5ff5 | 2020-05-21 13:56:33 -0700 | [diff] [blame] | 64 | |
Tom Cherry | a26f7df | 2020-05-19 17:48:42 -0700 | [diff] [blame] | 65 | // This always contains a copy of the last message logged, for deduplication. |
Tom Cherry | 1322472 | 2020-05-19 18:02:00 -0700 | [diff] [blame] | 66 | std::optional<LogBufferElement> last_logged_elements_[LOG_ID_MAX] GUARDED_BY(lock_); |
Tom Cherry | a26f7df | 2020-05-19 17:48:42 -0700 | [diff] [blame] | 67 | // This contains an element if duplicate messages are seen. |
| 68 | // Its `dropped` count is `duplicates seen - 1`. |
Tom Cherry | 1322472 | 2020-05-19 18:02:00 -0700 | [diff] [blame] | 69 | std::optional<LogBufferElement> duplicate_elements_[LOG_ID_MAX] GUARDED_BY(lock_); |
Tom Cherry | d5b3838 | 2020-05-12 13:16:41 -0700 | [diff] [blame] | 70 | }; |