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

Commit 060fbfc5 authored by Ruchir Rastogi's avatar Ruchir Rastogi
Browse files

Support a ONE_WEEK bucket size

Test: bit statsd_test:*
Test: atest CtsStatsdHostTestCases (no additional tests fail)
Bug: 142512643
Change-Id: I0f6de2e66ffa72f7f762ab5d8ad76d07339692d7
parent 95c3d10f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -106,6 +106,7 @@ private:
    FRIEND_TEST(CountMetricProducerTest, TestEventWithAppUpgrade);
    FRIEND_TEST(CountMetricProducerTest, TestEventWithAppUpgradeInNextBucket);
    FRIEND_TEST(CountMetricProducerTest, TestFirstBucket);
    FRIEND_TEST(CountMetricProducerTest, TestOneWeekTimeUnit);
};

}  // namespace statsd
+2 −0
Original line number Diff line number Diff line
@@ -445,6 +445,8 @@ int64_t TimeUnitToBucketSizeInMillis(TimeUnit unit) {
            return 12 * 60 * 60 * 1000LL;
        case ONE_DAY:
            return 24 * 60 * 60 * 1000LL;
        case ONE_WEEK:
            return 7 * 24 * 60 * 60 * 1000LL;
        case CTS:
            return 1000;
        case TIME_UNIT_UNSPECIFIED:
+1 −0
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ enum TimeUnit {
  SIX_HOURS = 7;
  TWELVE_HOURS = 8;
  ONE_DAY = 9;
  ONE_WEEK = 10;
  CTS = 1000;
}

+20 −0
Original line number Diff line number Diff line
@@ -396,6 +396,26 @@ TEST(CountMetricProducerTest, TestAnomalyDetectionUnSliced) {
            std::ceil(1.0 * event7.GetElapsedTimestampNs() / NS_PER_SEC + refPeriodSec));
}

TEST(CountMetricProducerTest, TestOneWeekTimeUnit) {
    CountMetric metric;
    metric.set_id(1);
    metric.set_bucket(ONE_WEEK);

    sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();

    int64_t oneDayNs = 24 * 60 * 60 * 1e9;
    int64_t fiveWeeksNs = 5 * 7 * oneDayNs;

    CountMetricProducer countProducer(
            kConfigKey, metric, -1 /* meaning no condition */, wizard, oneDayNs, fiveWeeksNs);

    int64_t fiveWeeksOneDayNs = fiveWeeksNs + oneDayNs;

    EXPECT_EQ(fiveWeeksNs, countProducer.mCurrentBucketStartTimeNs);
    EXPECT_EQ(4, countProducer.mCurrentBucketNum);
    EXPECT_EQ(fiveWeeksOneDayNs, countProducer.getCurrentBucketEndTimeNs());
}

}  // namespace statsd
}  // namespace os
}  // namespace android