2014-02-26 17:50:16 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012-2014 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2019-10-15 22:10:26 +00:00
|
|
|
#pragma once
|
2014-02-26 17:50:16 +00:00
|
|
|
|
2018-08-13 21:22:56 +00:00
|
|
|
#include <stdint.h>
|
2015-03-16 19:04:09 +00:00
|
|
|
#include <stdlib.h>
|
2015-03-10 20:51:35 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
2016-09-30 20:30:33 +00:00
|
|
|
#include <log/log.h>
|
2020-05-15 02:25:05 +00:00
|
|
|
|
|
|
|
#include "LogWriter.h"
|
2014-02-26 17:50:16 +00:00
|
|
|
|
2020-06-02 22:39:21 +00:00
|
|
|
#include "LogStatistics.h"
|
2015-04-20 14:26:27 +00:00
|
|
|
|
2017-03-10 22:31:54 +00:00
|
|
|
#define EXPIRE_HOUR_THRESHOLD 24 // Only expire chatty UID logs to preserve
|
|
|
|
// non-chatty UIDs less than this age in hours
|
|
|
|
#define EXPIRE_THRESHOLD 10 // A smaller expire count is considered too
|
|
|
|
// chatty for the temporal expire messages
|
|
|
|
#define EXPIRE_RATELIMIT 10 // maximum rate in seconds to report expiration
|
2015-05-15 22:58:17 +00:00
|
|
|
|
2017-08-03 00:54:27 +00:00
|
|
|
class __attribute__((packed)) LogBufferElement {
|
2020-05-07 21:44:43 +00:00
|
|
|
public:
|
2020-05-21 20:56:33 +00:00
|
|
|
LogBufferElement(log_id_t log_id, log_time realtime, uid_t uid, pid_t pid, pid_t tid,
|
|
|
|
uint64_t sequence, const char* msg, uint16_t len);
|
2017-03-10 22:31:54 +00:00
|
|
|
LogBufferElement(const LogBufferElement& elem);
|
2020-06-17 18:40:55 +00:00
|
|
|
LogBufferElement(LogBufferElement&& elem) noexcept;
|
2017-08-03 00:54:27 +00:00
|
|
|
~LogBufferElement();
|
2014-02-26 17:50:16 +00:00
|
|
|
|
2020-05-20 02:01:16 +00:00
|
|
|
uint32_t GetTag() const;
|
|
|
|
uint16_t SetDropped(uint16_t value);
|
2014-02-26 17:50:16 +00:00
|
|
|
|
2020-05-15 02:25:05 +00:00
|
|
|
bool FlushTo(LogWriter* writer, LogStatistics* parent, bool lastSame);
|
2020-05-20 02:01:16 +00:00
|
|
|
|
2020-06-02 22:39:21 +00:00
|
|
|
LogStatisticsElement ToLogStatisticsElement() const;
|
|
|
|
|
2020-05-20 02:01:16 +00:00
|
|
|
log_id_t log_id() const { return static_cast<log_id_t>(log_id_); }
|
|
|
|
uid_t uid() const { return uid_; }
|
|
|
|
pid_t pid() const { return pid_; }
|
|
|
|
pid_t tid() const { return tid_; }
|
|
|
|
uint16_t msg_len() const { return dropped_ ? 0 : msg_len_; }
|
|
|
|
const char* msg() const { return dropped_ ? nullptr : msg_; }
|
|
|
|
uint64_t sequence() const { return sequence_; }
|
|
|
|
log_time realtime() const { return realtime_; }
|
|
|
|
uint16_t dropped_count() const { return dropped_ ? dropped_count_ : 0; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
// assumption: mDropped == true
|
|
|
|
size_t PopulateDroppedMessage(char*& buffer, LogStatistics* parent, bool lastSame);
|
|
|
|
|
|
|
|
// sized to match reality of incoming log packets
|
|
|
|
const uint32_t uid_;
|
|
|
|
const uint32_t pid_;
|
|
|
|
const uint32_t tid_;
|
|
|
|
uint64_t sequence_;
|
|
|
|
log_time realtime_;
|
|
|
|
union {
|
|
|
|
char* msg_; // mDropped == false
|
|
|
|
int32_t tag_; // mDropped == true
|
|
|
|
};
|
|
|
|
union {
|
|
|
|
const uint16_t msg_len_; // mDropped == false
|
|
|
|
uint16_t dropped_count_; // mDropped == true
|
|
|
|
};
|
|
|
|
const uint8_t log_id_;
|
|
|
|
bool dropped_;
|
2014-02-26 17:50:16 +00:00
|
|
|
};
|