Loading cmds/statsd/benchmark/log_event_benchmark.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -39,7 +39,7 @@ static void BM_LogEventCreation(benchmark::State& state) { uint8_t msg[LOGGER_ENTRY_MAX_PAYLOAD]; size_t size = createAndParseStatsEvent(msg); while (state.KeepRunning()) { benchmark::DoNotOptimize(LogEvent(msg, size, /*uid=*/ 1000)); benchmark::DoNotOptimize(LogEvent(msg, size, /*uid=*/ 1000, /*pid=*/ 1001)); } } BENCHMARK(BM_LogEventCreation); Loading cmds/statsd/src/external/StatsCallbackPuller.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -68,7 +68,7 @@ bool StatsCallbackPuller::PullInternal(vector<shared_ptr<LogEvent>>* data) { for (const StatsEventParcel& parcel: output) { shared_ptr<LogEvent> event = make_shared<LogEvent>( const_cast<uint8_t*>(parcel.buffer.data()), parcel.buffer.size(), /*uid=*/-1, /*useNewSchema=*/true); /*uid=*/-1, /*pid=*/-1, /*useNewSchema=*/true); sharedData->push_back(event); } *pullSuccess = success; Loading cmds/statsd/src/logd/LogEvent.cpp +12 −4 Original line number Diff line number Diff line Loading @@ -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(); Loading @@ -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 { Loading @@ -66,6 +72,7 @@ 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; Loading Loading @@ -146,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))); Loading cmds/statsd/src/logd/LogEvent.h +19 −6 Original line number Diff line number Diff line Loading @@ -71,12 +71,12 @@ public: /** * Read a LogEvent from the socket */ explicit LogEvent(uint8_t* msg, uint32_t len, uint32_t uid); explicit LogEvent(uint8_t* msg, uint32_t len, int32_t uid, int32_t pid); /** * Temp constructor to use for pulled atoms until we flip the socket schema. */ explicit LogEvent(uint8_t* msg, uint32_t len, uint32_t uid, bool useNewSchema); explicit LogEvent(uint8_t* msg, uint32_t len, int32_t uid, int32_t pid, bool useNewSchema); /** * Constructs a LogEvent with synthetic data for testing. Must call init() before reading. Loading Loading @@ -123,9 +123,17 @@ public: */ inline int GetTagId() const { return mTagId; } inline uint32_t GetUid() const { return mLogUid; } /** * Get the uid of the logging client. * Returns -1 if the uid is unknown/has not been set. */ inline int32_t GetUid() const { return mLogUid; } /** * Get the pid of the logging client. * Returns -1 if the pid is unknown/has not been set. */ inline int32_t GetPid() const { return mLogPid; } /** * Get the nth value, starting at 1. Loading Loading @@ -305,9 +313,14 @@ private: // The elapsed timestamp set by statsd log writer. int64_t mElapsedTimestampNs; // The atom tag of the event. int mTagId; uint32_t mLogUid; // The uid of the logging client (defaults to -1). int32_t mLogUid = -1; // The pid of the logging client (defaults to -1). int32_t mLogPid = -1; }; void writeExperimentIdsToProto(const std::vector<int64_t>& experimentIds, std::vector<uint8_t>* protoOut); Loading cmds/statsd/src/socket/StatsSocketListener.cpp +2 −1 Original line number Diff line number Diff line Loading @@ -126,9 +126,10 @@ bool StatsSocketListener::onDataAvailable(SocketClient* cli) { uint8_t* msg = ptr + sizeof(uint32_t); uint32_t len = n - sizeof(uint32_t); uint32_t uid = cred->uid; uint32_t pid = cred->pid; int64_t oldestTimestamp; if (!mQueue->push(std::make_unique<LogEvent>(msg, len, uid), &oldestTimestamp)) { if (!mQueue->push(std::make_unique<LogEvent>(msg, len, uid, pid), &oldestTimestamp)) { StatsdStats::getInstance().noteEventQueueOverflow(oldestTimestamp); } Loading Loading
cmds/statsd/benchmark/log_event_benchmark.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -39,7 +39,7 @@ static void BM_LogEventCreation(benchmark::State& state) { uint8_t msg[LOGGER_ENTRY_MAX_PAYLOAD]; size_t size = createAndParseStatsEvent(msg); while (state.KeepRunning()) { benchmark::DoNotOptimize(LogEvent(msg, size, /*uid=*/ 1000)); benchmark::DoNotOptimize(LogEvent(msg, size, /*uid=*/ 1000, /*pid=*/ 1001)); } } BENCHMARK(BM_LogEventCreation); Loading
cmds/statsd/src/external/StatsCallbackPuller.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -68,7 +68,7 @@ bool StatsCallbackPuller::PullInternal(vector<shared_ptr<LogEvent>>* data) { for (const StatsEventParcel& parcel: output) { shared_ptr<LogEvent> event = make_shared<LogEvent>( const_cast<uint8_t*>(parcel.buffer.data()), parcel.buffer.size(), /*uid=*/-1, /*useNewSchema=*/true); /*uid=*/-1, /*pid=*/-1, /*useNewSchema=*/true); sharedData->push_back(event); } *pullSuccess = success; Loading
cmds/statsd/src/logd/LogEvent.cpp +12 −4 Original line number Diff line number Diff line Loading @@ -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(); Loading @@ -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 { Loading @@ -66,6 +72,7 @@ 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; Loading Loading @@ -146,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))); Loading
cmds/statsd/src/logd/LogEvent.h +19 −6 Original line number Diff line number Diff line Loading @@ -71,12 +71,12 @@ public: /** * Read a LogEvent from the socket */ explicit LogEvent(uint8_t* msg, uint32_t len, uint32_t uid); explicit LogEvent(uint8_t* msg, uint32_t len, int32_t uid, int32_t pid); /** * Temp constructor to use for pulled atoms until we flip the socket schema. */ explicit LogEvent(uint8_t* msg, uint32_t len, uint32_t uid, bool useNewSchema); explicit LogEvent(uint8_t* msg, uint32_t len, int32_t uid, int32_t pid, bool useNewSchema); /** * Constructs a LogEvent with synthetic data for testing. Must call init() before reading. Loading Loading @@ -123,9 +123,17 @@ public: */ inline int GetTagId() const { return mTagId; } inline uint32_t GetUid() const { return mLogUid; } /** * Get the uid of the logging client. * Returns -1 if the uid is unknown/has not been set. */ inline int32_t GetUid() const { return mLogUid; } /** * Get the pid of the logging client. * Returns -1 if the pid is unknown/has not been set. */ inline int32_t GetPid() const { return mLogPid; } /** * Get the nth value, starting at 1. Loading Loading @@ -305,9 +313,14 @@ private: // The elapsed timestamp set by statsd log writer. int64_t mElapsedTimestampNs; // The atom tag of the event. int mTagId; uint32_t mLogUid; // The uid of the logging client (defaults to -1). int32_t mLogUid = -1; // The pid of the logging client (defaults to -1). int32_t mLogPid = -1; }; void writeExperimentIdsToProto(const std::vector<int64_t>& experimentIds, std::vector<uint8_t>* protoOut); Loading
cmds/statsd/src/socket/StatsSocketListener.cpp +2 −1 Original line number Diff line number Diff line Loading @@ -126,9 +126,10 @@ bool StatsSocketListener::onDataAvailable(SocketClient* cli) { uint8_t* msg = ptr + sizeof(uint32_t); uint32_t len = n - sizeof(uint32_t); uint32_t uid = cred->uid; uint32_t pid = cred->pid; int64_t oldestTimestamp; if (!mQueue->push(std::make_unique<LogEvent>(msg, len, uid), &oldestTimestamp)) { if (!mQueue->push(std::make_unique<LogEvent>(msg, len, uid, pid), &oldestTimestamp)) { StatsdStats::getInstance().noteEventQueueOverflow(oldestTimestamp); } Loading