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

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

Merge "Update indices of preserved matchers"

parents 432e984e 090ffd79
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -52,6 +52,15 @@ public:
                      const std::unordered_map<int64_t, int>& matcherMap,
                      std::vector<bool>& stack) = 0;

    // Update appropriate state on config updates. Primarily, all indices need to be updated.
    // This matcher and all of its children are guaranteed to be preserved across the update.
    // matcher: the AtomMatcher proto from the config.
    // index: the index of this matcher in mAllAtomMatchingTrackers.
    // atomMatchingTrackerMap: map from matcher id to index in mAllAtomMatchingTrackers
    virtual bool onConfigUpdated(
            const AtomMatcher& matcher, const int index,
            const std::unordered_map<int64_t, int>& atomMatchingTrackerMap) = 0;

    // Called when a log event comes.
    // event: the log event.
    // allAtomMatchingTrackers: the list of all AtomMatchingTrackers. This is needed because the log
@@ -83,7 +92,7 @@ protected:
    const int64_t mId;

    // Index of this AtomMatchingTracker in MetricsManager's container.
    const int mIndex;
    int mIndex;

    // Whether this AtomMatchingTracker has been properly initialized.
    bool mInitialized;
+17 −0
Original line number Diff line number Diff line
@@ -93,6 +93,23 @@ bool CombinationAtomMatchingTracker::init(
    return true;
}

bool CombinationAtomMatchingTracker::onConfigUpdated(
        const AtomMatcher& matcher, const int index,
        const unordered_map<int64_t, int>& atomMatchingTrackerMap) {
    mIndex = index;
    mChildren.clear();
    AtomMatcher_Combination combinationMatcher = matcher.combination();
    for (const int64_t child : combinationMatcher.matcher()) {
        const auto& pair = atomMatchingTrackerMap.find(child);
        if (pair == atomMatchingTrackerMap.end()) {
            ALOGW("Matcher %lld not found in the config", (long long)child);
            return false;
        }
        mChildren.push_back(pair->second);
    }
    return true;
}

void CombinationAtomMatchingTracker::onLogEvent(
        const LogEvent& event, const vector<sp<AtomMatchingTracker>>& allAtomMatchingTrackers,
        vector<MatchingState>& matcherResults) {
+6 −1
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ namespace os {
namespace statsd {

// Represents a AtomMatcher_Combination in the StatsdConfig.
class CombinationAtomMatchingTracker : public virtual AtomMatchingTracker {
class CombinationAtomMatchingTracker : public AtomMatchingTracker {
public:
    CombinationAtomMatchingTracker(const int64_t& id, const int index, const uint64_t protoHash);

@@ -35,6 +35,9 @@ public:
              const std::vector<sp<AtomMatchingTracker>>& allAtomMatchingTrackers,
              const std::unordered_map<int64_t, int>& matcherMap, std::vector<bool>& stack);

    bool onConfigUpdated(const AtomMatcher& matcher, const int index,
                         const std::unordered_map<int64_t, int>& atomMatchingTrackerMap) override;

    ~CombinationAtomMatchingTracker();

    void onLogEvent(const LogEvent& event,
@@ -45,6 +48,8 @@ private:
    LogicalOperation mLogicalOperation;

    std::vector<int> mChildren;

    FRIEND_TEST(ConfigUpdateTest, TestUpdateMatchers);
};

}  // namespace statsd
+8 −0
Original line number Diff line number Diff line
@@ -50,6 +50,14 @@ bool SimpleAtomMatchingTracker::init(const vector<AtomMatcher>& allAtomMatchers,
    return mInitialized;
}

bool SimpleAtomMatchingTracker::onConfigUpdated(
        const AtomMatcher& matcher, const int index,
        const unordered_map<int64_t, int>& atomMatchingTrackerMap) {
    mIndex = index;
    // Do not need to update mMatcher since the matcher must be identical across the update.
    return mInitialized;
}

void SimpleAtomMatchingTracker::onLogEvent(
        const LogEvent& event, const vector<sp<AtomMatchingTracker>>& allAtomMatchingTrackers,
        vector<MatchingState>& matcherResults) {
+4 −1
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@ namespace android {
namespace os {
namespace statsd {

class SimpleAtomMatchingTracker : public virtual AtomMatchingTracker {
class SimpleAtomMatchingTracker : public AtomMatchingTracker {
public:
    SimpleAtomMatchingTracker(const int64_t& id, const int index, const uint64_t protoHash,
                              const SimpleAtomMatcher& matcher, const sp<UidMap>& uidMap);
@@ -40,6 +40,9 @@ public:
              const std::unordered_map<int64_t, int>& matcherMap,
              std::vector<bool>& stack) override;

    bool onConfigUpdated(const AtomMatcher& matcher, const int index,
                         const std::unordered_map<int64_t, int>& atomMatchingTrackerMap) override;

    void onLogEvent(const LogEvent& event,
                    const std::vector<sp<AtomMatchingTracker>>& allAtomMatchingTrackers,
                    std::vector<MatchingState>& matcherResults) override;
Loading