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

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

Merge "filter pulled events for ValueMetric"

parents 52b976d8 054ce9cc
Loading
Loading
Loading
Loading
+26 −11
Original line number Diff line number Diff line
@@ -73,12 +73,19 @@ const int FIELD_ID_START_BUCKET_ELAPSED_MILLIS = 5;
const int FIELD_ID_END_BUCKET_ELAPSED_MILLIS = 6;

// ValueMetric has a minimum bucket size of 10min so that we don't pull too frequently
ValueMetricProducer::ValueMetricProducer(const ConfigKey& key, const ValueMetric& metric,
ValueMetricProducer::ValueMetricProducer(const ConfigKey& key,
                                         const ValueMetric& metric,
                                         const int conditionIndex,
                                         const sp<ConditionWizard>& wizard, const int pullTagId,
                                         const int64_t timeBaseNs, const int64_t startTimeNs,
                                         const sp<ConditionWizard>& conditionWizard,
                                         const int whatMatcherIndex,
                                         const sp<EventMatcherWizard>& matcherWizard,
                                         const int pullTagId,
                                         const int64_t timeBaseNs,
                                         const int64_t startTimeNs,
                                         const sp<StatsPullerManager>& pullerManager)
    : MetricProducer(metric.id(), key, timeBaseNs, conditionIndex, wizard),
    : MetricProducer(metric.id(), key, timeBaseNs, conditionIndex, conditionWizard),
      mWhatMatcherIndex(whatMatcherIndex),
      mEventMatcherWizard(matcherWizard),
      mPullerManager(pullerManager),
      mPullTagId(pullTagId),
      mIsPulled(pullTagId != -1),
@@ -143,7 +150,7 @@ ValueMetricProducer::ValueMetricProducer(const ConfigKey& key, const ValueMetric
    mCurrentBucketStartTimeNs = startTimeNs;
    // Kicks off the puller immediately if condition is true and diff based.
    if (mIsPulled && mCondition && mUseDiff) {
        pullLocked(startTimeNs);
        pullAndMatchEventsLocked(startTimeNs);
    }
    VLOG("value metric %lld created. bucket size %lld start_time: %lld", (long long)metric.id(),
         (long long)mBucketSizeNs, (long long)mTimeBaseNs);
@@ -307,7 +314,7 @@ void ValueMetricProducer::onConditionChangedLocked(const bool condition,

    // Pull on condition changes.
    if (mIsPulled && (mCondition != condition)) {
        pullLocked(eventTimeNs);
        pullAndMatchEventsLocked(eventTimeNs);
    }

    // when condition change from true to false, clear diff base
@@ -322,14 +329,17 @@ void ValueMetricProducer::onConditionChangedLocked(const bool condition,
    mCondition = condition;
}

void ValueMetricProducer::pullLocked(const int64_t timestampNs) {
void ValueMetricProducer::pullAndMatchEventsLocked(const int64_t timestampNs) {
    vector<std::shared_ptr<LogEvent>> allData;
    if (mPullerManager->Pull(mPullTagId, timestampNs, &allData)) {
        if (allData.size() == 0) {
            return;
        }
        for (const auto& data : allData) {
            onMatchedLogEventLocked(0, *data);
            if (mEventMatcherWizard->matchLogEvent(
                *data, mWhatMatcherIndex) == MatchingState::kMatched) {
                onMatchedLogEventLocked(mWhatMatcherIndex, *data);
            }
        }
    }
}
@@ -340,9 +350,9 @@ int64_t ValueMetricProducer::calcPreviousBucketEndTime(const int64_t currentTime

void ValueMetricProducer::onDataPulled(const std::vector<std::shared_ptr<LogEvent>>& allData) {
    std::lock_guard<std::mutex> lock(mMutex);

    if (mCondition) {
        if (allData.size() == 0) {
            VLOG("Data pulled is empty");
            return;
        }
        // For scheduled pulled data, the effective event time is snap to the nearest
@@ -360,10 +370,15 @@ void ValueMetricProducer::onDataPulled(const std::vector<std::shared_ptr<LogEven
            return;
        }
        for (const auto& data : allData) {
            if (mEventMatcherWizard->matchLogEvent(*data, mWhatMatcherIndex) ==
                MatchingState::kMatched) {
                data->setElapsedTimestampNs(bucketEndTime);
            onMatchedLogEventLocked(0, *data);
                onMatchedLogEventLocked(mWhatMatcherIndex, *data);
            }
        }
    } else {
        VLOG("No need to commit data on condition false.");
    }
}

void ValueMetricProducer::dumpStatesLocked(FILE* out, bool verbose) const {
+11 −3
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
#include "../condition/ConditionTracker.h"
#include "../external/PullDataReceiver.h"
#include "../external/StatsPullerManager.h"
#include "../matchers/EventMatcherWizard.h"
#include "../stats_log_util.h"
#include "MetricProducer.h"
#include "frameworks/base/cmds/statsd/src/statsd_config.pb.h"
@@ -41,7 +42,9 @@ struct ValueBucket {
class ValueMetricProducer : public virtual MetricProducer, public virtual PullDataReceiver {
public:
    ValueMetricProducer(const ConfigKey& key, const ValueMetric& valueMetric,
                        const int conditionIndex, const sp<ConditionWizard>& wizard,
                        const int conditionIndex, const sp<ConditionWizard>& conditionWizard,
                        const int whatMatcherIndex,
                        const sp<EventMatcherWizard>& matcherWizard,
                        const int pullTagId, const int64_t timeBaseNs, const int64_t startTimeNs,
                        const sp<StatsPullerManager>& pullerManager);

@@ -55,7 +58,7 @@ public:
                          const int64_t version) override {
        std::lock_guard<std::mutex> lock(mMutex);
        if (mIsPulled && mCondition) {
            pullLocked(eventTimeNs - 1);
            pullAndMatchEventsLocked(eventTimeNs - 1);
        }
        flushCurrentBucketLocked(eventTimeNs);
        mCurrentBucketStartTimeNs = eventTimeNs;
@@ -96,6 +99,10 @@ private:
    // Calculate previous bucket end time based on current time.
    int64_t calcPreviousBucketEndTime(const int64_t currentTimeNs);

    const int mWhatMatcherIndex;

    sp<EventMatcherWizard> mEventMatcherWizard;

    sp<StatsPullerManager> mPullerManager;

    // Value fields for matching.
@@ -139,7 +146,7 @@ private:
    // Util function to check whether the specified dimension hits the guardrail.
    bool hitGuardRailLocked(const MetricDimensionKey& newKey);

    void pullLocked(const int64_t timestampNs);
    void pullAndMatchEventsLocked(const int64_t timestampNs);

    static const size_t kBucketSize = sizeof(ValueBucket{});

@@ -158,6 +165,7 @@ private:
    const bool mSkipZeroDiffOutput;

    FRIEND_TEST(ValueMetricProducerTest, TestPulledEventsNoCondition);
  FRIEND_TEST(ValueMetricProducerTest, TestPulledEventsWithFiltering);
    FRIEND_TEST(ValueMetricProducerTest, TestPulledEventsTakeAbsoluteValueOnReset);
    FRIEND_TEST(ValueMetricProducerTest, TestPulledEventsTakeZeroOnReset);
    FRIEND_TEST(ValueMetricProducerTest, TestEventsWithNonSlicedCondition);
+3 −3
Original line number Diff line number Diff line
@@ -488,8 +488,8 @@ bool initMetrics(const ConfigKey& key, const StatsdConfig& config, const int64_t
            }
        }

        sp<MetricProducer> valueProducer =
                new ValueMetricProducer(key, metric, conditionIndex, wizard, pullTagId,
        sp<MetricProducer> valueProducer = new ValueMetricProducer(
                key, metric, conditionIndex, wizard, trackerIndex, matcherWizard, pullTagId,
                timeBaseTimeNs, currentTimeNs, pullerManager);
        allMetricProducers.push_back(valueProducer);
    }
+267 −30

File changed.

Preview size limit exceeded, changes collapsed.