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

Commit 0ba14747 authored by Salud Lemus's avatar Salud Lemus Committed by Android (Google) Code Review
Browse files

Merge "Make LogMatchingTracker, SimpleLogMatchingTracker,...

Merge "Make LogMatchingTracker, SimpleLogMatchingTracker, CombinationLogMatchingTracker, LogTracker, and AtomMatcher naming consistent"
parents 567f3228 f63fa899
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -73,10 +73,10 @@ cc_defaults {
        "src/HashableDimensionKey.cpp",
        "src/logd/LogEvent.cpp",
        "src/logd/LogEventQueue.cpp",
        "src/matchers/CombinationLogMatchingTracker.cpp",
        "src/matchers/CombinationAtomMatchingTracker.cpp",
        "src/matchers/EventMatcherWizard.cpp",
        "src/matchers/matcher_util.cpp",
        "src/matchers/SimpleLogMatchingTracker.cpp",
        "src/matchers/SimpleAtomMatchingTracker.cpp",
        "src/metadata_util.cpp",
        "src/metrics/CountMetricProducer.cpp",
        "src/metrics/duration_helper/MaxDurationTracker.cpp",
+2 −2
Original line number Diff line number Diff line
@@ -92,8 +92,8 @@ bool CombinationConditionTracker::init(const vector<Predicate>& allConditionConf
            mUnSlicedChildren.push_back(childIndex);
        }
        mChildren.push_back(childIndex);
        mTrackerIndex.insert(childTracker->getLogTrackerIndex().begin(),
                             childTracker->getLogTrackerIndex().end());
        mTrackerIndex.insert(childTracker->getAtomMatchingTrackerIndex().begin(),
                             childTracker->getAtomMatchingTrackerIndex().end());
    }

    mUnSlicedPartCondition = evaluateCombinationCondition(mUnSlicedChildren, mLogicalOperation,
+7 −7
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@

#include "condition/condition_util.h"
#include "frameworks/base/cmds/statsd/src/statsd_config.pb.h"
#include "matchers/LogMatchingTracker.h"
#include "matchers/AtomMatchingTracker.h"
#include "matchers/matcher_util.h"

#include <utils/RefBase.h>
@@ -60,9 +60,9 @@ public:

    // evaluate current condition given the new event.
    // event: the new log event
    // eventMatcherValues: the results of the LogMatcherTrackers. LogMatcherTrackers always process
    //                     event before ConditionTrackers, because ConditionTracker depends on
    //                     LogMatchingTrackers.
    // eventMatcherValues: the results of the AtomMatchingTrackers. AtomMatchingTrackers always
    //                     process event before ConditionTrackers, because ConditionTracker depends
    //                     on AtomMatchingTrackers.
    // mAllConditions: the list of all ConditionTracker
    // conditionCache: the cached non-sliced condition of the ConditionTrackers for this new event.
    // conditionChanged: the bit map to record whether the condition has changed.
@@ -88,8 +88,8 @@ public:
            const bool isPartialLink,
            std::vector<ConditionState>& conditionCache) const = 0;

    // return the list of LogMatchingTracker index that this ConditionTracker uses.
    virtual const std::set<int>& getLogTrackerIndex() const {
    // return the list of AtomMatchingTracker index that this ConditionTracker uses.
    virtual const std::set<int>& getAtomMatchingTrackerIndex() const {
        return mTrackerIndex;
    }

@@ -136,7 +136,7 @@ protected:
    // if it's properly initialized.
    bool mInitialized;

    // the list of LogMatchingTracker index that this ConditionTracker uses.
    // the list of AtomMatchingTracker index that this ConditionTracker uses.
    std::set<int> mTrackerIndex;

    // This variable is only used for CombinationConditionTrackers.
+24 −23
Original line number Diff line number Diff line
@@ -14,8 +14,8 @@
 * limitations under the License.
 */

#ifndef LOG_MATCHING_TRACKER_H
#define LOG_MATCHING_TRACKER_H
#ifndef ATOM_MATCHING_TRACKER_H
#define ATOM_MATCHING_TRACKER_H

#include "frameworks/base/cmds/statsd/src/statsd_config.pb.h"
#include "logd/LogEvent.h"
@@ -31,35 +31,36 @@ namespace android {
namespace os {
namespace statsd {

class LogMatchingTracker : public virtual RefBase {
class AtomMatchingTracker : public virtual RefBase {
public:
    LogMatchingTracker(const int64_t& id, const int index, const uint64_t protoHash)
    AtomMatchingTracker(const int64_t& id, const int index, const uint64_t protoHash)
        : mId(id), mIndex(index), mInitialized(false), mProtoHash(protoHash){};

    virtual ~LogMatchingTracker(){};
    virtual ~AtomMatchingTracker(){};

    // Initialize this LogMatchingTracker.
    // allLogMatchers: the list of the AtomMatcher proto config. This is needed because we don't
    // Initialize this AtomMatchingTracker.
    // allAtomMatchers: the list of the AtomMatcher proto config. This is needed because we don't
    //                  store the proto object in memory. We only need it during initilization.
    // allTrackers: the list of the LogMatchingTracker objects. It's a one-to-one mapping with
    //              allLogMatchers. This is needed because the initialization is done recursively
    //              for CombinationLogMatchingTrackers using DFS.
    // allAtomMatchingTrackers: the list of the AtomMatchingTracker objects. It's a one-to-one
    //                          mapping with allAtomMatchers. This is needed because the
    //                          initialization is done recursively for
    //                          CombinationAtomMatchingTrackers using DFS.
    // stack: a bit map to record which matcher has been visited on the stack. This is for detecting
    //        circle dependency.
    virtual bool init(const std::vector<AtomMatcher>& allLogMatchers,
                      const std::vector<sp<LogMatchingTracker>>& allTrackers,
    virtual bool init(const std::vector<AtomMatcher>& allAtomMatchers,
                      const std::vector<sp<AtomMatchingTracker>>& allAtomMatchingTrackers,
                      const std::unordered_map<int64_t, int>& matcherMap,
                      std::vector<bool>& stack) = 0;

    // Called when a log event comes.
    // event: the log event.
    // allTrackers: the list of all LogMatchingTrackers. This is needed because the log processing
    //              is done recursively.
    // allAtomMatchingTrackers: the list of all AtomMatchingTrackers. This is needed because the log
    //                          processing is done recursively.
    // matcherResults: The cached results for all matchers for this event. Parent matchers can
    //                 directly access the children's matching results if they have been evaluated.
    //                 Otherwise, call children matchers' onLogEvent.
    virtual void onLogEvent(const LogEvent& event,
                            const std::vector<sp<LogMatchingTracker>>& allTrackers,
                            const std::vector<sp<AtomMatchingTracker>>& allAtomMatchingTrackers,
                            std::vector<MatchingState>& matcherResults) = 0;

    // Get the tagIds that this matcher cares about. The combined collection is stored
@@ -81,23 +82,23 @@ protected:
    // Name of this matching. We don't really need the name, but it makes log message easy to debug.
    const int64_t mId;

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

    // Whether this LogMatchingTracker has been properly initialized.
    // Whether this AtomMatchingTracker has been properly initialized.
    bool mInitialized;

    // The collection of the event tag ids that this LogMatchingTracker cares. So we can quickly
    // The collection of the event tag ids that this AtomMatchingTracker cares. So we can quickly
    // return kNotMatched when we receive an event with an id not in the list. This is especially
    // useful when we have a complex CombinationLogMatcherTracker.
    // useful when we have a complex CombinationAtomMatchingTracker.
    std::set<int> mAtomIds;

    // Hash of the AtomMatcher's proto bytes from StatsdConfig.
    // Used to determine if the definition of this matcher has changed across a config update.
    const uint64_t mProtoHash;

    FRIEND_TEST(MetricsManagerTest, TestCreateLogTrackerSimple);
    FRIEND_TEST(MetricsManagerTest, TestCreateLogTrackerCombination);
    FRIEND_TEST(MetricsManagerTest, TestCreateAtomMatchingTrackerSimple);
    FRIEND_TEST(MetricsManagerTest, TestCreateAtomMatchingTrackerCombination);
    FRIEND_TEST(ConfigUpdateTest, TestUpdateMatchers);
};

@@ -105,4 +106,4 @@ protected:
}  // namespace os
}  // namespace android

#endif  // LOG_MATCHING_TRACKER_H
#endif  // ATOM_MATCHING_TRACKER_H
+19 −17
Original line number Diff line number Diff line
@@ -16,7 +16,8 @@

#include "Log.h"

#include "CombinationLogMatchingTracker.h"
#include "CombinationAtomMatchingTracker.h"

#include "matchers/matcher_util.h"

namespace android {
@@ -27,18 +28,18 @@ using std::set;
using std::unordered_map;
using std::vector;

CombinationLogMatchingTracker::CombinationLogMatchingTracker(const int64_t& id, const int index,
CombinationAtomMatchingTracker::CombinationAtomMatchingTracker(const int64_t& id, const int index,
                                                               const uint64_t protoHash)
    : LogMatchingTracker(id, index, protoHash) {
    : AtomMatchingTracker(id, index, protoHash) {
}

CombinationLogMatchingTracker::~CombinationLogMatchingTracker() {
CombinationAtomMatchingTracker::~CombinationAtomMatchingTracker() {
}

bool CombinationLogMatchingTracker::init(const vector<AtomMatcher>& allLogMatchers,
                                         const vector<sp<LogMatchingTracker>>& allTrackers,
                                         const unordered_map<int64_t, int>& matcherMap,
                                         vector<bool>& stack) {
bool CombinationAtomMatchingTracker::init(
        const vector<AtomMatcher>& allAtomMatchers,
        const vector<sp<AtomMatchingTracker>>& allAtomMatchingTrackers,
        const unordered_map<int64_t, int>& matcherMap, vector<bool>& stack) {
    if (mInitialized) {
        return true;
    }
@@ -46,7 +47,7 @@ bool CombinationLogMatchingTracker::init(const vector<AtomMatcher>& allLogMatche
    // mark this node as visited in the recursion stack.
    stack[mIndex] = true;

    AtomMatcher_Combination matcher = allLogMatchers[mIndex].combination();
    AtomMatcher_Combination matcher = allAtomMatchers[mIndex].combination();

    // LogicalOperation is missing in the config
    if (!matcher.has_operation()) {
@@ -74,14 +75,15 @@ bool CombinationLogMatchingTracker::init(const vector<AtomMatcher>& allLogMatche
            return false;
        }

        if (!allTrackers[childIndex]->init(allLogMatchers, allTrackers, matcherMap, stack)) {
        if (!allAtomMatchingTrackers[childIndex]->init(allAtomMatchers, allAtomMatchingTrackers,
                                                       matcherMap, stack)) {
            ALOGW("child matcher init failed %lld", (long long)child);
            return false;
        }

        mChildren.push_back(childIndex);

        const set<int>& childTagIds = allTrackers[childIndex]->getAtomIds();
        const set<int>& childTagIds = allAtomMatchingTrackers[childIndex]->getAtomIds();
        mAtomIds.insert(childTagIds.begin(), childTagIds.end());
    }

@@ -91,8 +93,8 @@ bool CombinationLogMatchingTracker::init(const vector<AtomMatcher>& allLogMatche
    return true;
}

void CombinationLogMatchingTracker::onLogEvent(const LogEvent& event,
                                               const vector<sp<LogMatchingTracker>>& allTrackers,
void CombinationAtomMatchingTracker::onLogEvent(
        const LogEvent& event, const vector<sp<AtomMatchingTracker>>& allAtomMatchingTrackers,
        vector<MatchingState>& matcherResults) {
    // this event has been processed.
    if (matcherResults[mIndex] != MatchingState::kNotComputed) {
@@ -107,8 +109,8 @@ void CombinationLogMatchingTracker::onLogEvent(const LogEvent& event,
    // evaluate children matchers if they haven't been evaluated.
    for (const int childIndex : mChildren) {
        if (matcherResults[childIndex] == MatchingState::kNotComputed) {
            const sp<LogMatchingTracker>& child = allTrackers[childIndex];
            child->onLogEvent(event, allTrackers, matcherResults);
            const sp<AtomMatchingTracker>& child = allAtomMatchingTrackers[childIndex];
            child->onLogEvent(event, allAtomMatchingTrackers, matcherResults);
        }
    }

Loading