Merge "Reduce memory footprint of LogEvent" into rvc-dev am: 272cae6e10 am: cc944dd4d1

Change-Id: I8a2e1033c64d1b597a6ab3f27b4b3dbe66c4eaef
This commit is contained in:
Ruchir Rastogi
2020-04-29 16:51:23 +00:00
committed by Automerger Merge Worker
2 changed files with 16 additions and 20 deletions

View File

@@ -227,8 +227,8 @@ void LogEvent::parseAttributionChain(int32_t* pos, int32_t depth, bool* last,
} }
// Check if at least one node was successfully parsed. // Check if at least one node was successfully parsed.
if (mValues.size() - 1 > firstUidInChainIndex) { if (mValues.size() - 1 > firstUidInChainIndex) {
mAttributionChainStartIndex = firstUidInChainIndex; mAttributionChainStartIndex = static_cast<int8_t>(firstUidInChainIndex);
mAttributionChainEndIndex = mValues.size() - 1; mAttributionChainEndIndex = static_cast<int8_t>(mValues.size() - 1);
} }
parseAnnotations(numAnnotations, firstUidInChainIndex); parseAnnotations(numAnnotations, firstUidInChainIndex);
@@ -249,7 +249,7 @@ void LogEvent::parseIsUidAnnotation(uint8_t annotationType) {
} }
bool isUid = readNextValue<uint8_t>(); bool isUid = readNextValue<uint8_t>();
if (isUid) mUidFieldIndex = mValues.size() - 1; if (isUid) mUidFieldIndex = static_cast<int8_t>(mValues.size() - 1);
mValues[mValues.size() - 1].mAnnotations.setUidField(isUid); mValues[mValues.size() - 1].mAnnotations.setUidField(isUid);
} }
@@ -290,7 +290,7 @@ void LogEvent::parseExclusiveStateAnnotation(uint8_t annotationType) {
} }
const bool exclusiveState = readNextValue<uint8_t>(); const bool exclusiveState = readNextValue<uint8_t>();
mExclusiveStateFieldIndex = mValues.size() - 1; mExclusiveStateFieldIndex = static_cast<int8_t>(mValues.size() - 1);
mValues[getExclusiveStateFieldIndex()].mAnnotations.setExclusiveState(exclusiveState); mValues[getExclusiveStateFieldIndex()].mAnnotations.setExclusiveState(exclusiveState);
} }
@@ -408,7 +408,7 @@ bool LogEvent::parseBuffer(uint8_t* buf, size_t len) {
parseAttributionChain(pos, /*depth=*/0, last, getNumAnnotations(typeInfo)); parseAttributionChain(pos, /*depth=*/0, last, getNumAnnotations(typeInfo));
break; break;
case ERROR_TYPE: case ERROR_TYPE:
mErrorBitmask = readNextValue<int32_t>(); /* mErrorBitmask =*/ readNextValue<int32_t>();
mValid = false; mValid = false;
break; break;
default: default:
@@ -577,8 +577,8 @@ bool LogEvent::hasAttributionChain(std::pair<int, int>* indexRange) const {
} }
if (nullptr != indexRange) { if (nullptr != indexRange) {
indexRange->first = mAttributionChainStartIndex; indexRange->first = static_cast<int>(mAttributionChainStartIndex);
indexRange->second = mAttributionChainEndIndex; indexRange->second = static_cast<int>(mAttributionChainEndIndex);
} }
return true; return true;

View File

@@ -160,7 +160,7 @@ public:
// } // }
// Note that atomIndex is 1-indexed. // Note that atomIndex is 1-indexed.
inline int getUidFieldIndex() { inline int getUidFieldIndex() {
return mUidFieldIndex; return static_cast<int>(mUidFieldIndex);
} }
// Returns whether this LogEvent has an AttributionChain. // Returns whether this LogEvent has an AttributionChain.
@@ -179,7 +179,7 @@ public:
// } // }
// Note that atomIndex is 1-indexed. // Note that atomIndex is 1-indexed.
inline int getExclusiveStateFieldIndex() const { inline int getExclusiveStateFieldIndex() const {
return mExclusiveStateFieldIndex; return static_cast<int>(mExclusiveStateFieldIndex);
} }
// If a reset state is not sent in the StatsEvent, returns -1. Note that a // If a reset state is not sent in the StatsEvent, returns -1. Note that a
@@ -212,10 +212,6 @@ public:
return mValid; return mValid;
} }
int32_t getErrorBitmask() const {
return mErrorBitmask;
}
private: private:
/** /**
* Only use this if copy is absolutely needed. * Only use this if copy is absolutely needed.
@@ -316,16 +312,16 @@ private:
// The pid of the logging client (defaults to -1). // The pid of the logging client (defaults to -1).
int32_t mLogPid = -1; int32_t mLogPid = -1;
// Bitmask of errors sent by StatsEvent/AStatsEvent.
int32_t mErrorBitmask = 0;
// Annotations // Annotations
bool mTruncateTimestamp = false; bool mTruncateTimestamp = false;
int mUidFieldIndex = -1;
int mAttributionChainStartIndex = -1;
int mAttributionChainEndIndex = -1;
int mExclusiveStateFieldIndex = -1;
int mResetState = -1; int mResetState = -1;
// Indexes within the FieldValue vector can be stored in 7 bits because
// that's the assumption enforced by the encoding used in FieldValue.
int8_t mUidFieldIndex = -1;
int8_t mAttributionChainStartIndex = -1;
int8_t mAttributionChainEndIndex = -1;
int8_t mExclusiveStateFieldIndex = -1;
}; };
void writeExperimentIdsToProto(const std::vector<int64_t>& experimentIds, std::vector<uint8_t>* protoOut); void writeExperimentIdsToProto(const std::vector<int64_t>& experimentIds, std::vector<uint8_t>* protoOut);