blob: 7ad0e15ac0c36f464479ad5a5768afcbb53bea7a [file] [log] [blame]
Mark Salyzyn12bac902014-02-26 09:50:16 -08001/*
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 Cherrye0ac1582019-10-15 15:10:26 -070017#pragma once
Mark Salyzyn12bac902014-02-26 09:50:16 -080018
Chih-Hung Hsieh9ff81552018-08-13 14:22:56 -070019#include <stdint.h>
Mark Salyzyna69d5a42015-03-16 12:04:09 -070020#include <stdlib.h>
Mark Salyzyn9cf5d402015-03-10 13:51:35 -070021#include <sys/types.h>
22
Mark Salyzyn8b8bfd22016-09-30 13:30:33 -070023#include <log/log.h>
Tom Cherryadf2e442020-05-14 19:25:05 -070024
25#include "LogWriter.h"
Mark Salyzyn12bac902014-02-26 09:50:16 -080026
Tom Cherry8f459112020-06-02 15:39:21 -070027#include "LogStatistics.h"
Mark Salyzynbf918322015-04-20 07:26:27 -070028
Christopher Ferrisdddc2892017-08-02 17:54:27 -070029class __attribute__((packed)) LogBufferElement {
Tom Cherry479b5032020-05-07 14:44:43 -070030 public:
Tom Cherry0bf66db2020-05-21 13:56:33 -070031 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 Salyzyn65059532017-03-10 14:31:54 -080033 LogBufferElement(const LogBufferElement& elem);
Tom Cherry17b77582020-06-17 11:40:55 -070034 LogBufferElement(LogBufferElement&& elem) noexcept;
Christopher Ferrisdddc2892017-08-02 17:54:27 -070035 ~LogBufferElement();
Mark Salyzyn12bac902014-02-26 09:50:16 -080036
Tom Cherryf1910142020-05-19 19:01:16 -070037 uint32_t GetTag() const;
Mark Salyzyn12bac902014-02-26 09:50:16 -080038
Elliott Hughes225e5c62022-09-16 23:01:59 +000039 bool FlushTo(LogWriter* writer);
Tom Cherryf1910142020-05-19 19:01:16 -070040
Tom Cherry8f459112020-06-02 15:39:21 -070041 LogStatisticsElement ToLogStatisticsElement() const;
42
Tom Cherryf1910142020-05-19 19:01:16 -070043 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 Hughes225e5c62022-09-16 23:01:59 +000047 uint16_t msg_len() const { return msg_len_; }
48 const char* msg() const { return msg_; }
Tom Cherryf1910142020-05-19 19:01:16 -070049 uint64_t sequence() const { return sequence_; }
50 log_time realtime() const { return realtime_; }
Tom Cherryf1910142020-05-19 19:01:16 -070051
52 private:
Tom Cherryf1910142020-05-19 19:01:16 -070053 // 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 Hughes225e5c62022-09-16 23:01:59 +000059 char* msg_;
60 const uint16_t msg_len_;
Tom Cherryf1910142020-05-19 19:01:16 -070061 const uint8_t log_id_;
Mark Salyzyn12bac902014-02-26 09:50:16 -080062};