Loading cmds/statsd/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -250,6 +250,7 @@ cc_test { "tests/external/GpuStatsPuller_test.cpp", "tests/external/IncidentReportArgs_test.cpp", "tests/external/puller_util_test.cpp", "tests/external/StatsCallbackPuller_test.cpp", "tests/external/StatsPuller_test.cpp", "tests/external/SurfaceflingerStatsPuller_test.cpp", "tests/FieldValue_test.cpp", Loading cmds/statsd/src/external/StatsCallbackPuller.cpp +10 −11 Original line number Diff line number Diff line Loading @@ -35,8 +35,9 @@ namespace android { namespace os { namespace statsd { StatsCallbackPuller::StatsCallbackPuller(int tagId, const sp<IPullAtomCallback>& callback) : StatsPuller(tagId), mCallback(callback) { StatsCallbackPuller::StatsCallbackPuller(int tagId, const sp<IPullAtomCallback>& callback, int64_t timeoutNs) : StatsPuller(tagId), mCallback(callback), mTimeoutNs(timeoutNs) { VLOG("StatsCallbackPuller created for tag %d", tagId); } Loading Loading @@ -64,10 +65,9 @@ bool StatsCallbackPuller::PullInternal(vector<shared_ptr<LogEvent>>* data) { { lock_guard<mutex> lk(*cv_mutex); for (const StatsEventParcel& parcel: output) { shared_ptr<LogEvent> event = make_shared<LogEvent>(const_cast<uint8_t*>(parcel.buffer.data()), parcel.buffer.size(), /*uid=*/ -1); shared_ptr<LogEvent> event = make_shared<LogEvent>( const_cast<uint8_t*>(parcel.buffer.data()), parcel.buffer.size(), /*uid=*/-1, /*useNewSchema=*/true); sharedData->push_back(event); } *pullSuccess = success; Loading @@ -76,7 +76,8 @@ bool StatsCallbackPuller::PullInternal(vector<shared_ptr<LogEvent>>* data) { cv->notify_one(); }); // Initiate the pull. // Initiate the pull. This is a oneway call to a different process, except // in unit tests. In process calls are not oneway. Status status = mCallback->onPullAtom(mTagId, resultReceiver); if (!status.isOk()) { return false; Loading @@ -84,10 +85,8 @@ bool StatsCallbackPuller::PullInternal(vector<shared_ptr<LogEvent>>* data) { { unique_lock<mutex> unique_lk(*cv_mutex); int64_t pullTimeoutNs = StatsPullerManager::kAllPullAtomInfo.at({.atomTag = mTagId}).pullTimeoutNs; // Wait until the pull finishes, or until the pull timeout. cv->wait_for(unique_lk, chrono::nanoseconds(pullTimeoutNs), cv->wait_for(unique_lk, chrono::nanoseconds(mTimeoutNs), [pullFinish] { return *pullFinish; }); if (!*pullFinish) { // Note: The parent stats puller will also note that there was a timeout and that the Loading @@ -96,7 +95,7 @@ bool StatsCallbackPuller::PullInternal(vector<shared_ptr<LogEvent>>* data) { return true; } else { // Only copy the data if we did not timeout and the pull was successful. if (pullSuccess) { if (*pullSuccess) { *data = std::move(*sharedData); } VLOG("StatsCallbackPuller::pull succeeded for %d", mTagId); Loading cmds/statsd/src/external/StatsCallbackPuller.h +7 −1 Original line number Diff line number Diff line Loading @@ -27,11 +27,17 @@ namespace statsd { class StatsCallbackPuller : public StatsPuller { public: explicit StatsCallbackPuller(int tagId, const sp<IPullAtomCallback>& callback); explicit StatsCallbackPuller(int tagId, const sp<IPullAtomCallback>& callback, int64_t timeoutNs); private: bool PullInternal(vector<std::shared_ptr<LogEvent> >* data) override; const sp<IPullAtomCallback> mCallback; const int64_t mTimeoutNs; FRIEND_TEST(StatsCallbackPullerTest, PullFail); FRIEND_TEST(StatsCallbackPullerTest, PullSuccess); FRIEND_TEST(StatsCallbackPullerTest, PullTimeout); }; } // namespace statsd Loading cmds/statsd/src/external/StatsPullerManager.cpp +5 −4 Original line number Diff line number Diff line Loading @@ -500,9 +500,10 @@ void StatsPullerManager::RegisterPullAtomCallback(const int uid, const int32_t a VLOG("RegisterPullerCallback: adding puller for tag %d", atomTag); // TODO: linkToDeath with the callback so that we can remove it and delete the puller. StatsdStats::getInstance().notePullerCallbackRegistrationChanged(atomTag, /*registered=*/true); kAllPullAtomInfo[{.atomTag = atomTag}] = {.additiveFields = additiveFields, kAllPullAtomInfo[{.atomTag = atomTag}] = { .additiveFields = additiveFields, .coolDownNs = coolDownNs, .puller = new StatsCallbackPuller(atomTag, callback), .puller = new StatsCallbackPuller(atomTag, callback, timeoutNs), .pullTimeoutNs = timeoutNs, }; } Loading cmds/statsd/src/logd/LogEvent.cpp +11 −0 Original line number Diff line number Diff line Loading @@ -52,6 +52,17 @@ 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) { if (useNewSchema) { initNew(); } else { mContext = create_android_log_parser((char*)msg, len); init(mContext); if (mContext) android_log_destroy(&mContext); // set mContext to NULL } } LogEvent::LogEvent(const LogEvent& event) { mTagId = event.mTagId; mLogUid = event.mLogUid; Loading Loading
cmds/statsd/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -250,6 +250,7 @@ cc_test { "tests/external/GpuStatsPuller_test.cpp", "tests/external/IncidentReportArgs_test.cpp", "tests/external/puller_util_test.cpp", "tests/external/StatsCallbackPuller_test.cpp", "tests/external/StatsPuller_test.cpp", "tests/external/SurfaceflingerStatsPuller_test.cpp", "tests/FieldValue_test.cpp", Loading
cmds/statsd/src/external/StatsCallbackPuller.cpp +10 −11 Original line number Diff line number Diff line Loading @@ -35,8 +35,9 @@ namespace android { namespace os { namespace statsd { StatsCallbackPuller::StatsCallbackPuller(int tagId, const sp<IPullAtomCallback>& callback) : StatsPuller(tagId), mCallback(callback) { StatsCallbackPuller::StatsCallbackPuller(int tagId, const sp<IPullAtomCallback>& callback, int64_t timeoutNs) : StatsPuller(tagId), mCallback(callback), mTimeoutNs(timeoutNs) { VLOG("StatsCallbackPuller created for tag %d", tagId); } Loading Loading @@ -64,10 +65,9 @@ bool StatsCallbackPuller::PullInternal(vector<shared_ptr<LogEvent>>* data) { { lock_guard<mutex> lk(*cv_mutex); for (const StatsEventParcel& parcel: output) { shared_ptr<LogEvent> event = make_shared<LogEvent>(const_cast<uint8_t*>(parcel.buffer.data()), parcel.buffer.size(), /*uid=*/ -1); shared_ptr<LogEvent> event = make_shared<LogEvent>( const_cast<uint8_t*>(parcel.buffer.data()), parcel.buffer.size(), /*uid=*/-1, /*useNewSchema=*/true); sharedData->push_back(event); } *pullSuccess = success; Loading @@ -76,7 +76,8 @@ bool StatsCallbackPuller::PullInternal(vector<shared_ptr<LogEvent>>* data) { cv->notify_one(); }); // Initiate the pull. // Initiate the pull. This is a oneway call to a different process, except // in unit tests. In process calls are not oneway. Status status = mCallback->onPullAtom(mTagId, resultReceiver); if (!status.isOk()) { return false; Loading @@ -84,10 +85,8 @@ bool StatsCallbackPuller::PullInternal(vector<shared_ptr<LogEvent>>* data) { { unique_lock<mutex> unique_lk(*cv_mutex); int64_t pullTimeoutNs = StatsPullerManager::kAllPullAtomInfo.at({.atomTag = mTagId}).pullTimeoutNs; // Wait until the pull finishes, or until the pull timeout. cv->wait_for(unique_lk, chrono::nanoseconds(pullTimeoutNs), cv->wait_for(unique_lk, chrono::nanoseconds(mTimeoutNs), [pullFinish] { return *pullFinish; }); if (!*pullFinish) { // Note: The parent stats puller will also note that there was a timeout and that the Loading @@ -96,7 +95,7 @@ bool StatsCallbackPuller::PullInternal(vector<shared_ptr<LogEvent>>* data) { return true; } else { // Only copy the data if we did not timeout and the pull was successful. if (pullSuccess) { if (*pullSuccess) { *data = std::move(*sharedData); } VLOG("StatsCallbackPuller::pull succeeded for %d", mTagId); Loading
cmds/statsd/src/external/StatsCallbackPuller.h +7 −1 Original line number Diff line number Diff line Loading @@ -27,11 +27,17 @@ namespace statsd { class StatsCallbackPuller : public StatsPuller { public: explicit StatsCallbackPuller(int tagId, const sp<IPullAtomCallback>& callback); explicit StatsCallbackPuller(int tagId, const sp<IPullAtomCallback>& callback, int64_t timeoutNs); private: bool PullInternal(vector<std::shared_ptr<LogEvent> >* data) override; const sp<IPullAtomCallback> mCallback; const int64_t mTimeoutNs; FRIEND_TEST(StatsCallbackPullerTest, PullFail); FRIEND_TEST(StatsCallbackPullerTest, PullSuccess); FRIEND_TEST(StatsCallbackPullerTest, PullTimeout); }; } // namespace statsd Loading
cmds/statsd/src/external/StatsPullerManager.cpp +5 −4 Original line number Diff line number Diff line Loading @@ -500,9 +500,10 @@ void StatsPullerManager::RegisterPullAtomCallback(const int uid, const int32_t a VLOG("RegisterPullerCallback: adding puller for tag %d", atomTag); // TODO: linkToDeath with the callback so that we can remove it and delete the puller. StatsdStats::getInstance().notePullerCallbackRegistrationChanged(atomTag, /*registered=*/true); kAllPullAtomInfo[{.atomTag = atomTag}] = {.additiveFields = additiveFields, kAllPullAtomInfo[{.atomTag = atomTag}] = { .additiveFields = additiveFields, .coolDownNs = coolDownNs, .puller = new StatsCallbackPuller(atomTag, callback), .puller = new StatsCallbackPuller(atomTag, callback, timeoutNs), .pullTimeoutNs = timeoutNs, }; } Loading
cmds/statsd/src/logd/LogEvent.cpp +11 −0 Original line number Diff line number Diff line Loading @@ -52,6 +52,17 @@ 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) { if (useNewSchema) { initNew(); } else { mContext = create_android_log_parser((char*)msg, len); init(mContext); if (mContext) android_log_destroy(&mContext); // set mContext to NULL } } LogEvent::LogEvent(const LogEvent& event) { mTagId = event.mTagId; mLogUid = event.mLogUid; Loading