Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0d9dd2b0 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix Race Condition"

parents 8b09990e 9ec159ac
Loading
Loading
Loading
Loading
+26 −5
Original line number Original line Diff line number Diff line
@@ -328,11 +328,6 @@ void StatsLogProcessor::OnConfigUpdatedLocked(
                               mAnomalyAlarmMonitor, mPeriodicAlarmMonitor);
                               mAnomalyAlarmMonitor, mPeriodicAlarmMonitor);
    if (newMetricsManager->isConfigValid()) {
    if (newMetricsManager->isConfigValid()) {
        mUidMap->OnConfigUpdated(key);
        mUidMap->OnConfigUpdated(key);
        if (newMetricsManager->shouldAddUidMapListener()) {
            // We have to add listener after the MetricsManager is constructed because it's
            // not safe to create wp or sp from this pointer inside its constructor.
            mUidMap->addListener(newMetricsManager.get());
        }
        newMetricsManager->refreshTtl(timestampNs);
        newMetricsManager->refreshTtl(timestampNs);
        mMetricsManagers[key] = newMetricsManager;
        mMetricsManagers[key] = newMetricsManager;
        VLOG("StatsdConfig valid");
        VLOG("StatsdConfig valid");
@@ -753,6 +748,32 @@ 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) {
        it.second->notifyAppUpgrade(eventTimeNs, apk, uid, version);
    }
}

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) {
        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) {
        it.second->onUidMapReceived(eventTimeNs);
    }
}

void StatsLogProcessor::noteOnDiskData(const ConfigKey& key) {
void StatsLogProcessor::noteOnDiskData(const ConfigKey& key) {
    std::lock_guard<std::mutex> lock(mMetricsMutex);
    std::lock_guard<std::mutex> lock(mMetricsMutex);
    mOnDiskDataConfigs.insert(key);
    mOnDiskDataConfigs.insert(key);
+11 −1
Original line number Original line Diff line number Diff line
@@ -32,7 +32,7 @@ namespace os {
namespace statsd {
namespace statsd {




class StatsLogProcessor : public ConfigListener {
class StatsLogProcessor : public ConfigListener, public virtual PackageInfoListener {
public:
public:
    StatsLogProcessor(const sp<UidMap>& uidMap, const sp<StatsPullerManager>& pullerManager,
    StatsLogProcessor(const sp<UidMap>& uidMap, const sp<StatsPullerManager>& pullerManager,
                      const sp<AlarmMonitor>& anomalyAlarmMonitor,
                      const sp<AlarmMonitor>& anomalyAlarmMonitor,
@@ -91,6 +91,16 @@ public:
    /* Sets the active status/ttl for all configs and metrics to the status in ActiveConfigList. */
    /* Sets the active status/ttl for all configs and metrics to the status in ActiveConfigList. */
    void SetConfigsActiveState(const ActiveConfigList& activeConfigList, int64_t currentTimeNs);
    void SetConfigsActiveState(const ActiveConfigList& activeConfigList, int64_t currentTimeNs);


    /* Notify all MetricsManagers of app upgrades */
    void notifyAppUpgrade(const int64_t& eventTimeNs, const string& apk, const int uid,
                          const int64_t version) override;

    /* Notify all MetricsManagers of app removals */
    void notifyAppRemoved(const int64_t& eventTimeNs, const string& apk, const int uid) override;

    /* Notify all MetricsManagers of uid map snapshots received */
    void onUidMapReceived(const int64_t& eventTimeNs) override;

    // Reset all configs.
    // Reset all configs.
    void resetConfigs();
    void resetConfigs();


+1 −0
Original line number Original line Diff line number Diff line
@@ -200,6 +200,7 @@ StatsService::StatsService(const sp<Looper>& handlerLooper, shared_ptr<LogEventQ
                }
                }
            });
            });


    mUidMap->setListener(mProcessor);
    mConfigManager->AddListener(mProcessor);
    mConfigManager->AddListener(mProcessor);


    init_system_properties();
    init_system_properties();
+4 −9
Original line number Original line Diff line number Diff line
@@ -87,7 +87,7 @@ struct Activation {
// writing the report to dropbox. MetricProducers should respond to package changes as required in
// writing the report to dropbox. MetricProducers should respond to package changes as required in
// PackageInfoListener, but if none of the metrics are slicing by package name, then the update can
// PackageInfoListener, but if none of the metrics are slicing by package name, then the update can
// be a no-op.
// be a no-op.
class MetricProducer : public virtual PackageInfoListener, public virtual StateListener {
class MetricProducer : public virtual android::RefBase, public virtual StateListener {
public:
public:
    MetricProducer(const int64_t& metricId, const ConfigKey& key, const int64_t timeBaseNs,
    MetricProducer(const int64_t& metricId, const ConfigKey& key, const int64_t timeBaseNs,
                   const int conditionIndex, const sp<ConditionWizard>& wizard,
                   const int conditionIndex, const sp<ConditionWizard>& wizard,
@@ -109,8 +109,8 @@ public:
     * the flush again when the end timestamp is forced to be now, and then after flushing, update
     * the flush again when the end timestamp is forced to be now, and then after flushing, update
     * the start timestamp to be now.
     * the start timestamp to be now.
     */
     */
    void notifyAppUpgrade(const int64_t& eventTimeNs, const string& apk, const int uid,
    virtual void notifyAppUpgrade(const int64_t& eventTimeNs, const string& apk, const int uid,
                          const int64_t version) override {
                          const int64_t version) {
        std::lock_guard<std::mutex> lock(mMutex);
        std::lock_guard<std::mutex> lock(mMutex);


        if (eventTimeNs > getCurrentBucketEndTimeNs()) {
        if (eventTimeNs > getCurrentBucketEndTimeNs()) {
@@ -123,16 +123,11 @@ public:
        // is a partial bucket and can merge it with the previous bucket.
        // is a partial bucket and can merge it with the previous bucket.
    };
    };


    void notifyAppRemoved(const int64_t& eventTimeNs, const string& apk, const int uid) override{
    void notifyAppRemoved(const int64_t& eventTimeNs, const string& apk, const int uid) {
        // Force buckets to split on removal also.
        // Force buckets to split on removal also.
        notifyAppUpgrade(eventTimeNs, apk, uid, 0);
        notifyAppUpgrade(eventTimeNs, apk, uid, 0);
    };
    };


    void onUidMapReceived(const int64_t& eventTimeNs) override{
            // Purposefully don't flush partial buckets on a new snapshot.
            // This occurs if a new user is added/removed or statsd crashes.
    };

    // Consume the parsed stats log entry that already matched the "what" of the metric.
    // Consume the parsed stats log entry that already matched the "what" of the metric.
    void onMatchedLogEvent(const size_t matcherIndex, const LogEvent& event) {
    void onMatchedLogEvent(const size_t matcherIndex, const LogEvent& event) {
        std::lock_guard<std::mutex> lock(mMutex);
        std::lock_guard<std::mutex> lock(mMutex);
+11 −0
Original line number Original line Diff line number Diff line
@@ -182,6 +182,10 @@ bool MetricsManager::isConfigValid() const {


void MetricsManager::notifyAppUpgrade(const int64_t& eventTimeNs, const string& apk, const int uid,
void MetricsManager::notifyAppUpgrade(const int64_t& eventTimeNs, const string& apk, const int uid,
                                      const int64_t version) {
                                      const int64_t version) {
    // Inform all metric producers.
    for (auto it : mAllMetricProducers) {
        it->notifyAppUpgrade(eventTimeNs, apk, uid, version);
    }
    // check if we care this package
    // check if we care this package
    if (std::find(mAllowedPkg.begin(), mAllowedPkg.end(), apk) == mAllowedPkg.end()) {
    if (std::find(mAllowedPkg.begin(), mAllowedPkg.end(), apk) == mAllowedPkg.end()) {
        return;
        return;
@@ -193,6 +197,10 @@ void MetricsManager::notifyAppUpgrade(const int64_t& eventTimeNs, const string&


void MetricsManager::notifyAppRemoved(const int64_t& eventTimeNs, const string& apk,
void MetricsManager::notifyAppRemoved(const int64_t& eventTimeNs, const string& apk,
                                      const int uid) {
                                      const int uid) {
    // Inform all metric producers.
    for (auto it : mAllMetricProducers) {
        it->notifyAppRemoved(eventTimeNs, apk, uid);
    }
    // check if we care this package
    // check if we care this package
    if (std::find(mAllowedPkg.begin(), mAllowedPkg.end(), apk) == mAllowedPkg.end()) {
    if (std::find(mAllowedPkg.begin(), mAllowedPkg.end(), apk) == mAllowedPkg.end()) {
        return;
        return;
@@ -203,6 +211,9 @@ void MetricsManager::notifyAppRemoved(const int64_t& eventTimeNs, const string&
}
}


void MetricsManager::onUidMapReceived(const int64_t& eventTimeNs) {
void MetricsManager::onUidMapReceived(const int64_t& eventTimeNs) {
    // Purposefully don't inform metric producers on a new snapshot
    // because we don't need to flush partial buckets.
    // This occurs if a new user is added/removed or statsd crashes.
    if (mAllowedPkg.size() == 0) {
    if (mAllowedPkg.size() == 0) {
        return;
        return;
    }
    }
Loading