blob: 815b445a8c5bfe19c5270167af114c4fc685cd54 [file] [log] [blame]
Yao Chencaf339d2017-10-06 16:01:10 -07001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef SIMPLE_CONDITION_TRACKER_H
18#define SIMPLE_CONDITION_TRACKER_H
19
Yao Chen967b2052017-11-07 16:36:43 -080020#include <gtest/gtest_prod.h>
Yao Chencaf339d2017-10-06 16:01:10 -070021#include "ConditionTracker.h"
Yao Chenb3561512017-11-21 18:07:17 -080022#include "config/ConfigKey.h"
Yao Chencaf339d2017-10-06 16:01:10 -070023#include "frameworks/base/cmds/statsd/src/statsd_config.pb.h"
Yao Chen729093d2017-10-16 10:33:26 -070024#include "stats_util.h"
Yao Chencaf339d2017-10-06 16:01:10 -070025
26namespace android {
27namespace os {
28namespace statsd {
29
30class SimpleConditionTracker : public virtual ConditionTracker {
31public:
Yangster-mac94e197c2018-01-02 16:03:03 -080032 SimpleConditionTracker(const ConfigKey& key, const int64_t& id, const int index,
Stefan Lafon12d01fa2017-12-04 20:56:09 -080033 const SimplePredicate& simplePredicate,
Yangster-mac94e197c2018-01-02 16:03:03 -080034 const std::unordered_map<int64_t, int>& trackerNameIndexMap);
Yao Chencaf339d2017-10-06 16:01:10 -070035
36 ~SimpleConditionTracker();
37
Stefan Lafon12d01fa2017-12-04 20:56:09 -080038 bool init(const std::vector<Predicate>& allConditionConfig,
Yao Chencaf339d2017-10-06 16:01:10 -070039 const std::vector<sp<ConditionTracker>>& allConditionTrackers,
Yangster-mac94e197c2018-01-02 16:03:03 -080040 const std::unordered_map<int64_t, int>& conditionIdIndexMap,
Yao Chencaf339d2017-10-06 16:01:10 -070041 std::vector<bool>& stack) override;
42
Yao Chen967b2052017-11-07 16:36:43 -080043 void evaluateCondition(const LogEvent& event,
Yao Chencaf339d2017-10-06 16:01:10 -070044 const std::vector<MatchingState>& eventMatcherValues,
45 const std::vector<sp<ConditionTracker>>& mAllConditions,
46 std::vector<ConditionState>& conditionCache,
Yao Chen967b2052017-11-07 16:36:43 -080047 std::vector<bool>& changedCache) override;
Yao Chen729093d2017-10-16 10:33:26 -070048
Yangster-mac20877162017-12-22 17:19:39 -080049 void isConditionMet(const ConditionKey& conditionParameters,
Yao Chen729093d2017-10-16 10:33:26 -070050 const std::vector<sp<ConditionTracker>>& allConditions,
Yangster7c334a12017-11-22 14:24:24 -080051 std::vector<ConditionState>& conditionCache) const override;
Yao Chen729093d2017-10-16 10:33:26 -070052
Yao Chencaf339d2017-10-06 16:01:10 -070053private:
Yao Chenb3561512017-11-21 18:07:17 -080054 const ConfigKey mConfigKey;
Yao Chencaf339d2017-10-06 16:01:10 -070055 // The index of the LogEventMatcher which defines the start.
56 int mStartLogMatcherIndex;
57
58 // The index of the LogEventMatcher which defines the end.
59 int mStopLogMatcherIndex;
60
61 // if the start end needs to be nested.
62 bool mCountNesting;
63
64 // The index of the LogEventMatcher which defines the stop all.
65 int mStopAllLogMatcherIndex;
Yao Chen729093d2017-10-16 10:33:26 -070066
Yao Chen967b2052017-11-07 16:36:43 -080067 ConditionState mInitialValue;
Yao Chen729093d2017-10-16 10:33:26 -070068
Yangster-mac20877162017-12-22 17:19:39 -080069 FieldMatcher mOutputDimensions;
Yao Chen967b2052017-11-07 16:36:43 -080070
71 std::map<HashableDimensionKey, int> mSlicedConditionState;
72
73 void handleStopAll(std::vector<ConditionState>& conditionCache,
74 std::vector<bool>& changedCache);
75
76 void handleConditionEvent(const HashableDimensionKey& outputKey, bool matchStart,
77 std::vector<ConditionState>& conditionCache,
78 std::vector<bool>& changedCache);
79
Yao Chenb3561512017-11-21 18:07:17 -080080 bool hitGuardRail(const HashableDimensionKey& newKey);
81
Yao Chen967b2052017-11-07 16:36:43 -080082 FRIEND_TEST(SimpleConditionTrackerTest, TestSlicedCondition);
83 FRIEND_TEST(SimpleConditionTrackerTest, TestSlicedWithNoOutputDim);
84 FRIEND_TEST(SimpleConditionTrackerTest, TestStopAll);
Yao Chencaf339d2017-10-06 16:01:10 -070085};
86
87} // namespace statsd
88} // namespace os
89} // namespace android
90
91#endif // SIMPLE_CONDITION_TRACKER_H