summaryrefslogtreecommitdiff
path: root/cmds/statsd/src/logd/LogEvent.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cmds/statsd/src/logd/LogEvent.cpp')
-rw-r--r--cmds/statsd/src/logd/LogEvent.cpp80
1 files changed, 12 insertions, 68 deletions
diff --git a/cmds/statsd/src/logd/LogEvent.cpp b/cmds/statsd/src/logd/LogEvent.cpp
index 36f4623c4dcb..9a0693a84e65 100644
--- a/cmds/statsd/src/logd/LogEvent.cpp
+++ b/cmds/statsd/src/logd/LogEvent.cpp
@@ -37,11 +37,12 @@ using std::vector;
// Msg is expected to begin at the start of the serialized atom -- it should not
// include the android_log_header_t or the StatsEventTag.
-LogEvent::LogEvent(uint8_t* msg, uint32_t len, uint32_t uid)
+LogEvent::LogEvent(uint8_t* msg, uint32_t len, int32_t uid, int32_t pid)
: mBuf(msg),
mRemainingLen(len),
mLogdTimestampNs(time(nullptr)),
- mLogUid(uid)
+ mLogUid(uid),
+ mLogPid(pid)
{
#ifdef NEW_ENCODING_SCHEME
initNew();
@@ -52,8 +53,13 @@ LogEvent::LogEvent(uint8_t* msg, uint32_t len, uint32_t uid)
#endif
}
-LogEvent::LogEvent(uint8_t* msg, uint32_t len, uint32_t uid, bool useNewSchema)
- : mBuf(msg), mRemainingLen(len), mLogdTimestampNs(time(nullptr)), mLogUid(uid) {
+LogEvent::LogEvent(uint8_t* msg, uint32_t len, int32_t uid, int32_t pid, bool useNewSchema)
+ : mBuf(msg),
+ mRemainingLen(len),
+ mLogdTimestampNs(time(nullptr)),
+ mLogUid(uid),
+ mLogPid(pid)
+{
if (useNewSchema) {
initNew();
} else {
@@ -66,75 +72,12 @@ LogEvent::LogEvent(uint8_t* msg, uint32_t len, uint32_t uid, bool useNewSchema)
LogEvent::LogEvent(const LogEvent& event) {
mTagId = event.mTagId;
mLogUid = event.mLogUid;
+ mLogPid = event.mLogPid;
mElapsedTimestampNs = event.mElapsedTimestampNs;
mLogdTimestampNs = event.mLogdTimestampNs;
mValues = event.mValues;
}
-LogEvent::LogEvent(const StatsLogEventWrapper& statsLogEventWrapper, int workChainIndex) {
- mTagId = statsLogEventWrapper.getTagId();
- mLogdTimestampNs = statsLogEventWrapper.getWallClockTimeNs();
- mElapsedTimestampNs = statsLogEventWrapper.getElapsedRealTimeNs();
- mLogUid = 0;
- int workChainPosOffset = 0;
- if (workChainIndex != -1) {
- const WorkChain& wc = statsLogEventWrapper.getWorkChains()[workChainIndex];
- // chains are at field 1, level 2
- int depth = 2;
- for (int i = 0; i < (int)wc.uids.size(); i++) {
- int pos[] = {1, i + 1, 1};
- mValues.push_back(FieldValue(Field(mTagId, pos, depth), Value(wc.uids[i])));
- pos[2]++;
- mValues.push_back(FieldValue(Field(mTagId, pos, depth), Value(wc.tags[i])));
- mValues.back().mField.decorateLastPos(2);
- }
- mValues.back().mField.decorateLastPos(1);
- workChainPosOffset = 1;
- }
- for (int i = 0; i < (int)statsLogEventWrapper.getElements().size(); i++) {
- Field field(statsLogEventWrapper.getTagId(), getSimpleField(i + 1 + workChainPosOffset));
- switch (statsLogEventWrapper.getElements()[i].type) {
- case android::os::StatsLogValue::STATS_LOG_VALUE_TYPE::INT:
- mValues.push_back(
- FieldValue(field, Value(statsLogEventWrapper.getElements()[i].int_value)));
- break;
- case android::os::StatsLogValue::STATS_LOG_VALUE_TYPE::LONG:
- mValues.push_back(
- FieldValue(field, Value(statsLogEventWrapper.getElements()[i].long_value)));
- break;
- case android::os::StatsLogValue::STATS_LOG_VALUE_TYPE::FLOAT:
- mValues.push_back(FieldValue(
- field, Value(statsLogEventWrapper.getElements()[i].float_value)));
- break;
- case android::os::StatsLogValue::STATS_LOG_VALUE_TYPE::DOUBLE:
- mValues.push_back(FieldValue(
- field, Value(statsLogEventWrapper.getElements()[i].double_value)));
- break;
- case android::os::StatsLogValue::STATS_LOG_VALUE_TYPE::STRING:
- mValues.push_back(
- FieldValue(field, Value(statsLogEventWrapper.getElements()[i].str_value)));
- break;
- case android::os::StatsLogValue::STATS_LOG_VALUE_TYPE::STORAGE:
- mValues.push_back(FieldValue(
- field, Value(statsLogEventWrapper.getElements()[i].storage_value)));
- break;
- default:
- break;
- }
- }
-}
-
-void LogEvent::createLogEvents(const StatsLogEventWrapper& statsLogEventWrapper,
- std::vector<std::shared_ptr<LogEvent>>& logEvents) {
- if (statsLogEventWrapper.getWorkChains().size() == 0) {
- logEvents.push_back(std::make_shared<LogEvent>(statsLogEventWrapper, -1));
- } else {
- for (size_t i = 0; i < statsLogEventWrapper.getWorkChains().size(); i++) {
- logEvents.push_back(std::make_shared<LogEvent>(statsLogEventWrapper, i));
- }
- }
-}
-
LogEvent::LogEvent(int32_t tagId, int64_t wallClockTimestampNs, int64_t elapsedTimestampNs) {
mLogdTimestampNs = wallClockTimestampNs;
mElapsedTimestampNs = elapsedTimestampNs;
@@ -210,6 +153,7 @@ LogEvent::LogEvent(const string& trainName, int64_t trainVersionCode, bool requi
mElapsedTimestampNs = getElapsedRealtimeNs();
mTagId = android::util::BINARY_PUSH_STATE_CHANGED;
mLogUid = android::IPCThreadState::self()->getCallingUid();
+ mLogPid = android::IPCThreadState::self()->getCallingPid();
mValues.push_back(FieldValue(Field(mTagId, getSimpleField(1)), Value(trainName)));
mValues.push_back(FieldValue(Field(mTagId, getSimpleField(2)), Value(trainVersionCode)));