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 | |
Tom Cherry | e0ac158 | 2019-10-15 15:10:26 -0700 | [diff] [blame] | 17 | #pragma once |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 18 | |
Chih-Hung Hsieh | 9ff8155 | 2018-08-13 14:22:56 -0700 | [diff] [blame] | 19 | #include <stdint.h> |
Mark Salyzyn | a69d5a4 | 2015-03-16 12:04:09 -0700 | [diff] [blame] | 20 | #include <stdlib.h> |
Mark Salyzyn | 9cf5d40 | 2015-03-10 13:51:35 -0700 | [diff] [blame] | 21 | #include <sys/types.h> |
| 22 | |
Mark Salyzyn | 8b8bfd2 | 2016-09-30 13:30:33 -0700 | [diff] [blame] | 23 | #include <log/log.h> |
Tom Cherry | adf2e44 | 2020-05-14 19:25:05 -0700 | [diff] [blame] | 24 | |
| 25 | #include "LogWriter.h" |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 26 | |
Tom Cherry | 8f45911 | 2020-06-02 15:39:21 -0700 | [diff] [blame] | 27 | #include "LogStatistics.h" |
Mark Salyzyn | bf91832 | 2015-04-20 07:26:27 -0700 | [diff] [blame] | 28 | |
Christopher Ferris | dddc289 | 2017-08-02 17:54:27 -0700 | [diff] [blame] | 29 | class __attribute__((packed)) LogBufferElement { |
Tom Cherry | 479b503 | 2020-05-07 14:44:43 -0700 | [diff] [blame] | 30 | public: |
Tom Cherry | 0bf66db | 2020-05-21 13:56:33 -0700 | [diff] [blame] | 31 | LogBufferElement(log_id_t log_id, log_time realtime, uid_t uid, pid_t pid, pid_t tid, |
| 32 | uint64_t sequence, const char* msg, uint16_t len); |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 33 | LogBufferElement(const LogBufferElement& elem); |
Tom Cherry | 17b7758 | 2020-06-17 11:40:55 -0700 | [diff] [blame] | 34 | LogBufferElement(LogBufferElement&& elem) noexcept; |
Christopher Ferris | dddc289 | 2017-08-02 17:54:27 -0700 | [diff] [blame] | 35 | ~LogBufferElement(); |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 36 | |
Tom Cherry | f191014 | 2020-05-19 19:01:16 -0700 | [diff] [blame] | 37 | uint32_t GetTag() const; |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 38 | |
Elliott Hughes | 225e5c6 | 2022-09-16 23:01:59 +0000 | [diff] [blame] | 39 | bool FlushTo(LogWriter* writer); |
Tom Cherry | f191014 | 2020-05-19 19:01:16 -0700 | [diff] [blame] | 40 | |
Tom Cherry | 8f45911 | 2020-06-02 15:39:21 -0700 | [diff] [blame] | 41 | LogStatisticsElement ToLogStatisticsElement() const; |
| 42 | |
Tom Cherry | f191014 | 2020-05-19 19:01:16 -0700 | [diff] [blame] | 43 | log_id_t log_id() const { return static_cast<log_id_t>(log_id_); } |
| 44 | uid_t uid() const { return uid_; } |
| 45 | pid_t pid() const { return pid_; } |
| 46 | pid_t tid() const { return tid_; } |
Elliott Hughes | 225e5c6 | 2022-09-16 23:01:59 +0000 | [diff] [blame] | 47 | uint16_t msg_len() const { return msg_len_; } |
| 48 | const char* msg() const { return msg_; } |
Tom Cherry | f191014 | 2020-05-19 19:01:16 -0700 | [diff] [blame] | 49 | uint64_t sequence() const { return sequence_; } |
| 50 | log_time realtime() const { return realtime_; } |
Tom Cherry | f191014 | 2020-05-19 19:01:16 -0700 | [diff] [blame] | 51 | |
| 52 | private: |
Tom Cherry | f191014 | 2020-05-19 19:01:16 -0700 | [diff] [blame] | 53 | // sized to match reality of incoming log packets |
| 54 | const uint32_t uid_; |
| 55 | const uint32_t pid_; |
| 56 | const uint32_t tid_; |
| 57 | uint64_t sequence_; |
| 58 | log_time realtime_; |
Elliott Hughes | 225e5c6 | 2022-09-16 23:01:59 +0000 | [diff] [blame] | 59 | char* msg_; |
| 60 | const uint16_t msg_len_; |
Tom Cherry | f191014 | 2020-05-19 19:01:16 -0700 | [diff] [blame] | 61 | const uint8_t log_id_; |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 62 | }; |