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

Commit d59a6589 authored by Yao Chen's avatar Yao Chen
Browse files

Some fixes in duration metrics

+ Don't need to keep the condition key if the condition is not sliced.
+ Whiten the hash before returning.

Test: statsd_test
Change-Id: Ie0bcb14b3adc4a15b79ba3be050431a672a68c28
parent c7dca1bd
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -117,11 +117,11 @@ unique_ptr<DurationTracker> DurationMetricProducer::createDurationTracker(
        case DurationMetric_AggregationType_SUM:
        case DurationMetric_AggregationType_SUM:
            return make_unique<OringDurationTracker>(
            return make_unique<OringDurationTracker>(
                    mConfigKey, mMetricId, eventKey, mWizard, mConditionTrackerIndex, mNested,
                    mConfigKey, mMetricId, eventKey, mWizard, mConditionTrackerIndex, mNested,
                    mCurrentBucketStartTimeNs, mBucketSizeNs, mAnomalyTrackers);
                    mCurrentBucketStartTimeNs, mBucketSizeNs, mConditionSliced, mAnomalyTrackers);
        case DurationMetric_AggregationType_MAX_SPARSE:
        case DurationMetric_AggregationType_MAX_SPARSE:
            return make_unique<MaxDurationTracker>(
            return make_unique<MaxDurationTracker>(
                    mConfigKey, mMetricId, eventKey, mWizard, mConditionTrackerIndex, mNested,
                    mConfigKey, mMetricId, eventKey, mWizard, mConditionTrackerIndex, mNested,
                    mCurrentBucketStartTimeNs, mBucketSizeNs, mAnomalyTrackers);
                    mCurrentBucketStartTimeNs, mBucketSizeNs, mConditionSliced, mAnomalyTrackers);
    }
    }
}
}


+4 −1
Original line number Original line Diff line number Diff line
@@ -62,7 +62,7 @@ class DurationTracker {
public:
public:
    DurationTracker(const ConfigKey& key, const int64_t& id, const HashableDimensionKey& eventKey,
    DurationTracker(const ConfigKey& key, const int64_t& id, const HashableDimensionKey& eventKey,
                    sp<ConditionWizard> wizard, int conditionIndex, bool nesting,
                    sp<ConditionWizard> wizard, int conditionIndex, bool nesting,
                    uint64_t currentBucketStartNs, uint64_t bucketSizeNs,
                    uint64_t currentBucketStartNs, uint64_t bucketSizeNs, bool conditionSliced,
                    const std::vector<sp<DurationAnomalyTracker>>& anomalyTrackers)
                    const std::vector<sp<DurationAnomalyTracker>>& anomalyTrackers)
        : mConfigKey(key),
        : mConfigKey(key),
          mTrackerId(id),
          mTrackerId(id),
@@ -74,6 +74,7 @@ public:
          mCurrentBucketStartTimeNs(currentBucketStartNs),
          mCurrentBucketStartTimeNs(currentBucketStartNs),
          mDuration(0),
          mDuration(0),
          mCurrentBucketNum(0),
          mCurrentBucketNum(0),
          mConditionSliced(conditionSliced),
          mAnomalyTrackers(anomalyTrackers){};
          mAnomalyTrackers(anomalyTrackers){};


    virtual ~DurationTracker(){};
    virtual ~DurationTracker(){};
@@ -163,6 +164,8 @@ protected:


    uint64_t mCurrentBucketNum;
    uint64_t mCurrentBucketNum;


    const bool mConditionSliced;

    std::vector<sp<DurationAnomalyTracker>> mAnomalyTrackers;
    std::vector<sp<DurationAnomalyTracker>> mAnomalyTrackers;


    FRIEND_TEST(OringDurationTrackerTest, TestPredictAnomalyTimestamp);
    FRIEND_TEST(OringDurationTrackerTest, TestPredictAnomalyTimestamp);
+5 −2
Original line number Original line Diff line number Diff line
@@ -28,9 +28,10 @@ MaxDurationTracker::MaxDurationTracker(const ConfigKey& key, const int64_t& id,
                                       const HashableDimensionKey& eventKey,
                                       const HashableDimensionKey& eventKey,
                                       sp<ConditionWizard> wizard, int conditionIndex, bool nesting,
                                       sp<ConditionWizard> wizard, int conditionIndex, bool nesting,
                                       uint64_t currentBucketStartNs, uint64_t bucketSizeNs,
                                       uint64_t currentBucketStartNs, uint64_t bucketSizeNs,
                                       bool conditionSliced,
                                       const vector<sp<DurationAnomalyTracker>>& anomalyTrackers)
                                       const vector<sp<DurationAnomalyTracker>>& anomalyTrackers)
    : DurationTracker(key, id, eventKey, wizard, conditionIndex, nesting, currentBucketStartNs,
    : DurationTracker(key, id, eventKey, wizard, conditionIndex, nesting, currentBucketStartNs,
                      bucketSizeNs, anomalyTrackers) {
                      bucketSizeNs, conditionSliced, anomalyTrackers) {
}
}


bool MaxDurationTracker::hitGuardRail(const HashableDimensionKey& newKey) {
bool MaxDurationTracker::hitGuardRail(const HashableDimensionKey& newKey) {
@@ -63,7 +64,9 @@ void MaxDurationTracker::noteStart(const HashableDimensionKey& key, bool conditi
    }
    }


    DurationInfo& duration = mInfos[key];
    DurationInfo& duration = mInfos[key];
    if (mConditionSliced) {
        duration.conditionKeys = conditionKey;
        duration.conditionKeys = conditionKey;
    }
    VLOG("MaxDuration: key %s start condition %d", key.c_str(), condition);
    VLOG("MaxDuration: key %s start condition %d", key.c_str(), condition);


    switch (duration.state) {
    switch (duration.state) {
+1 −1
Original line number Original line Diff line number Diff line
@@ -31,7 +31,7 @@ public:
    MaxDurationTracker(const ConfigKey& key, const int64_t& id,
    MaxDurationTracker(const ConfigKey& key, const int64_t& id,
                       const HashableDimensionKey& eventKey, sp<ConditionWizard> wizard,
                       const HashableDimensionKey& eventKey, sp<ConditionWizard> wizard,
                       int conditionIndex, bool nesting, uint64_t currentBucketStartNs,
                       int conditionIndex, bool nesting, uint64_t currentBucketStartNs,
                       uint64_t bucketSizeNs,
                       uint64_t bucketSizeNs, bool conditionSliced,
                       const std::vector<sp<DurationAnomalyTracker>>& anomalyTrackers);
                       const std::vector<sp<DurationAnomalyTracker>>& anomalyTrackers);
    void noteStart(const HashableDimensionKey& key, bool condition, const uint64_t eventTime,
    void noteStart(const HashableDimensionKey& key, bool condition, const uint64_t eventTime,
                   const ConditionKey& conditionKey) override;
                   const ConditionKey& conditionKey) override;
+4 −4
Original line number Original line Diff line number Diff line
@@ -27,10 +27,10 @@ using std::pair;
OringDurationTracker::OringDurationTracker(
OringDurationTracker::OringDurationTracker(
        const ConfigKey& key, const int64_t& id, const HashableDimensionKey& eventKey,
        const ConfigKey& key, const int64_t& id, const HashableDimensionKey& eventKey,
        sp<ConditionWizard> wizard, int conditionIndex, bool nesting, uint64_t currentBucketStartNs,
        sp<ConditionWizard> wizard, int conditionIndex, bool nesting, uint64_t currentBucketStartNs,
        uint64_t bucketSizeNs, const vector<sp<DurationAnomalyTracker>>& anomalyTrackers)
        uint64_t bucketSizeNs, bool conditionSliced,

        const vector<sp<DurationAnomalyTracker>>& anomalyTrackers)
    : DurationTracker(key, id, eventKey, wizard, conditionIndex, nesting, currentBucketStartNs,
    : DurationTracker(key, id, eventKey, wizard, conditionIndex, nesting, currentBucketStartNs,
                      bucketSizeNs, anomalyTrackers),
                      bucketSizeNs, conditionSliced, anomalyTrackers),
      mStarted(),
      mStarted(),
      mPaused() {
      mPaused() {
    mLastStartTime = 0;
    mLastStartTime = 0;
@@ -73,7 +73,7 @@ void OringDurationTracker::noteStart(const HashableDimensionKey& key, bool condi
        mPaused[key]++;
        mPaused[key]++;
    }
    }


    if (mConditionKeyMap.find(key) == mConditionKeyMap.end()) {
    if (mConditionSliced && mConditionKeyMap.find(key) == mConditionKeyMap.end()) {
        mConditionKeyMap[key] = conditionKey;
        mConditionKeyMap[key] = conditionKey;
    }
    }


Loading