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

Commit a7fb12d2 authored by Yangster-mac's avatar Yangster-mac
Browse files

1/ Use FieldMatcher to specify the value fields in value metric.

2/ rename number_of_buckets as num_buckets
3/ use double for the Alert's threshold

Test: statsd unit tests passed.
Change-Id: Id1f55f14d3712eddee561681e3cd77343f086c7a
parent 478b6caa
Loading
Loading
Loading
Loading
+3 −3
Original line number Original line Diff line number Diff line
@@ -34,11 +34,11 @@ namespace statsd {
AnomalyTracker::AnomalyTracker(const Alert& alert, const ConfigKey& configKey)
AnomalyTracker::AnomalyTracker(const Alert& alert, const ConfigKey& configKey)
    : mAlert(alert),
    : mAlert(alert),
      mConfigKey(configKey),
      mConfigKey(configKey),
      mNumOfPastBuckets(mAlert.number_of_buckets() - 1) {
      mNumOfPastBuckets(mAlert.num_buckets() - 1) {
    VLOG("AnomalyTracker() called");
    VLOG("AnomalyTracker() called");
    if (mAlert.number_of_buckets() <= 0) {
    if (mAlert.num_buckets() <= 0) {
        ALOGE("Cannot create AnomalyTracker with %lld buckets",
        ALOGE("Cannot create AnomalyTracker with %lld buckets",
              (long long)mAlert.number_of_buckets());
              (long long)mAlert.num_buckets());
        return;
        return;
    }
    }
    if (!mAlert.has_trigger_if_sum_gt()) {
    if (!mAlert.has_trigger_if_sum_gt()) {
+2 −1
Original line number Original line Diff line number Diff line
@@ -377,7 +377,8 @@ StatsdConfig build_fake_config() {
    ValueMetric* valueMetric = config.add_value_metric();
    ValueMetric* valueMetric = config.add_value_metric();
    valueMetric->set_id(11);
    valueMetric->set_id(11);
    valueMetric->set_what(109);
    valueMetric->set_what(109);
    valueMetric->set_value_field(KERNEL_WAKELOCK_COUNT_KEY);
    valueMetric->mutable_value_field()->set_field(KERNEL_WAKELOCK_TAG_ID);
    valueMetric->mutable_value_field()->add_child()->set_field(KERNEL_WAKELOCK_COUNT_KEY);
    valueMetric->set_condition(201);
    valueMetric->set_condition(201);
    dimensions = valueMetric->mutable_dimensions();
    dimensions = valueMetric->mutable_dimensions();
    dimensions->set_field(KERNEL_WAKELOCK_TAG_ID);
    dimensions->set_field(KERNEL_WAKELOCK_TAG_ID);
+17 −0
Original line number Original line Diff line number Diff line
@@ -351,6 +351,23 @@ bool IsSubDimension(const DimensionsValue& dimension, const DimensionsValue& sub
    }
    }
}
}


long getLongFromDimenValue(const DimensionsValue& dimensionValue) {
    switch (dimensionValue.value_case()) {
        case DimensionsValue::ValueCase::kValueInt:
            return dimensionValue.value_int();
        case DimensionsValue::ValueCase::kValueLong:
            return dimensionValue.value_long();
        case DimensionsValue::ValueCase::kValueBool:
            return dimensionValue.value_bool() ? 1 : 0;
        case DimensionsValue::ValueCase::kValueFloat:
            return (int64_t)dimensionValue.value_float();
        case DimensionsValue::ValueCase::kValueTuple:
        case DimensionsValue::ValueCase::kValueStr:
        case DimensionsValue::ValueCase::VALUE_NOT_SET:
            return 0;
    }
}

}  // namespace statsd
}  // namespace statsd
}  // namespace os
}  // namespace os
}  // namespace android
}  // namespace android
+2 −0
Original line number Original line Diff line number Diff line
@@ -56,6 +56,8 @@ void DimensionsValueToString(const DimensionsValue& value, std::string *flattene


bool IsSubDimension(const DimensionsValue& dimension, const DimensionsValue& sub);
bool IsSubDimension(const DimensionsValue& dimension, const DimensionsValue& sub);


// Helper function to get long value from the DimensionsValue proto.
long getLongFromDimenValue(const DimensionsValue& dimensionValue);
}  // namespace statsd
}  // namespace statsd
}  // namespace os
}  // namespace os
}  // namespace android
}  // namespace android
+3 −3
Original line number Original line Diff line number Diff line
@@ -98,9 +98,9 @@ DurationMetricProducer::~DurationMetricProducer() {


sp<AnomalyTracker> DurationMetricProducer::addAnomalyTracker(const Alert &alert) {
sp<AnomalyTracker> DurationMetricProducer::addAnomalyTracker(const Alert &alert) {
    std::lock_guard<std::mutex> lock(mMutex);
    std::lock_guard<std::mutex> lock(mMutex);
    if (alert.trigger_if_sum_gt() > alert.number_of_buckets() * mBucketSizeNs) {
    if (alert.trigger_if_sum_gt() > alert.num_buckets() * mBucketSizeNs) {
        ALOGW("invalid alert: threshold (%lld) > possible recordable value (%d x %lld)",
        ALOGW("invalid alert: threshold (%f) > possible recordable value (%d x %lld)",
              alert.trigger_if_sum_gt(), alert.number_of_buckets(),
              alert.trigger_if_sum_gt(), alert.num_buckets(),
              (long long)mBucketSizeNs);
              (long long)mBucketSizeNs);
        return nullptr;
        return nullptr;
    }
    }
Loading