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

Commit 12d01fa7 authored by Stefan Lafon's avatar Stefan Lafon
Browse files

Rename more things in statsd_config.proto.

SimpleCondition -> SimplePredicate
simple_condition -> simple_predicate
Condition -> Predicate
condition -> predicate

Test: Ran statsd and statsd_test.

Change-Id: I3115fb51a4dc3cbe5f23535dfc448d5755b9ed7f
parent a2d0fc00
Loading
Loading
Loading
Loading
+7 −7
Original line number Original line Diff line number Diff line
@@ -39,11 +39,11 @@ CombinationConditionTracker::~CombinationConditionTracker() {
    VLOG("~CombinationConditionTracker() %s", mName.c_str());
    VLOG("~CombinationConditionTracker() %s", mName.c_str());
}
}


bool CombinationConditionTracker::init(const vector<Condition>& allConditionConfig,
bool CombinationConditionTracker::init(const vector<Predicate>& allConditionConfig,
                                       const vector<sp<ConditionTracker>>& allConditionTrackers,
                                       const vector<sp<ConditionTracker>>& allConditionTrackers,
                                       const unordered_map<string, int>& conditionNameIndexMap,
                                       const unordered_map<string, int>& conditionNameIndexMap,
                                       vector<bool>& stack) {
                                       vector<bool>& stack) {
    VLOG("Combiniation condition init() %s", mName.c_str());
    VLOG("Combination predicate init() %s", mName.c_str());
    if (mInitialized) {
    if (mInitialized) {
        return true;
        return true;
    }
    }
@@ -51,22 +51,22 @@ bool CombinationConditionTracker::init(const vector<Condition>& allConditionConf
    // mark this node as visited in the recursion stack.
    // mark this node as visited in the recursion stack.
    stack[mIndex] = true;
    stack[mIndex] = true;


    Condition_Combination combinationCondition = allConditionConfig[mIndex].combination();
    Predicate_Combination combinationCondition = allConditionConfig[mIndex].combination();


    if (!combinationCondition.has_operation()) {
    if (!combinationCondition.has_operation()) {
        return false;
        return false;
    }
    }
    mLogicalOperation = combinationCondition.operation();
    mLogicalOperation = combinationCondition.operation();


    if (mLogicalOperation == LogicalOperation::NOT && combinationCondition.condition_size() != 1) {
    if (mLogicalOperation == LogicalOperation::NOT && combinationCondition.predicate_size() != 1) {
        return false;
        return false;
    }
    }


    for (string child : combinationCondition.condition()) {
    for (string child : combinationCondition.predicate()) {
        auto it = conditionNameIndexMap.find(child);
        auto it = conditionNameIndexMap.find(child);


        if (it == conditionNameIndexMap.end()) {
        if (it == conditionNameIndexMap.end()) {
            ALOGW("Condition %s not found in the config", child.c_str());
            ALOGW("Predicate %s not found in the config", child.c_str());
            return false;
            return false;
        }
        }


@@ -154,7 +154,7 @@ void CombinationConditionTracker::evaluateCondition(
            }
            }
        }
        }
        nonSlicedConditionCache[mIndex] = ConditionState::kUnknown;
        nonSlicedConditionCache[mIndex] = ConditionState::kUnknown;
        ALOGD("CombinationCondition %s sliced may changed? %d", mName.c_str(),
        ALOGD("CombinationPredicate %s sliced may changed? %d", mName.c_str(),
              conditionChangedCache[mIndex] == true);
              conditionChangedCache[mIndex] == true);
    }
    }
}
}
+2 −2
Original line number Original line Diff line number Diff line
@@ -30,7 +30,7 @@ public:


    ~CombinationConditionTracker();
    ~CombinationConditionTracker();


    bool init(const std::vector<Condition>& allConditionConfig,
    bool init(const std::vector<Predicate>& allConditionConfig,
              const std::vector<sp<ConditionTracker>>& allConditionTrackers,
              const std::vector<sp<ConditionTracker>>& allConditionTrackers,
              const std::unordered_map<std::string, int>& conditionNameIndexMap,
              const std::unordered_map<std::string, int>& conditionNameIndexMap,
              std::vector<bool>& stack) override;
              std::vector<bool>& stack) override;
@@ -47,7 +47,7 @@ public:


private:
private:
    LogicalOperation mLogicalOperation;
    LogicalOperation mLogicalOperation;
    // Store index of the children Conditions.
    // Store index of the children Predicates.
    // We don't store string name of the Children, because we want to get rid of the hash map to
    // We don't store string name of the Children, because we want to get rid of the hash map to
    // map the name to object. We don't want to store smart pointers to children, because it
    // map the name to object. We don't want to store smart pointers to children, because it
    // increases the risk of circular dependency and memory leak.
    // increases the risk of circular dependency and memory leak.
+2 −3
Original line number Original line Diff line number Diff line
@@ -45,12 +45,12 @@ public:
    // Initialize this ConditionTracker. This initialization is done recursively (DFS). It can also
    // Initialize this ConditionTracker. This initialization is done recursively (DFS). It can also
    // be done in the constructor, but we do it separately because (1) easy to return a bool to
    // be done in the constructor, but we do it separately because (1) easy to return a bool to
    // indicate whether the initialization is successful. (2) makes unit test easier.
    // indicate whether the initialization is successful. (2) makes unit test easier.
    // allConditionConfig: the list of all Condition config from statsd_config.
    // allConditionConfig: the list of all Predicate config from statsd_config.
    // allConditionTrackers: the list of all ConditionTrackers (this is needed because we may also
    // allConditionTrackers: the list of all ConditionTrackers (this is needed because we may also
    //                       need to call init() on children conditions)
    //                       need to call init() on children conditions)
    // conditionNameIndexMap: the mapping from condition name to its index.
    // conditionNameIndexMap: the mapping from condition name to its index.
    // stack: a bit map to keep track which nodes have been visited on the stack in the recursion.
    // stack: a bit map to keep track which nodes have been visited on the stack in the recursion.
    virtual bool init(const std::vector<Condition>& allConditionConfig,
    virtual bool init(const std::vector<Predicate>& allConditionConfig,
                      const std::vector<sp<ConditionTracker>>& allConditionTrackers,
                      const std::vector<sp<ConditionTracker>>& allConditionTrackers,
                      const std::unordered_map<std::string, int>& conditionNameIndexMap,
                      const std::unordered_map<std::string, int>& conditionNameIndexMap,
                      std::vector<bool>& stack) = 0;
                      std::vector<bool>& stack) = 0;
@@ -118,4 +118,3 @@ protected:
}  // namespace statsd
}  // namespace statsd
}  // namespace os
}  // namespace os
}  // namespace android
}  // namespace android
+20 −20
Original line number Original line Diff line number Diff line
@@ -34,16 +34,16 @@ using std::vector;


SimpleConditionTracker::SimpleConditionTracker(
SimpleConditionTracker::SimpleConditionTracker(
        const ConfigKey& key, const string& name, const int index,
        const ConfigKey& key, const string& name, const int index,
        const SimpleCondition& simpleCondition,
        const SimplePredicate& simplePredicate,
        const unordered_map<string, int>& trackerNameIndexMap)
        const unordered_map<string, int>& trackerNameIndexMap)
    : ConditionTracker(name, index), mConfigKey(key) {
    : ConditionTracker(name, index), mConfigKey(key) {
    VLOG("creating SimpleConditionTracker %s", mName.c_str());
    VLOG("creating SimpleConditionTracker %s", mName.c_str());
    mCountNesting = simpleCondition.count_nesting();
    mCountNesting = simplePredicate.count_nesting();


    if (simpleCondition.has_start()) {
    if (simplePredicate.has_start()) {
        auto pair = trackerNameIndexMap.find(simpleCondition.start());
        auto pair = trackerNameIndexMap.find(simplePredicate.start());
        if (pair == trackerNameIndexMap.end()) {
        if (pair == trackerNameIndexMap.end()) {
            ALOGW("Start matcher %s not found in the config", simpleCondition.start().c_str());
            ALOGW("Start matcher %s not found in the config", simplePredicate.start().c_str());
            return;
            return;
        }
        }
        mStartLogMatcherIndex = pair->second;
        mStartLogMatcherIndex = pair->second;
@@ -52,10 +52,10 @@ SimpleConditionTracker::SimpleConditionTracker(
        mStartLogMatcherIndex = -1;
        mStartLogMatcherIndex = -1;
    }
    }


    if (simpleCondition.has_stop()) {
    if (simplePredicate.has_stop()) {
        auto pair = trackerNameIndexMap.find(simpleCondition.stop());
        auto pair = trackerNameIndexMap.find(simplePredicate.stop());
        if (pair == trackerNameIndexMap.end()) {
        if (pair == trackerNameIndexMap.end()) {
            ALOGW("Stop matcher %s not found in the config", simpleCondition.stop().c_str());
            ALOGW("Stop matcher %s not found in the config", simplePredicate.stop().c_str());
            return;
            return;
        }
        }
        mStopLogMatcherIndex = pair->second;
        mStopLogMatcherIndex = pair->second;
@@ -64,10 +64,10 @@ SimpleConditionTracker::SimpleConditionTracker(
        mStopLogMatcherIndex = -1;
        mStopLogMatcherIndex = -1;
    }
    }


    if (simpleCondition.has_stop_all()) {
    if (simplePredicate.has_stop_all()) {
        auto pair = trackerNameIndexMap.find(simpleCondition.stop_all());
        auto pair = trackerNameIndexMap.find(simplePredicate.stop_all());
        if (pair == trackerNameIndexMap.end()) {
        if (pair == trackerNameIndexMap.end()) {
            ALOGW("Stop all matcher %s not found in the config", simpleCondition.stop().c_str());
            ALOGW("Stop all matcher %s not found in the config", simplePredicate.stop().c_str());
            return;
            return;
        }
        }
        mStopAllLogMatcherIndex = pair->second;
        mStopAllLogMatcherIndex = pair->second;
@@ -76,14 +76,14 @@ SimpleConditionTracker::SimpleConditionTracker(
        mStopAllLogMatcherIndex = -1;
        mStopAllLogMatcherIndex = -1;
    }
    }


    mOutputDimension.insert(mOutputDimension.begin(), simpleCondition.dimension().begin(),
    mOutputDimension.insert(mOutputDimension.begin(), simplePredicate.dimension().begin(),
                            simpleCondition.dimension().end());
                            simplePredicate.dimension().end());


    if (mOutputDimension.size() > 0) {
    if (mOutputDimension.size() > 0) {
        mSliced = true;
        mSliced = true;
    }
    }


    if (simpleCondition.initial_value() == SimpleCondition_InitialValue_FALSE) {
    if (simplePredicate.initial_value() == SimplePredicate_InitialValue_FALSE) {
        mInitialValue = ConditionState::kFalse;
        mInitialValue = ConditionState::kFalse;
    } else {
    } else {
        mInitialValue = ConditionState::kUnknown;
        mInitialValue = ConditionState::kUnknown;
@@ -98,7 +98,7 @@ SimpleConditionTracker::~SimpleConditionTracker() {
    VLOG("~SimpleConditionTracker()");
    VLOG("~SimpleConditionTracker()");
}
}


bool SimpleConditionTracker::init(const vector<Condition>& allConditionConfig,
bool SimpleConditionTracker::init(const vector<Predicate>& allConditionConfig,
                                  const vector<sp<ConditionTracker>>& allConditionTrackers,
                                  const vector<sp<ConditionTracker>>& allConditionTrackers,
                                  const unordered_map<string, int>& conditionNameIndexMap,
                                  const unordered_map<string, int>& conditionNameIndexMap,
                                  vector<bool>& stack) {
                                  vector<bool>& stack) {
@@ -139,7 +139,7 @@ bool SimpleConditionTracker::hitGuardRail(const HashableDimensionKey& newKey) {
        StatsdStats::getInstance().noteConditionDimensionSize(mConfigKey, mName, newTupleCount);
        StatsdStats::getInstance().noteConditionDimensionSize(mConfigKey, mName, newTupleCount);
        // 2. Don't add more tuples, we are above the allowed threshold. Drop the data.
        // 2. Don't add more tuples, we are above the allowed threshold. Drop the data.
        if (newTupleCount > StatsdStats::kDimensionKeySizeHardLimit) {
        if (newTupleCount > StatsdStats::kDimensionKeySizeHardLimit) {
            ALOGE("Condition %s dropping data for dimension key %s", mName.c_str(), newKey.c_str());
            ALOGE("Predicate %s dropping data for dimension key %s", mName.c_str(), newKey.c_str());
            return true;
            return true;
        }
        }
    }
    }
@@ -221,7 +221,7 @@ void SimpleConditionTracker::handleConditionEvent(const HashableDimensionKey& ou
    conditionChangedCache[mIndex] = changed;
    conditionChangedCache[mIndex] = changed;
    conditionCache[mIndex] = newCondition;
    conditionCache[mIndex] = newCondition;


    VLOG("SimpleCondition %s nonSlicedChange? %d", mName.c_str(),
    VLOG("SimplePredicate %s nonSlicedChange? %d", mName.c_str(),
         conditionChangedCache[mIndex] == true);
         conditionChangedCache[mIndex] == true);
}
}


@@ -292,13 +292,13 @@ void SimpleConditionTracker::isConditionMet(
            (pair == conditionParameters.end()) ? DEFAULT_DIMENSION_KEY : pair->second;
            (pair == conditionParameters.end()) ? DEFAULT_DIMENSION_KEY : pair->second;


    if (pair == conditionParameters.end() && mOutputDimension.size() > 0) {
    if (pair == conditionParameters.end() && mOutputDimension.size() > 0) {
        ALOGE("Condition %s output has dimension, but it's not specified in the query!",
        ALOGE("Predicate %s output has dimension, but it's not specified in the query!",
              mName.c_str());
              mName.c_str());
        conditionCache[mIndex] = mInitialValue;
        conditionCache[mIndex] = mInitialValue;
        return;
        return;
    }
    }


    VLOG("simpleCondition %s query key: %s", mName.c_str(), key.c_str());
    VLOG("simplePredicate %s query key: %s", mName.c_str(), key.c_str());


    auto startedCountIt = mSlicedConditionState.find(key);
    auto startedCountIt = mSlicedConditionState.find(key);
    if (startedCountIt == mSlicedConditionState.end()) {
    if (startedCountIt == mSlicedConditionState.end()) {
@@ -308,7 +308,7 @@ void SimpleConditionTracker::isConditionMet(
                startedCountIt->second > 0 ? ConditionState::kTrue : ConditionState::kFalse;
                startedCountIt->second > 0 ? ConditionState::kTrue : ConditionState::kFalse;
    }
    }


    VLOG("Condition %s return %d", mName.c_str(), conditionCache[mIndex]);
    VLOG("Predicate %s return %d", mName.c_str(), conditionCache[mIndex]);
}
}


}  // namespace statsd
}  // namespace statsd
+2 −2
Original line number Original line Diff line number Diff line
@@ -30,12 +30,12 @@ namespace statsd {
class SimpleConditionTracker : public virtual ConditionTracker {
class SimpleConditionTracker : public virtual ConditionTracker {
public:
public:
    SimpleConditionTracker(const ConfigKey& key, const std::string& name, const int index,
    SimpleConditionTracker(const ConfigKey& key, const std::string& name, const int index,
                           const SimpleCondition& simpleCondition,
                           const SimplePredicate& simplePredicate,
                           const std::unordered_map<std::string, int>& trackerNameIndexMap);
                           const std::unordered_map<std::string, int>& trackerNameIndexMap);


    ~SimpleConditionTracker();
    ~SimpleConditionTracker();


    bool init(const std::vector<Condition>& allConditionConfig,
    bool init(const std::vector<Predicate>& allConditionConfig,
              const std::vector<sp<ConditionTracker>>& allConditionTrackers,
              const std::vector<sp<ConditionTracker>>& allConditionTrackers,
              const std::unordered_map<std::string, int>& conditionNameIndexMap,
              const std::unordered_map<std::string, int>& conditionNameIndexMap,
              std::vector<bool>& stack) override;
              std::vector<bool>& stack) override;
Loading