2014-02-26 18:50:16 +01: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-16 00:10:26 +02:00
|
|
|
#pragma once
|
2014-02-26 18:50:16 +01:00
|
|
|
|
2015-03-03 22:39:37 +01:00
|
|
|
#include <stdatomic.h>
|
2018-08-13 23:22:56 +02:00
|
|
|
#include <stdint.h>
|
2015-03-16 20:04:09 +01:00
|
|
|
#include <stdlib.h>
|
2015-03-10 21:51:35 +01:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
2016-09-30 22:30:33 +02:00
|
|
|
#include <log/log.h>
|
2014-02-26 18:50:16 +01:00
|
|
|
#include <sysutils/SocketClient.h>
|
|
|
|
|
2015-04-20 16:26:27 +02:00
|
|
|
class LogBuffer;
|
|
|
|
|
2017-03-10 23:31:54 +01: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-16 00:58:17 +02:00
|
|
|
|
2017-08-03 02:54:27 +02:00
|
|
|
class __attribute__((packed)) LogBufferElement {
|
2015-09-08 17:56:32 +02:00
|
|
|
friend LogBuffer;
|
|
|
|
|
2016-10-25 01:22:17 +02:00
|
|
|
// sized to match reality of incoming log packets
|
|
|
|
const uint32_t mUid;
|
|
|
|
const uint32_t mPid;
|
|
|
|
const uint32_t mTid;
|
|
|
|
log_time mRealTime;
|
2019-08-23 18:09:40 +02:00
|
|
|
union {
|
|
|
|
char* mMsg; // mDropped == false
|
|
|
|
int32_t mTag; // mDropped == true
|
|
|
|
};
|
2015-03-16 20:04:09 +01:00
|
|
|
union {
|
2017-08-03 02:54:27 +02:00
|
|
|
const uint16_t mMsgLen; // mDropped == false
|
|
|
|
uint16_t mDroppedCount; // mDropped == true
|
2015-03-16 20:04:09 +01:00
|
|
|
};
|
2016-10-25 01:22:17 +02:00
|
|
|
const uint8_t mLogId;
|
2017-08-03 02:54:27 +02:00
|
|
|
bool mDropped;
|
2016-10-25 01:22:17 +02:00
|
|
|
|
2015-03-03 22:39:37 +01:00
|
|
|
static atomic_int_fast64_t sequence;
|
2014-02-26 18:50:16 +01:00
|
|
|
|
2017-08-03 02:54:27 +02:00
|
|
|
// assumption: mDropped == true
|
2017-03-10 23:31:54 +01:00
|
|
|
size_t populateDroppedMessage(char*& buffer, LogBuffer* parent,
|
2017-01-23 23:20:31 +01:00
|
|
|
bool lastSame);
|
2017-03-10 23:31:54 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
LogBufferElement(log_id_t log_id, log_time realtime, uid_t uid, pid_t pid,
|
2018-08-13 23:22:56 +02:00
|
|
|
pid_t tid, const char* msg, uint16_t len);
|
2017-03-10 23:31:54 +01:00
|
|
|
LogBufferElement(const LogBufferElement& elem);
|
2017-08-03 02:54:27 +02:00
|
|
|
~LogBufferElement();
|
2014-02-26 18:50:16 +01:00
|
|
|
|
2016-10-25 01:22:17 +02:00
|
|
|
bool isBinary(void) const {
|
|
|
|
return (mLogId == LOG_ID_EVENTS) || (mLogId == LOG_ID_SECURITY);
|
|
|
|
}
|
|
|
|
|
2017-03-10 23:31:54 +01:00
|
|
|
log_id_t getLogId() const {
|
|
|
|
return static_cast<log_id_t>(mLogId);
|
|
|
|
}
|
|
|
|
uid_t getUid(void) const {
|
|
|
|
return mUid;
|
|
|
|
}
|
|
|
|
pid_t getPid(void) const {
|
|
|
|
return mPid;
|
|
|
|
}
|
|
|
|
pid_t getTid(void) const {
|
|
|
|
return mTid;
|
|
|
|
}
|
2017-08-03 02:54:27 +02:00
|
|
|
uint32_t getTag() const;
|
2018-08-13 23:22:56 +02:00
|
|
|
uint16_t getDropped(void) const {
|
2017-08-03 02:54:27 +02:00
|
|
|
return mDropped ? mDroppedCount : 0;
|
2015-03-16 20:04:09 +01:00
|
|
|
}
|
2018-08-13 23:22:56 +02:00
|
|
|
uint16_t setDropped(uint16_t value);
|
|
|
|
uint16_t getMsgLen() const {
|
2017-08-03 02:54:27 +02:00
|
|
|
return mDropped ? 0 : mMsgLen;
|
2017-03-10 23:31:54 +01:00
|
|
|
}
|
|
|
|
const char* getMsg() const {
|
2017-08-03 02:54:27 +02:00
|
|
|
return mDropped ? nullptr : mMsg;
|
2017-03-10 23:31:54 +01:00
|
|
|
}
|
|
|
|
log_time getRealTime(void) const {
|
|
|
|
return mRealTime;
|
|
|
|
}
|
2014-02-26 18:50:16 +01:00
|
|
|
|
2017-03-10 17:44:14 +01:00
|
|
|
static const log_time FLUSH_ERROR;
|
2019-10-16 00:10:26 +02:00
|
|
|
log_time flushTo(SocketClient* writer, LogBuffer* parent, bool lastSame);
|
2014-02-26 18:50:16 +01:00
|
|
|
};
|