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

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

Merge "Fix the fake statsd config. Better error messages."

parents 181704c9 7c8f0a52
Loading
Loading
Loading
Loading
+16 −14
Original line number Diff line number Diff line
@@ -232,7 +232,7 @@ void ConfigManager::update_saved_configs(const ConfigKey& key, const StatsdConfi
static StatsdConfig build_fake_config() {
    // HACK: Hard code a test metric for counting screen on events...
    StatsdConfig config;
    config.set_name("12345");
    config.set_name("CONFIG_12345");

    int WAKE_LOCK_TAG_ID = 1111;  // put a fake id here to make testing easier.
    int WAKE_LOCK_UID_KEY_ID = 1;
@@ -263,20 +263,21 @@ static StatsdConfig build_fake_config() {

    // Count Screen ON events.
    CountMetric* metric = config.add_count_metric();
    metric->set_name("1");
    metric->set_name("METRIC_1");
    metric->set_what("SCREEN_TURNED_ON");
    metric->mutable_bucket()->set_bucket_size_millis(30 * 1000L);

    // Anomaly threshold for screen-on count.
    Alert* alert = config.add_alert();
    alert->set_name("1");
    alert->set_name("ALERT_1");
    alert->set_metric_name("METRIC_1");
    alert->set_number_of_buckets(6);
    alert->set_trigger_if_sum_gt(10);
    alert->set_refractory_period_secs(30);

    // Count process state changes, slice by uid.
    metric = config.add_count_metric();
    metric->set_name("2");
    metric->set_name("METRIC_2");
    metric->set_what("PROCESS_STATE_CHANGE");
    metric->mutable_bucket()->set_bucket_size_millis(30 * 1000L);
    KeyMatcher* keyMatcher = metric->add_dimension();
@@ -284,14 +285,15 @@ static StatsdConfig build_fake_config() {

    // Anomaly threshold for background count.
    alert = config.add_alert();
    alert->set_name("2");
    alert->set_name("ALERT_2");
    alert->set_metric_name("METRIC_2");
    alert->set_number_of_buckets(4);
    alert->set_trigger_if_sum_gt(30);
    alert->set_refractory_period_secs(20);

    // Count process state changes, slice by uid, while SCREEN_IS_OFF
    metric = config.add_count_metric();
    metric->set_name("3");
    metric->set_name("METRIC_3");
    metric->set_what("PROCESS_STATE_CHANGE");
    metric->mutable_bucket()->set_bucket_size_millis(30 * 1000L);
    keyMatcher = metric->add_dimension();
@@ -300,7 +302,7 @@ static StatsdConfig build_fake_config() {

    // Count wake lock, slice by uid, while SCREEN_IS_ON and app in background
    metric = config.add_count_metric();
    metric->set_name("4");
    metric->set_name("METRIC_4");
    metric->set_what("APP_GET_WL");
    metric->mutable_bucket()->set_bucket_size_millis(30 * 1000L);
    keyMatcher = metric->add_dimension();
@@ -313,7 +315,7 @@ static StatsdConfig build_fake_config() {

    // Duration of an app holding any wl, while screen on and app in background, slice by uid
    DurationMetric* durationMetric = config.add_duration_metric();
    durationMetric->set_name("5");
    durationMetric->set_name("METRIC_5");
    durationMetric->mutable_bucket()->set_bucket_size_millis(30 * 1000L);
    durationMetric->set_aggregation_type(DurationMetric_AggregationType_SUM);
    keyMatcher = durationMetric->add_dimension();
@@ -327,7 +329,7 @@ static StatsdConfig build_fake_config() {

    // max Duration of an app holding any wl, while screen on and app in background, slice by uid
    durationMetric = config.add_duration_metric();
    durationMetric->set_name("6");
    durationMetric->set_name("METRIC_6");
    durationMetric->mutable_bucket()->set_bucket_size_millis(30 * 1000L);
    durationMetric->set_aggregation_type(DurationMetric_AggregationType_MAX_SPARSE);
    keyMatcher = durationMetric->add_dimension();
@@ -341,7 +343,7 @@ static StatsdConfig build_fake_config() {

    // Duration of an app holding any wl, while screen on and app in background
    durationMetric = config.add_duration_metric();
    durationMetric->set_name("7");
    durationMetric->set_name("METRIC_7");
    durationMetric->mutable_bucket()->set_bucket_size_millis(30 * 1000L);
    durationMetric->set_aggregation_type(DurationMetric_AggregationType_MAX_SPARSE);
    durationMetric->set_what("WL_HELD_PER_APP_PER_NAME");
@@ -353,14 +355,14 @@ static StatsdConfig build_fake_config() {

    // Duration of screen on time.
    durationMetric = config.add_duration_metric();
    durationMetric->set_name("8");
    durationMetric->set_name("METRIC_8");
    durationMetric->mutable_bucket()->set_bucket_size_millis(10 * 1000L);
    durationMetric->set_aggregation_type(DurationMetric_AggregationType_SUM);
    durationMetric->set_what("SCREEN_IS_ON");

    // Value metric to count KERNEL_WAKELOCK when screen turned on
    ValueMetric* valueMetric = config.add_value_metric();
    valueMetric->set_name("6");
    valueMetric->set_name("METRIC_6");
    valueMetric->set_what("KERNEL_WAKELOCK");
    valueMetric->set_value_field(1);
    valueMetric->set_condition("SCREEN_IS_ON");
@@ -371,12 +373,12 @@ static StatsdConfig build_fake_config() {

    // Add an EventMetric to log process state change events.
    EventMetric* eventMetric = config.add_event_metric();
    eventMetric->set_name("9");
    eventMetric->set_name("METRIC_9");
    eventMetric->set_what("SCREEN_TURNED_ON");

    // Add an GaugeMetric.
    GaugeMetric* gaugeMetric = config.add_gauge_metric();
    gaugeMetric->set_name("10");
    gaugeMetric->set_name("METRIC_10");
    gaugeMetric->set_what("DEVICE_TEMPERATURE");
    gaugeMetric->set_gauge_field(DEVICE_TEMPERATURE_KEY);
    gaugeMetric->mutable_bucket()->set_bucket_size_millis(60 * 1000L);
+11 −11
Original line number Diff line number Diff line
@@ -43,12 +43,12 @@ bool handleMetricWithLogTrackers(const string what, const int metricIndex,
                                 int& logTrackerIndex) {
    auto logTrackerIt = logTrackerMap.find(what);
    if (logTrackerIt == logTrackerMap.end()) {
        ALOGW("cannot find the LogEntryMatcher %s in config", what.c_str());
        ALOGW("cannot find the LogEntryMatcher \"%s\" in config", what.c_str());
        return false;
    }
    if (usedForDimension && allLogEntryMatchers[logTrackerIt->second]->getTagIds().size() > 1) {
        ALOGE("LogEntryMatcher %s has more than one tag ids. When a metric has dimension, the "
              "\"what\" can only about one atom type.",
        ALOGE("LogEntryMatcher \"%s\" has more than one tag ids. When a metric has dimension, "
              "the \"what\" can only about one atom type.",
              what.c_str());
        return false;
    }
@@ -67,14 +67,14 @@ bool handleMetricWithConditions(
        unordered_map<int, std::vector<int>>& conditionToMetricMap) {
    auto condition_it = conditionTrackerMap.find(condition);
    if (condition_it == conditionTrackerMap.end()) {
        ALOGW("cannot find the Condition %s in the config", condition.c_str());
        ALOGW("cannot find Condition \"%s\" in the config", condition.c_str());
        return false;
    }

    for (const auto& link : links) {
        auto it = conditionTrackerMap.find(link.condition());
        if (it == conditionTrackerMap.end()) {
            ALOGW("cannot find the Condition %s in the config", link.condition().c_str());
            ALOGW("cannot find Condition \"%s\" in the config", link.condition().c_str());
            return false;
        }
        allConditionTrackers[condition_it->second]->setSliced(true);
@@ -110,7 +110,7 @@ bool initLogTrackers(const StatsdConfig& config, unordered_map<string, int>& log
                        new CombinationLogMatchingTracker(logMatcher.name(), index));
                break;
            default:
                ALOGE("Matcher %s malformed", logMatcher.name().c_str());
                ALOGE("Matcher \"%s\" malformed", logMatcher.name().c_str());
                return false;
                // continue;
        }
@@ -158,7 +158,7 @@ bool initConditions(const StatsdConfig& config, const unordered_map<string, int>
                break;
            }
            default:
                ALOGE("Condition %s malformed", condition.name().c_str());
                ALOGE("Condition \"%s\" malformed", condition.name().c_str());
                return false;
        }
        if (conditionTrackerMap.find(condition.name()) != conditionTrackerMap.end()) {
@@ -204,7 +204,7 @@ bool initMetrics(const StatsdConfig& config, const unordered_map<string, int>& l
    for (int i = 0; i < config.count_metric_size(); i++) {
        const CountMetric& metric = config.count_metric(i);
        if (!metric.has_what()) {
            ALOGW("cannot find what in CountMetric %s", metric.name().c_str());
            ALOGW("cannot find \"what\" in CountMetric \"%s\"", metric.name().c_str());
            return false;
        }

@@ -341,7 +341,7 @@ bool initMetrics(const StatsdConfig& config, const unordered_map<string, int>& l
    for (int i = 0; i < config.value_metric_size(); i++) {
        const ValueMetric& metric = config.value_metric(i);
        if (!metric.has_what()) {
            ALOGW("cannot find what in ValueMetric %s", metric.name().c_str());
            ALOGW("cannot find \"what\" in ValueMetric \"%s\"", metric.name().c_str());
            return false;
        }

@@ -387,7 +387,7 @@ bool initMetrics(const StatsdConfig& config, const unordered_map<string, int>& l
    for (int i = 0; i < config.gauge_metric_size(); i++) {
        const GaugeMetric& metric = config.gauge_metric(i);
        if (!metric.has_what()) {
            ALOGW("cannot find what in ValueMetric %s", metric.name().c_str());
            ALOGW("cannot find \"what\" in ValueMetric \"%s\"", metric.name().c_str());
            return false;
        }

@@ -438,7 +438,7 @@ bool initAlerts(const StatsdConfig& config, const unordered_map<string, int>& me
        const Alert& alert = config.alert(i);
        const auto& itr = metricProducerMap.find(alert.metric_name());
        if (itr == metricProducerMap.end()) {
            ALOGW("alert has unknown metric name: %s %s", alert.name().c_str(),
            ALOGW("alert \"%s\" has unknown metric name: \"%s\"", alert.name().c_str(),
                  alert.metric_name().c_str());
            return false;
        }