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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _LOGD_LOG_BUFFER_ELEMENT_H__
|
|
|
|
#define _LOGD_LOG_BUFFER_ELEMENT_H__
|
|
|
|
|
2015-03-03 22:39:37 +01:00
|
|
|
#include <stdatomic.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;
|
|
|
|
|
2015-05-16 00:58:17 +02:00
|
|
|
#define EXPIRE_HOUR_THRESHOLD 24 // Only expire chatty UID logs to preserve
|
|
|
|
// non-chatty UIDs less than this age in hours
|
2015-06-04 22:35:30 +02:00
|
|
|
#define EXPIRE_THRESHOLD 10 // A smaller expire count is considered too
|
2015-05-16 00:58:17 +02:00
|
|
|
// chatty for the temporal expire messages
|
2015-06-04 22:35:30 +02:00
|
|
|
#define EXPIRE_RATELIMIT 10 // maximum rate in seconds to report expiration
|
2015-05-16 00:58:17 +02:00
|
|
|
|
2014-02-26 18:50:16 +01:00
|
|
|
class 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
|
|
|
|
uint32_t mTag; // only valid for isBinary()
|
|
|
|
const uint32_t mUid;
|
|
|
|
const uint32_t mPid;
|
|
|
|
const uint32_t mTid;
|
|
|
|
const uint64_t mSequence;
|
|
|
|
log_time mRealTime;
|
2014-02-26 18:50:16 +01:00
|
|
|
char *mMsg;
|
2015-03-16 20:04:09 +01:00
|
|
|
union {
|
2016-10-25 01:22:17 +02:00
|
|
|
const uint16_t mMsgLen; // mMSg != NULL
|
|
|
|
uint16_t mDropped; // mMsg == NULL
|
2015-03-16 20:04:09 +01:00
|
|
|
};
|
2016-10-25 01:22:17 +02:00
|
|
|
const uint8_t mLogId;
|
|
|
|
|
2015-03-03 22:39:37 +01:00
|
|
|
static atomic_int_fast64_t sequence;
|
2014-02-26 18:50:16 +01:00
|
|
|
|
2015-03-16 20:04:09 +01:00
|
|
|
// assumption: mMsg == NULL
|
2017-01-23 23:20:31 +01:00
|
|
|
size_t populateDroppedMessage(char*& buffer,
|
|
|
|
LogBuffer* parent,
|
|
|
|
bool lastSame);
|
2014-02-26 18:50:16 +01:00
|
|
|
public:
|
2014-03-05 16:41:49 +01:00
|
|
|
LogBufferElement(log_id_t log_id, log_time realtime,
|
2014-03-21 00:09:38 +01:00
|
|
|
uid_t uid, pid_t pid, pid_t tid,
|
|
|
|
const char *msg, unsigned short len);
|
2016-12-13 19:31:29 +01:00
|
|
|
LogBufferElement(const LogBufferElement &elem);
|
2014-02-26 18:50:16 +01:00
|
|
|
virtual ~LogBufferElement();
|
|
|
|
|
2016-10-25 01:22:17 +02:00
|
|
|
bool isBinary(void) const {
|
|
|
|
return (mLogId == LOG_ID_EVENTS) || (mLogId == LOG_ID_SECURITY);
|
|
|
|
}
|
|
|
|
|
|
|
|
log_id_t getLogId() const { return static_cast<log_id_t>(mLogId); }
|
2014-02-26 18:50:16 +01:00
|
|
|
uid_t getUid(void) const { return mUid; }
|
|
|
|
pid_t getPid(void) const { return mPid; }
|
2014-03-21 00:09:38 +01:00
|
|
|
pid_t getTid(void) const { return mTid; }
|
2016-10-25 01:22:17 +02:00
|
|
|
uint32_t getTag() const { return mTag; }
|
2015-03-16 20:04:09 +01:00
|
|
|
unsigned short getDropped(void) const { return mMsg ? 0 : mDropped; }
|
|
|
|
unsigned short setDropped(unsigned short value) {
|
|
|
|
if (mMsg) {
|
2015-10-02 18:22:52 +02:00
|
|
|
delete [] mMsg;
|
2015-03-16 20:04:09 +01:00
|
|
|
mMsg = NULL;
|
|
|
|
}
|
|
|
|
return mDropped = value;
|
|
|
|
}
|
|
|
|
unsigned short getMsgLen() const { return mMsg ? mMsgLen : 0; }
|
2016-12-13 19:31:29 +01:00
|
|
|
const char* getMsg() const { return mMsg; }
|
2015-03-03 22:39:37 +01:00
|
|
|
uint64_t getSequence(void) const { return mSequence; }
|
|
|
|
static uint64_t getCurrentSequence(void) { return sequence.load(memory_order_relaxed); }
|
2014-02-26 18:50:16 +01:00
|
|
|
log_time getRealTime(void) const { return mRealTime; }
|
|
|
|
|
2015-03-03 22:39:37 +01:00
|
|
|
static const uint64_t FLUSH_ERROR;
|
2017-01-23 23:20:31 +01:00
|
|
|
uint64_t flushTo(SocketClient* writer, LogBuffer* parent,
|
|
|
|
bool privileged, bool lastSame);
|
2014-02-26 18:50:16 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|