summaryrefslogtreecommitdiffstats
path: root/logd
diff options
context:
space:
mode:
authorChristopher Ferris <cferris@google.com>2017-08-15 17:00:02 +0000
committerandroid-build-merger <android-build-merger@google.com>2017-08-15 17:00:02 +0000
commite23b30a6da4a66c6948208b2fc16233948ad38f4 (patch)
treea905957dd82099831d744d4a6b57564cf9860b44 /logd
parentdb640d87cda3691568f1f1f10dafa95b1e512218 (diff)
parent44ad9374112cb50bfea4b759ff30376516392e4d (diff)
downloadcore-e23b30a6da4a66c6948208b2fc16233948ad38f4.tar.gz
core-e23b30a6da4a66c6948208b2fc16233948ad38f4.tar.bz2
core-e23b30a6da4a66c6948208b2fc16233948ad38f4.zip
Merge "Decrease size of LogBufferElements to 32 bytes."
am: 44ad937411 Change-Id: Ibfcc70ed00e8d76a3ff77e0e00cdf922bc65b55f
Diffstat (limited to 'logd')
-rw-r--r--logd/LogBufferElement.cpp48
-rw-r--r--logd/LogBufferElement.h30
2 files changed, 47 insertions, 31 deletions
diff --git a/logd/LogBufferElement.cpp b/logd/LogBufferElement.cpp
index 381c97457..f20ac4514 100644
--- a/logd/LogBufferElement.cpp
+++ b/logd/LogBufferElement.cpp
@@ -41,22 +41,20 @@ LogBufferElement::LogBufferElement(log_id_t log_id, log_time realtime,
mTid(tid),
mRealTime(realtime),
mMsgLen(len),
- mLogId(log_id) {
+ mLogId(log_id),
+ mDropped(false) {
mMsg = new char[len];
memcpy(mMsg, msg, len);
- mTag = (isBinary() && (mMsgLen >= sizeof(uint32_t)))
- ? le32toh(reinterpret_cast<android_event_header_t*>(mMsg)->tag)
- : 0;
}
LogBufferElement::LogBufferElement(const LogBufferElement& elem)
- : mTag(elem.mTag),
- mUid(elem.mUid),
+ : mUid(elem.mUid),
mPid(elem.mPid),
mTid(elem.mTid),
mRealTime(elem.mRealTime),
mMsgLen(elem.mMsgLen),
- mLogId(elem.mLogId) {
+ mLogId(elem.mLogId),
+ mDropped(elem.mDropped) {
mMsg = new char[mMsgLen];
memcpy(mMsg, elem.mMsg, mMsgLen);
}
@@ -65,6 +63,32 @@ LogBufferElement::~LogBufferElement() {
delete[] mMsg;
}
+uint32_t LogBufferElement::getTag() const {
+ return (isBinary() &&
+ ((mDropped && mMsg != nullptr) ||
+ (!mDropped && mMsgLen >= sizeof(android_event_header_t))))
+ ? reinterpret_cast<const android_event_header_t*>(mMsg)->tag
+ : 0;
+}
+
+unsigned short LogBufferElement::setDropped(unsigned short value) {
+ // The tag information is saved in mMsg data, if the tag is non-zero
+ // save only the information needed to get the tag.
+ if (getTag() != 0) {
+ if (mMsgLen > sizeof(android_event_header_t)) {
+ char* truncated_msg = new char[sizeof(android_event_header_t)];
+ memcpy(truncated_msg, mMsg, sizeof(android_event_header_t));
+ delete[] mMsg;
+ mMsg = truncated_msg;
+ } // mMsgLen == sizeof(android_event_header_t), already at minimum.
+ } else {
+ delete[] mMsg;
+ mMsg = nullptr;
+ }
+ mDropped = true;
+ return mDroppedCount = value;
+}
+
// caller must own and free character string
char* android::tidToName(pid_t tid) {
char* retval = NULL;
@@ -164,8 +188,8 @@ size_t LogBufferElement::populateDroppedMessage(char*& buffer, LogBuffer* parent
// identical to below to calculate the buffer size required
const char* type = lastSame ? "identical" : "expire";
size_t len = snprintf(NULL, 0, format_uid, mUid, name ? name : "",
- commName ? commName : "", type, mDropped,
- (mDropped > 1) ? "s" : "");
+ commName ? commName : "", type, getDropped(),
+ (getDropped() > 1) ? "s" : "");
size_t hdrLen;
if (isBinary()) {
@@ -196,8 +220,8 @@ size_t LogBufferElement::populateDroppedMessage(char*& buffer, LogBuffer* parent
}
snprintf(buffer + hdrLen, len + 1, format_uid, mUid, name ? name : "",
- commName ? commName : "", type, mDropped,
- (mDropped > 1) ? "s" : "");
+ commName ? commName : "", type, getDropped(),
+ (getDropped() > 1) ? "s" : "");
free(const_cast<char*>(name));
free(const_cast<char*>(commName));
@@ -225,7 +249,7 @@ log_time LogBufferElement::flushTo(SocketClient* reader, LogBuffer* parent,
char* buffer = NULL;
- if (!mMsg) {
+ if (mDropped) {
entry.len = populateDroppedMessage(buffer, parent, lastSame);
if (!entry.len) return mRealTime;
iovec[1].iov_base = buffer;
diff --git a/logd/LogBufferElement.h b/logd/LogBufferElement.h
index 814ec8785..b168645f1 100644
--- a/logd/LogBufferElement.h
+++ b/logd/LogBufferElement.h
@@ -32,25 +32,25 @@ class LogBuffer;
// chatty for the temporal expire messages
#define EXPIRE_RATELIMIT 10 // maximum rate in seconds to report expiration
-class LogBufferElement {
+class __attribute__((packed)) LogBufferElement {
friend LogBuffer;
// 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;
log_time mRealTime;
char* mMsg;
union {
- const uint16_t mMsgLen; // mMSg != NULL
- uint16_t mDropped; // mMsg == NULL
+ const uint16_t mMsgLen; // mDropped == false
+ uint16_t mDroppedCount; // mDropped == true
};
const uint8_t mLogId;
+ bool mDropped;
static atomic_int_fast64_t sequence;
- // assumption: mMsg == NULL
+ // assumption: mDropped == true
size_t populateDroppedMessage(char*& buffer, LogBuffer* parent,
bool lastSame);
@@ -58,7 +58,7 @@ class LogBufferElement {
LogBufferElement(log_id_t log_id, log_time realtime, uid_t uid, pid_t pid,
pid_t tid, const char* msg, unsigned short len);
LogBufferElement(const LogBufferElement& elem);
- virtual ~LogBufferElement();
+ ~LogBufferElement();
bool isBinary(void) const {
return (mLogId == LOG_ID_EVENTS) || (mLogId == LOG_ID_SECURITY);
@@ -76,24 +76,16 @@ class LogBufferElement {
pid_t getTid(void) const {
return mTid;
}
- uint32_t getTag() const {
- return mTag;
- }
+ uint32_t getTag() const;
unsigned short getDropped(void) const {
- return mMsg ? 0 : mDropped;
- }
- unsigned short setDropped(unsigned short value) {
- if (mMsg) {
- delete[] mMsg;
- mMsg = NULL;
- }
- return mDropped = value;
+ return mDropped ? mDroppedCount : 0;
}
+ unsigned short setDropped(unsigned short value);
unsigned short getMsgLen() const {
- return mMsg ? mMsgLen : 0;
+ return mDropped ? 0 : mMsgLen;
}
const char* getMsg() const {
- return mMsg;
+ return mDropped ? nullptr : mMsg;
}
log_time getRealTime(void) const {
return mRealTime;