Loading cmds/statsd/Android.bp +2 −2 Original line number Diff line number Diff line Loading @@ -104,7 +104,7 @@ cc_defaults { "src/subscriber/IncidentdReporter.cpp", "src/subscriber/SubscriberReporter.cpp", "src/uid_data.proto", "src/utils/NamedLatch.cpp", "src/utils/MultiConditionTrigger.cpp", ], local_include_dirs: [ Loading Loading @@ -366,7 +366,7 @@ cc_test { "tests/StatsService_test.cpp", "tests/storage/StorageManager_test.cpp", "tests/UidMap_test.cpp", "tests/utils/NamedLatch_test.cpp", "tests/utils/MultiConditionTrigger_test.cpp", ], static_libs: [ Loading cmds/statsd/src/StatsLogProcessor.cpp +14 −6 Original line number Diff line number Diff line Loading @@ -1055,8 +1055,8 @@ int64_t StatsLogProcessor::getLastReportTimeNs(const ConfigKey& key) { void StatsLogProcessor::notifyAppUpgrade(const int64_t& eventTimeNs, const string& apk, const int uid, const int64_t version) { std::lock_guard<std::mutex> lock(mMetricsMutex); ALOGW("Received app upgrade"); for (auto it : mMetricsManagers) { VLOG("Received app upgrade"); for (const auto& it : mMetricsManagers) { it.second->notifyAppUpgrade(eventTimeNs, apk, uid, version); } } Loading @@ -1064,20 +1064,28 @@ void StatsLogProcessor::notifyAppUpgrade(const int64_t& eventTimeNs, const strin void StatsLogProcessor::notifyAppRemoved(const int64_t& eventTimeNs, const string& apk, const int uid) { std::lock_guard<std::mutex> lock(mMetricsMutex); ALOGW("Received app removed"); for (auto it : mMetricsManagers) { VLOG("Received app removed"); for (const auto& it : mMetricsManagers) { it.second->notifyAppRemoved(eventTimeNs, apk, uid); } } void StatsLogProcessor::onUidMapReceived(const int64_t& eventTimeNs) { std::lock_guard<std::mutex> lock(mMetricsMutex); ALOGW("Received uid map"); for (auto it : mMetricsManagers) { VLOG("Received uid map"); for (const auto& it : mMetricsManagers) { it.second->onUidMapReceived(eventTimeNs); } } void StatsLogProcessor::onStatsdInitCompleted(const int64_t& elapsedTimeNs) { std::lock_guard<std::mutex> lock(mMetricsMutex); VLOG("Received boot completed signal"); for (const auto& it : mMetricsManagers) { it.second->onStatsdInitCompleted(elapsedTimeNs); } } void StatsLogProcessor::noteOnDiskData(const ConfigKey& key) { std::lock_guard<std::mutex> lock(mMetricsMutex); mOnDiskDataConfigs.insert(key); Loading cmds/statsd/src/StatsLogProcessor.h +5 −0 Original line number Diff line number Diff line Loading @@ -120,6 +120,11 @@ public: /* Notify all MetricsManagers of uid map snapshots received */ void onUidMapReceived(const int64_t& eventTimeNs) override; /* Notify all metrics managers of boot completed * This will force a bucket split when the boot is finished. */ void onStatsdInitCompleted(const int64_t& elapsedTimeNs); // Reset all configs. void resetConfigs(); Loading cmds/statsd/src/StatsService.cpp +5 −10 Original line number Diff line number Diff line Loading @@ -118,7 +118,8 @@ StatsService::StatsService(const sp<Looper>& handlerLooper, shared_ptr<LogEventQ } })), mEventQueue(queue), mBootCompleteLatch({kBootCompleteTag, kUidMapReceivedTag, kAllPullersRegisteredTag}), mBootCompleteTrigger({kBootCompleteTag, kUidMapReceivedTag, kAllPullersRegisteredTag}, [this]() { mProcessor->onStatsdInitCompleted(getElapsedRealtimeNs()); }), mStatsCompanionServiceDeathRecipient( AIBinder_DeathRecipient_new(StatsService::statsCompanionServiceDied)) { mUidMap = UidMap::getInstance(); Loading Loading @@ -165,12 +166,6 @@ StatsService::StatsService(const sp<Looper>& handlerLooper, shared_ptr<LogEventQ std::thread pushedEventThread([this] { readLogs(); }); pushedEventThread.detach(); } std::thread bootCompletedThread([this] { mBootCompleteLatch.wait(); VLOG("In the boot completed thread"); }); bootCompletedThread.detach(); } StatsService::~StatsService() { Loading Loading @@ -946,7 +941,7 @@ Status StatsService::informAllUidData(const ScopedFileDescriptor& fd) { packageNames, installers); mBootCompleteLatch.countDown(kUidMapReceivedTag); mBootCompleteTrigger.markComplete(kUidMapReceivedTag); VLOG("StatsService::informAllUidData UidData proto parsed successfully."); return Status::ok(); } Loading Loading @@ -1066,7 +1061,7 @@ Status StatsService::bootCompleted() { ENFORCE_UID(AID_SYSTEM); VLOG("StatsService::bootCompleted was called"); mBootCompleteLatch.countDown(kBootCompleteTag); mBootCompleteTrigger.markComplete(kBootCompleteTag); return Status::ok(); } Loading Loading @@ -1226,7 +1221,7 @@ Status StatsService::allPullersFromBootRegistered() { ENFORCE_UID(AID_SYSTEM); VLOG("StatsService::allPullersFromBootRegistered was called"); mBootCompleteLatch.countDown(kAllPullersRegisteredTag); mBootCompleteTrigger.markComplete(kAllPullersRegisteredTag); return Status::ok(); } Loading cmds/statsd/src/StatsService.h +5 −2 Original line number Diff line number Diff line Loading @@ -33,7 +33,7 @@ #include "packages/UidMap.h" #include "shell/ShellSubscriber.h" #include "statscompanion_util.h" #include "utils/NamedLatch.h" #include "utils/MultiConditionTrigger.h" using namespace android; using namespace android::os; Loading Loading @@ -381,7 +381,7 @@ private: mutable mutex mShellSubscriberMutex; std::shared_ptr<LogEventQueue> mEventQueue; NamedLatch mBootCompleteLatch; MultiConditionTrigger mBootCompleteTrigger; static const inline string kBootCompleteTag = "BOOT_COMPLETE"; static const inline string kUidMapReceivedTag = "UID_MAP"; static const inline string kAllPullersRegisteredTag = "PULLERS_REGISTERED"; Loading @@ -394,11 +394,14 @@ private: FRIEND_TEST(StatsServiceTest, TestAddConfig_invalid); FRIEND_TEST(StatsServiceTest, TestGetUidFromArgs); FRIEND_TEST(PartialBucketE2eTest, TestCountMetricNoSplitOnNewApp); FRIEND_TEST(PartialBucketE2eTest, TestCountMetricSplitOnBoot); FRIEND_TEST(PartialBucketE2eTest, TestCountMetricSplitOnUpgrade); FRIEND_TEST(PartialBucketE2eTest, TestCountMetricSplitOnRemoval); FRIEND_TEST(PartialBucketE2eTest, TestCountMetricWithoutSplit); FRIEND_TEST(PartialBucketE2eTest, TestValueMetricOnBootWithoutMinPartialBucket); FRIEND_TEST(PartialBucketE2eTest, TestValueMetricWithoutMinPartialBucket); FRIEND_TEST(PartialBucketE2eTest, TestValueMetricWithMinPartialBucket); FRIEND_TEST(PartialBucketE2eTest, TestGaugeMetricOnBootWithoutMinPartialBucket); FRIEND_TEST(PartialBucketE2eTest, TestGaugeMetricWithoutMinPartialBucket); FRIEND_TEST(PartialBucketE2eTest, TestGaugeMetricWithMinPartialBucket); }; Loading Loading
cmds/statsd/Android.bp +2 −2 Original line number Diff line number Diff line Loading @@ -104,7 +104,7 @@ cc_defaults { "src/subscriber/IncidentdReporter.cpp", "src/subscriber/SubscriberReporter.cpp", "src/uid_data.proto", "src/utils/NamedLatch.cpp", "src/utils/MultiConditionTrigger.cpp", ], local_include_dirs: [ Loading Loading @@ -366,7 +366,7 @@ cc_test { "tests/StatsService_test.cpp", "tests/storage/StorageManager_test.cpp", "tests/UidMap_test.cpp", "tests/utils/NamedLatch_test.cpp", "tests/utils/MultiConditionTrigger_test.cpp", ], static_libs: [ Loading
cmds/statsd/src/StatsLogProcessor.cpp +14 −6 Original line number Diff line number Diff line Loading @@ -1055,8 +1055,8 @@ int64_t StatsLogProcessor::getLastReportTimeNs(const ConfigKey& key) { void StatsLogProcessor::notifyAppUpgrade(const int64_t& eventTimeNs, const string& apk, const int uid, const int64_t version) { std::lock_guard<std::mutex> lock(mMetricsMutex); ALOGW("Received app upgrade"); for (auto it : mMetricsManagers) { VLOG("Received app upgrade"); for (const auto& it : mMetricsManagers) { it.second->notifyAppUpgrade(eventTimeNs, apk, uid, version); } } Loading @@ -1064,20 +1064,28 @@ void StatsLogProcessor::notifyAppUpgrade(const int64_t& eventTimeNs, const strin void StatsLogProcessor::notifyAppRemoved(const int64_t& eventTimeNs, const string& apk, const int uid) { std::lock_guard<std::mutex> lock(mMetricsMutex); ALOGW("Received app removed"); for (auto it : mMetricsManagers) { VLOG("Received app removed"); for (const auto& it : mMetricsManagers) { it.second->notifyAppRemoved(eventTimeNs, apk, uid); } } void StatsLogProcessor::onUidMapReceived(const int64_t& eventTimeNs) { std::lock_guard<std::mutex> lock(mMetricsMutex); ALOGW("Received uid map"); for (auto it : mMetricsManagers) { VLOG("Received uid map"); for (const auto& it : mMetricsManagers) { it.second->onUidMapReceived(eventTimeNs); } } void StatsLogProcessor::onStatsdInitCompleted(const int64_t& elapsedTimeNs) { std::lock_guard<std::mutex> lock(mMetricsMutex); VLOG("Received boot completed signal"); for (const auto& it : mMetricsManagers) { it.second->onStatsdInitCompleted(elapsedTimeNs); } } void StatsLogProcessor::noteOnDiskData(const ConfigKey& key) { std::lock_guard<std::mutex> lock(mMetricsMutex); mOnDiskDataConfigs.insert(key); Loading
cmds/statsd/src/StatsLogProcessor.h +5 −0 Original line number Diff line number Diff line Loading @@ -120,6 +120,11 @@ public: /* Notify all MetricsManagers of uid map snapshots received */ void onUidMapReceived(const int64_t& eventTimeNs) override; /* Notify all metrics managers of boot completed * This will force a bucket split when the boot is finished. */ void onStatsdInitCompleted(const int64_t& elapsedTimeNs); // Reset all configs. void resetConfigs(); Loading
cmds/statsd/src/StatsService.cpp +5 −10 Original line number Diff line number Diff line Loading @@ -118,7 +118,8 @@ StatsService::StatsService(const sp<Looper>& handlerLooper, shared_ptr<LogEventQ } })), mEventQueue(queue), mBootCompleteLatch({kBootCompleteTag, kUidMapReceivedTag, kAllPullersRegisteredTag}), mBootCompleteTrigger({kBootCompleteTag, kUidMapReceivedTag, kAllPullersRegisteredTag}, [this]() { mProcessor->onStatsdInitCompleted(getElapsedRealtimeNs()); }), mStatsCompanionServiceDeathRecipient( AIBinder_DeathRecipient_new(StatsService::statsCompanionServiceDied)) { mUidMap = UidMap::getInstance(); Loading Loading @@ -165,12 +166,6 @@ StatsService::StatsService(const sp<Looper>& handlerLooper, shared_ptr<LogEventQ std::thread pushedEventThread([this] { readLogs(); }); pushedEventThread.detach(); } std::thread bootCompletedThread([this] { mBootCompleteLatch.wait(); VLOG("In the boot completed thread"); }); bootCompletedThread.detach(); } StatsService::~StatsService() { Loading Loading @@ -946,7 +941,7 @@ Status StatsService::informAllUidData(const ScopedFileDescriptor& fd) { packageNames, installers); mBootCompleteLatch.countDown(kUidMapReceivedTag); mBootCompleteTrigger.markComplete(kUidMapReceivedTag); VLOG("StatsService::informAllUidData UidData proto parsed successfully."); return Status::ok(); } Loading Loading @@ -1066,7 +1061,7 @@ Status StatsService::bootCompleted() { ENFORCE_UID(AID_SYSTEM); VLOG("StatsService::bootCompleted was called"); mBootCompleteLatch.countDown(kBootCompleteTag); mBootCompleteTrigger.markComplete(kBootCompleteTag); return Status::ok(); } Loading Loading @@ -1226,7 +1221,7 @@ Status StatsService::allPullersFromBootRegistered() { ENFORCE_UID(AID_SYSTEM); VLOG("StatsService::allPullersFromBootRegistered was called"); mBootCompleteLatch.countDown(kAllPullersRegisteredTag); mBootCompleteTrigger.markComplete(kAllPullersRegisteredTag); return Status::ok(); } Loading
cmds/statsd/src/StatsService.h +5 −2 Original line number Diff line number Diff line Loading @@ -33,7 +33,7 @@ #include "packages/UidMap.h" #include "shell/ShellSubscriber.h" #include "statscompanion_util.h" #include "utils/NamedLatch.h" #include "utils/MultiConditionTrigger.h" using namespace android; using namespace android::os; Loading Loading @@ -381,7 +381,7 @@ private: mutable mutex mShellSubscriberMutex; std::shared_ptr<LogEventQueue> mEventQueue; NamedLatch mBootCompleteLatch; MultiConditionTrigger mBootCompleteTrigger; static const inline string kBootCompleteTag = "BOOT_COMPLETE"; static const inline string kUidMapReceivedTag = "UID_MAP"; static const inline string kAllPullersRegisteredTag = "PULLERS_REGISTERED"; Loading @@ -394,11 +394,14 @@ private: FRIEND_TEST(StatsServiceTest, TestAddConfig_invalid); FRIEND_TEST(StatsServiceTest, TestGetUidFromArgs); FRIEND_TEST(PartialBucketE2eTest, TestCountMetricNoSplitOnNewApp); FRIEND_TEST(PartialBucketE2eTest, TestCountMetricSplitOnBoot); FRIEND_TEST(PartialBucketE2eTest, TestCountMetricSplitOnUpgrade); FRIEND_TEST(PartialBucketE2eTest, TestCountMetricSplitOnRemoval); FRIEND_TEST(PartialBucketE2eTest, TestCountMetricWithoutSplit); FRIEND_TEST(PartialBucketE2eTest, TestValueMetricOnBootWithoutMinPartialBucket); FRIEND_TEST(PartialBucketE2eTest, TestValueMetricWithoutMinPartialBucket); FRIEND_TEST(PartialBucketE2eTest, TestValueMetricWithMinPartialBucket); FRIEND_TEST(PartialBucketE2eTest, TestGaugeMetricOnBootWithoutMinPartialBucket); FRIEND_TEST(PartialBucketE2eTest, TestGaugeMetricWithoutMinPartialBucket); FRIEND_TEST(PartialBucketE2eTest, TestGaugeMetricWithMinPartialBucket); }; Loading