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

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

Merge "Match pulled events in gauge metric."

parents 21c589aa 32f07af2
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ statsd_common_src := \
    src/logd/LogEvent.cpp \
    src/logd/LogListener.cpp \
    src/matchers/CombinationLogMatchingTracker.cpp \
    src/matchers/EventMatcherWizard.cpp \
    src/matchers/matcher_util.cpp \
    src/matchers/SimpleLogMatchingTracker.cpp \
    src/metrics/MetricProducer.cpp \
+1 −1
Original line number Diff line number Diff line
@@ -194,7 +194,7 @@ private:
    FRIEND_TEST(GaugeMetricE2eTest, TestMultipleFieldsForPushedEvent);
    FRIEND_TEST(GaugeMetricE2eTest, TestRandomSamplePulledEvents);
    FRIEND_TEST(GaugeMetricE2eTest, TestRandomSamplePulledEvent_LateAlarm);
    FRIEND_TEST(GaugeMetricE2eTest, TestAllConditionChangesSamplePulledEvents);
    FRIEND_TEST(GaugeMetricE2eTest, TestConditionChangeToTrueSamplePulledEvents);
    FRIEND_TEST(ValueMetricE2eTest, TestPulledEvents);
    FRIEND_TEST(ValueMetricE2eTest, TestPulledEvents_LateAlarm);

+38 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include "EventMatcherWizard.h"
#include <unordered_set>

namespace android {
namespace os {
namespace statsd {

using std::map;
using std::string;
using std::vector;

MatchingState EventMatcherWizard::matchLogEvent(const LogEvent& event, int matcher_index) {
    if (matcher_index < 0 || matcher_index >= (int)mAllEventMatchers.size()) {
        return MatchingState::kNotComputed;
    }
    vector<MatchingState> matcherCache(mAllEventMatchers.size(), MatchingState::kNotComputed);
    mAllEventMatchers[matcher_index]->onLogEvent(event, mAllEventMatchers, matcherCache);
    return matcherCache[matcher_index];
}

}  // namespace statsd
}  // namespace os
}  // namespace android
 No newline at end of file
+41 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include "LogMatchingTracker.h"

namespace android {
namespace os {
namespace statsd {

class EventMatcherWizard : public virtual android::RefBase {
public:
    EventMatcherWizard(){};  // for testing
    EventMatcherWizard(const std::vector<sp<LogMatchingTracker>>& eventTrackers)
        : mAllEventMatchers(eventTrackers){};

    virtual ~EventMatcherWizard(){};

    MatchingState matchLogEvent(const LogEvent& event, int matcher_index);

private:
    std::vector<sp<LogMatchingTracker>> mAllEventMatchers;
};

}  // namespace statsd
}  // namespace os
}  // namespace android
+19 −8
Original line number Diff line number Diff line
@@ -69,11 +69,16 @@ const int FIELD_ID_END_BUCKET_ELAPSED_MILLIS = 8;

GaugeMetricProducer::GaugeMetricProducer(const ConfigKey& key, const GaugeMetric& metric,
                                         const int conditionIndex,
                                         const sp<ConditionWizard>& wizard, const int pullTagId,
                                         const sp<ConditionWizard>& wizard,
                                         const int whatMatcherIndex,
                                         const sp<EventMatcherWizard>& matcherWizard,
                                         const int pullTagId,
                                         const int triggerAtomId, const int atomId,
                                         const int64_t timeBaseNs, const int64_t startTimeNs,
                                         const sp<StatsPullerManager>& pullerManager)
    : MetricProducer(metric.id(), key, timeBaseNs, conditionIndex, wizard),
      mWhatMatcherIndex(whatMatcherIndex),
      mEventMatcherWizard(matcherWizard),
      mPullerManager(pullerManager),
      mPullTagId(pullTagId),
      mTriggerAtomId(triggerAtomId),
@@ -136,7 +141,7 @@ GaugeMetricProducer::GaugeMetricProducer(const ConfigKey& key, const GaugeMetric
    // Adjust start for partial bucket
    mCurrentBucketStartTimeNs = startTimeNs;
    if (mIsPulled) {
        pullLocked(startTimeNs);
        pullAndMatchEventsLocked(startTimeNs);
    }

    VLOG("Gauge metric %lld created. bucket size %lld start_time: %lld sliced %d",
@@ -302,7 +307,7 @@ void GaugeMetricProducer::onDumpReportLocked(const int64_t dumpTimeNs,
    mPastBuckets.clear();
}

void GaugeMetricProducer::pullLocked(const int64_t timestampNs) {
void GaugeMetricProducer::pullAndMatchEventsLocked(const int64_t timestampNs) {
    bool triggerPuller = false;
    switch(mSamplingType) {
        // When the metric wants to do random sampling and there is already one gauge atom for the
@@ -331,7 +336,10 @@ void GaugeMetricProducer::pullLocked(const int64_t timestampNs) {
        return;
    }
    for (const auto& data : allData) {
        onMatchedLogEventLocked(0, *data);
        if (mEventMatcherWizard->matchLogEvent(
                *data, mWhatMatcherIndex) == MatchingState::kMatched) {
            onMatchedLogEventLocked(mWhatMatcherIndex, *data);
        }
    }
}

@@ -341,7 +349,7 @@ void GaugeMetricProducer::onConditionChangedLocked(const bool conditionMet,
    flushIfNeededLocked(eventTimeNs);
    mCondition = conditionMet;
    if (mIsPulled) {
        pullLocked(eventTimeNs);
        pullAndMatchEventsLocked(eventTimeNs);
    }  // else: Push mode. No need to proactively pull the gauge data.
}

@@ -354,7 +362,7 @@ void GaugeMetricProducer::onSlicedConditionMayChangeLocked(bool overallCondition
    // pull for every dimension.
    mCondition = overallCondition;
    if (mIsPulled) {
        pullLocked(eventTimeNs);
        pullAndMatchEventsLocked(eventTimeNs);
    }  // else: Push mode. No need to proactively pull the gauge data.
}

@@ -387,7 +395,10 @@ void GaugeMetricProducer::onDataPulled(const std::vector<std::shared_ptr<LogEven
        return;
    }
    for (const auto& data : allData) {
        onMatchedLogEventLocked(0, *data);
        if (mEventMatcherWizard->matchLogEvent(
                *data, mWhatMatcherIndex) == MatchingState::kMatched) {
            onMatchedLogEventLocked(mWhatMatcherIndex, *data);
        }
    }
}

@@ -426,7 +437,7 @@ void GaugeMetricProducer::onMatchedLogEventInternalLocked(
    flushIfNeededLocked(eventTimeNs);

    if (mTriggerAtomId == event.GetTagId()) {
        pullLocked(eventTimeNs);
        pullAndMatchEventsLocked(eventTimeNs);
        return;
    }

Loading