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

Commit 0f0e5955 authored by Christine Tsai's avatar Christine Tsai Committed by Android (Google) Code Review
Browse files

Merge "Remove ConditionState parameter from ValueMetric's pull and accumulate functions"

parents 5aa92326 78b85709
Loading
Loading
Loading
Loading
+9 −11
Original line number Original line Diff line number Diff line
@@ -159,7 +159,7 @@ ValueMetricProducer::ValueMetricProducer(


     // Kicks off the puller immediately if condition is true and diff based.
     // Kicks off the puller immediately if condition is true and diff based.
    if (mIsActive && mIsPulled && mCondition == ConditionState::kTrue && mUseDiff) {
    if (mIsActive && mIsPulled && mCondition == ConditionState::kTrue && mUseDiff) {
        pullAndMatchEventsLocked(mCurrentBucketStartTimeNs, mCondition);
        pullAndMatchEventsLocked(mCurrentBucketStartTimeNs);
    }
    }
    // Now that activations are processed, start the condition timer if needed.
    // Now that activations are processed, start the condition timer if needed.
    mConditionTimer.onConditionChanged(mIsActive && mCondition == ConditionState::kTrue,
    mConditionTimer.onConditionChanged(mIsActive && mCondition == ConditionState::kTrue,
@@ -216,7 +216,7 @@ void ValueMetricProducer::onDumpReportLocked(const int64_t dumpTimeNs,
                    invalidateCurrentBucket();
                    invalidateCurrentBucket();
                    break;
                    break;
                case NO_TIME_CONSTRAINTS:
                case NO_TIME_CONSTRAINTS:
                    pullAndMatchEventsLocked(dumpTimeNs, mCondition);
                    pullAndMatchEventsLocked(dumpTimeNs);
                    break;
                    break;
            }
            }
        }
        }
@@ -366,7 +366,7 @@ void ValueMetricProducer::onActiveStateChangedLocked(const int64_t& eventTimeNs)
    // Pull on active state changes.
    // Pull on active state changes.
    if (!isEventTooLate) {
    if (!isEventTooLate) {
        if (mIsPulled) {
        if (mIsPulled) {
            pullAndMatchEventsLocked(eventTimeNs, mCondition);
            pullAndMatchEventsLocked(eventTimeNs);
        }
        }
        // When active state changes from true to false, clear diff base but don't
        // When active state changes from true to false, clear diff base but don't
        // reset other counters as we may accumulate more value in the bucket.
        // reset other counters as we may accumulate more value in the bucket.
@@ -425,7 +425,7 @@ void ValueMetricProducer::onConditionChangedLocked(const bool condition,
    // called before #onDataPulled.
    // called before #onDataPulled.
    if (mIsPulled &&
    if (mIsPulled &&
        (newCondition == ConditionState::kTrue || mCondition == ConditionState::kTrue)) {
        (newCondition == ConditionState::kTrue || mCondition == ConditionState::kTrue)) {
        pullAndMatchEventsLocked(eventTimeNs, newCondition);
        pullAndMatchEventsLocked(eventTimeNs);
    }
    }


    // For metrics that use diff, when condition changes from true to false,
    // For metrics that use diff, when condition changes from true to false,
@@ -443,8 +443,7 @@ void ValueMetricProducer::onConditionChangedLocked(const bool condition,
    mConditionTimer.onConditionChanged(mCondition, eventTimeNs);
    mConditionTimer.onConditionChanged(mCondition, eventTimeNs);
}
}


void ValueMetricProducer::pullAndMatchEventsLocked(const int64_t timestampNs,
void ValueMetricProducer::pullAndMatchEventsLocked(const int64_t timestampNs) {
        ConditionState condition) {
    vector<std::shared_ptr<LogEvent>> allData;
    vector<std::shared_ptr<LogEvent>> allData;
    if (!mPullerManager->Pull(mPullTagId, &allData)) {
    if (!mPullerManager->Pull(mPullTagId, &allData)) {
        ALOGE("Stats puller failed for tag: %d at %lld", mPullTagId, (long long)timestampNs);
        ALOGE("Stats puller failed for tag: %d at %lld", mPullTagId, (long long)timestampNs);
@@ -452,7 +451,7 @@ void ValueMetricProducer::pullAndMatchEventsLocked(const int64_t timestampNs,
        return;
        return;
    }
    }


    accumulateEvents(allData, timestampNs, timestampNs, condition);
    accumulateEvents(allData, timestampNs, timestampNs);
}
}


int64_t ValueMetricProducer::calcPreviousBucketEndTime(const int64_t currentTimeNs) {
int64_t ValueMetricProducer::calcPreviousBucketEndTime(const int64_t currentTimeNs) {
@@ -474,7 +473,7 @@ void ValueMetricProducer::onDataPulled(const std::vector<std::shared_ptr<LogEven
            if (isEventLate) {
            if (isEventLate) {
                // If the event is late, we are in the middle of a bucket. Just
                // If the event is late, we are in the middle of a bucket. Just
                // process the data without trying to snap the data to the nearest bucket.
                // process the data without trying to snap the data to the nearest bucket.
                accumulateEvents(allData, originalPullTimeNs, originalPullTimeNs, mCondition);
                accumulateEvents(allData, originalPullTimeNs, originalPullTimeNs);
            } else {
            } else {
                // For scheduled pulled data, the effective event time is snap to the nearest
                // For scheduled pulled data, the effective event time is snap to the nearest
                // bucket end. In the case of waking up from a deep sleep state, we will
                // bucket end. In the case of waking up from a deep sleep state, we will
@@ -488,7 +487,7 @@ void ValueMetricProducer::onDataPulled(const std::vector<std::shared_ptr<LogEven
                int64_t bucketEndTime = calcPreviousBucketEndTime(originalPullTimeNs) - 1;
                int64_t bucketEndTime = calcPreviousBucketEndTime(originalPullTimeNs) - 1;
                StatsdStats::getInstance().noteBucketBoundaryDelayNs(
                StatsdStats::getInstance().noteBucketBoundaryDelayNs(
                        mMetricId, originalPullTimeNs - bucketEndTime);
                        mMetricId, originalPullTimeNs - bucketEndTime);
                accumulateEvents(allData, originalPullTimeNs, bucketEndTime, mCondition);
                accumulateEvents(allData, originalPullTimeNs, bucketEndTime);
            }
            }
        }
        }
    }
    }
@@ -499,8 +498,7 @@ void ValueMetricProducer::onDataPulled(const std::vector<std::shared_ptr<LogEven
}
}


void ValueMetricProducer::accumulateEvents(const std::vector<std::shared_ptr<LogEvent>>& allData,
void ValueMetricProducer::accumulateEvents(const std::vector<std::shared_ptr<LogEvent>>& allData,
                                           int64_t originalPullTimeNs, int64_t eventElapsedTimeNs,
                                           int64_t originalPullTimeNs, int64_t eventElapsedTimeNs) {
                                           ConditionState condition) {
    bool isEventLate = eventElapsedTimeNs < mCurrentBucketStartTimeNs;
    bool isEventLate = eventElapsedTimeNs < mCurrentBucketStartTimeNs;
    if (isEventLate) {
    if (isEventLate) {
        VLOG("Skip bucket end pull due to late arrival: %lld vs %lld",
        VLOG("Skip bucket end pull due to late arrival: %lld vs %lld",
+3 −4
Original line number Original line Diff line number Diff line
@@ -78,7 +78,7 @@ public:
            return;
            return;
        }
        }
        if (mIsPulled && mCondition) {
        if (mIsPulled && mCondition) {
            pullAndMatchEventsLocked(eventTimeNs, mCondition);
            pullAndMatchEventsLocked(eventTimeNs);
        }
        }
        flushCurrentBucketLocked(eventTimeNs, eventTimeNs);
        flushCurrentBucketLocked(eventTimeNs, eventTimeNs);
    };
    };
@@ -188,11 +188,10 @@ private:


    bool hitFullBucketGuardRailLocked(const MetricDimensionKey& newKey);
    bool hitFullBucketGuardRailLocked(const MetricDimensionKey& newKey);


    void pullAndMatchEventsLocked(const int64_t timestampNs, ConditionState condition);
    void pullAndMatchEventsLocked(const int64_t timestampNs);


    void accumulateEvents(const std::vector<std::shared_ptr<LogEvent>>& allData,
    void accumulateEvents(const std::vector<std::shared_ptr<LogEvent>>& allData,
                          int64_t originalPullTimeNs, int64_t eventElapsedTimeNs,
                          int64_t originalPullTimeNs, int64_t eventElapsedTimeNs);
                          ConditionState condition);


    ValueBucket buildPartialBucket(int64_t bucketEndTime,
    ValueBucket buildPartialBucket(int64_t bucketEndTime,
                                   const std::vector<Interval>& intervals);
                                   const std::vector<Interval>& intervals);