Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
Yao Chen | 5110bed | 2017-10-23 12:50:02 -0700 | [diff] [blame] | 17 | #define DEBUG false // STOPSHIP if true |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 18 | #include "Log.h" |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 19 | |
| 20 | #include "SimpleConditionTracker.h" |
Yao Chen | b356151 | 2017-11-21 18:07:17 -0800 | [diff] [blame] | 21 | #include "guardrail/StatsdStats.h" |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 22 | |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 23 | #include <log/logprint.h> |
| 24 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 25 | namespace android { |
| 26 | namespace os { |
| 27 | namespace statsd { |
| 28 | |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 29 | using std::map; |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 30 | using std::string; |
| 31 | using std::unique_ptr; |
| 32 | using std::unordered_map; |
| 33 | using std::vector; |
| 34 | |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 35 | SimpleConditionTracker::SimpleConditionTracker( |
Yao Chen | b356151 | 2017-11-21 18:07:17 -0800 | [diff] [blame] | 36 | const ConfigKey& key, const string& name, const int index, |
Stefan Lafon | 12d01fa | 2017-12-04 20:56:09 -0800 | [diff] [blame] | 37 | const SimplePredicate& simplePredicate, |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 38 | const unordered_map<string, int>& trackerNameIndexMap) |
Yao Chen | b356151 | 2017-11-21 18:07:17 -0800 | [diff] [blame] | 39 | : ConditionTracker(name, index), mConfigKey(key) { |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 40 | VLOG("creating SimpleConditionTracker %s", mName.c_str()); |
Stefan Lafon | 12d01fa | 2017-12-04 20:56:09 -0800 | [diff] [blame] | 41 | mCountNesting = simplePredicate.count_nesting(); |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 42 | |
Stefan Lafon | 12d01fa | 2017-12-04 20:56:09 -0800 | [diff] [blame] | 43 | if (simplePredicate.has_start()) { |
| 44 | auto pair = trackerNameIndexMap.find(simplePredicate.start()); |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 45 | if (pair == trackerNameIndexMap.end()) { |
Stefan Lafon | 12d01fa | 2017-12-04 20:56:09 -0800 | [diff] [blame] | 46 | ALOGW("Start matcher %s not found in the config", simplePredicate.start().c_str()); |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 47 | return; |
| 48 | } |
| 49 | mStartLogMatcherIndex = pair->second; |
| 50 | mTrackerIndex.insert(mStartLogMatcherIndex); |
| 51 | } else { |
| 52 | mStartLogMatcherIndex = -1; |
| 53 | } |
| 54 | |
Stefan Lafon | 12d01fa | 2017-12-04 20:56:09 -0800 | [diff] [blame] | 55 | if (simplePredicate.has_stop()) { |
| 56 | auto pair = trackerNameIndexMap.find(simplePredicate.stop()); |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 57 | if (pair == trackerNameIndexMap.end()) { |
Stefan Lafon | 12d01fa | 2017-12-04 20:56:09 -0800 | [diff] [blame] | 58 | ALOGW("Stop matcher %s not found in the config", simplePredicate.stop().c_str()); |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 59 | return; |
| 60 | } |
| 61 | mStopLogMatcherIndex = pair->second; |
Yao Chen | 4b14685 | 2017-10-10 15:34:42 -0700 | [diff] [blame] | 62 | mTrackerIndex.insert(mStopLogMatcherIndex); |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 63 | } else { |
| 64 | mStopLogMatcherIndex = -1; |
| 65 | } |
| 66 | |
Stefan Lafon | 12d01fa | 2017-12-04 20:56:09 -0800 | [diff] [blame] | 67 | if (simplePredicate.has_stop_all()) { |
| 68 | auto pair = trackerNameIndexMap.find(simplePredicate.stop_all()); |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 69 | if (pair == trackerNameIndexMap.end()) { |
Stefan Lafon | 12d01fa | 2017-12-04 20:56:09 -0800 | [diff] [blame] | 70 | ALOGW("Stop all matcher %s not found in the config", simplePredicate.stop().c_str()); |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 71 | return; |
| 72 | } |
| 73 | mStopAllLogMatcherIndex = pair->second; |
| 74 | mTrackerIndex.insert(mStopAllLogMatcherIndex); |
| 75 | } else { |
| 76 | mStopAllLogMatcherIndex = -1; |
| 77 | } |
| 78 | |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 79 | mOutputDimensions = simplePredicate.dimensions(); |
Yao Chen | 5154a37 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 80 | |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 81 | if (mOutputDimensions.child_size() > 0) { |
Yao Chen | 5154a37 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 82 | mSliced = true; |
| 83 | } |
| 84 | |
Stefan Lafon | 12d01fa | 2017-12-04 20:56:09 -0800 | [diff] [blame] | 85 | if (simplePredicate.initial_value() == SimplePredicate_InitialValue_FALSE) { |
Yao Chen | 967b205 | 2017-11-07 16:36:43 -0800 | [diff] [blame] | 86 | mInitialValue = ConditionState::kFalse; |
| 87 | } else { |
| 88 | mInitialValue = ConditionState::kUnknown; |
| 89 | } |
| 90 | |
| 91 | mNonSlicedConditionState = mInitialValue; |
| 92 | |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 93 | mInitialized = true; |
| 94 | } |
| 95 | |
| 96 | SimpleConditionTracker::~SimpleConditionTracker() { |
| 97 | VLOG("~SimpleConditionTracker()"); |
| 98 | } |
| 99 | |
Stefan Lafon | 12d01fa | 2017-12-04 20:56:09 -0800 | [diff] [blame] | 100 | bool SimpleConditionTracker::init(const vector<Predicate>& allConditionConfig, |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 101 | const vector<sp<ConditionTracker>>& allConditionTrackers, |
| 102 | const unordered_map<string, int>& conditionNameIndexMap, |
| 103 | vector<bool>& stack) { |
| 104 | // SimpleConditionTracker does not have dependency on other conditions, thus we just return |
| 105 | // if the initialization was successful. |
| 106 | return mInitialized; |
| 107 | } |
| 108 | |
Yao Chen | 967b205 | 2017-11-07 16:36:43 -0800 | [diff] [blame] | 109 | void print(map<HashableDimensionKey, int>& conditions, const string& name) { |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 110 | VLOG("%s DUMP:", name.c_str()); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 111 | for (const auto& pair : conditions) { |
Yao Chen | 967b205 | 2017-11-07 16:36:43 -0800 | [diff] [blame] | 112 | VLOG("\t%s : %d", pair.first.c_str(), pair.second); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 113 | } |
| 114 | } |
| 115 | |
Yao Chen | 967b205 | 2017-11-07 16:36:43 -0800 | [diff] [blame] | 116 | void SimpleConditionTracker::handleStopAll(std::vector<ConditionState>& conditionCache, |
| 117 | std::vector<bool>& conditionChangedCache) { |
| 118 | // Unless the default condition is false, and there was nothing started, otherwise we have |
| 119 | // triggered a condition change. |
| 120 | conditionChangedCache[mIndex] = |
| 121 | (mInitialValue == ConditionState::kFalse && mSlicedConditionState.empty()) ? false |
| 122 | : true; |
| 123 | |
| 124 | // After StopAll, we know everything has stopped. From now on, default condition is false. |
| 125 | mInitialValue = ConditionState::kFalse; |
| 126 | mSlicedConditionState.clear(); |
| 127 | conditionCache[mIndex] = ConditionState::kFalse; |
| 128 | } |
| 129 | |
Yao Chen | b356151 | 2017-11-21 18:07:17 -0800 | [diff] [blame] | 130 | bool SimpleConditionTracker::hitGuardRail(const HashableDimensionKey& newKey) { |
| 131 | if (!mSliced || mSlicedConditionState.find(newKey) != mSlicedConditionState.end()) { |
| 132 | // if the condition is not sliced or the key is not new, we are good! |
| 133 | return false; |
| 134 | } |
| 135 | // 1. Report the tuple count if the tuple count > soft limit |
| 136 | if (mSlicedConditionState.size() > StatsdStats::kDimensionKeySizeSoftLimit - 1) { |
| 137 | size_t newTupleCount = mSlicedConditionState.size() + 1; |
| 138 | StatsdStats::getInstance().noteConditionDimensionSize(mConfigKey, mName, newTupleCount); |
| 139 | // 2. Don't add more tuples, we are above the allowed threshold. Drop the data. |
| 140 | if (newTupleCount > StatsdStats::kDimensionKeySizeHardLimit) { |
Stefan Lafon | 12d01fa | 2017-12-04 20:56:09 -0800 | [diff] [blame] | 141 | ALOGE("Predicate %s dropping data for dimension key %s", mName.c_str(), newKey.c_str()); |
Yao Chen | b356151 | 2017-11-21 18:07:17 -0800 | [diff] [blame] | 142 | return true; |
| 143 | } |
| 144 | } |
| 145 | return false; |
| 146 | } |
| 147 | |
Yao Chen | 967b205 | 2017-11-07 16:36:43 -0800 | [diff] [blame] | 148 | void SimpleConditionTracker::handleConditionEvent(const HashableDimensionKey& outputKey, |
| 149 | bool matchStart, |
| 150 | std::vector<ConditionState>& conditionCache, |
| 151 | std::vector<bool>& conditionChangedCache) { |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 152 | if ((int)conditionChangedCache.size() <= mIndex) { |
| 153 | ALOGE("handleConditionEvent: param conditionChangedCache not initialized."); |
| 154 | return; |
| 155 | } |
| 156 | if ((int)conditionCache.size() <= mIndex) { |
| 157 | ALOGE("handleConditionEvent: param conditionCache not initialized."); |
| 158 | return; |
| 159 | } |
Yao Chen | 967b205 | 2017-11-07 16:36:43 -0800 | [diff] [blame] | 160 | bool changed = false; |
| 161 | auto outputIt = mSlicedConditionState.find(outputKey); |
| 162 | ConditionState newCondition; |
Yao Chen | b356151 | 2017-11-21 18:07:17 -0800 | [diff] [blame] | 163 | if (hitGuardRail(outputKey)) { |
| 164 | conditionChangedCache[mIndex] = false; |
| 165 | // Tells the caller it's evaluated. |
| 166 | conditionCache[mIndex] = ConditionState::kUnknown; |
| 167 | return; |
| 168 | } |
Yao Chen | 967b205 | 2017-11-07 16:36:43 -0800 | [diff] [blame] | 169 | if (outputIt == mSlicedConditionState.end()) { |
| 170 | // We get a new output key. |
| 171 | newCondition = matchStart ? ConditionState::kTrue : ConditionState::kFalse; |
| 172 | if (matchStart && mInitialValue != ConditionState::kTrue) { |
| 173 | mSlicedConditionState[outputKey] = 1; |
| 174 | changed = true; |
| 175 | } else if (mInitialValue != ConditionState::kFalse) { |
| 176 | // it's a stop and we don't have history about it. |
| 177 | // If the default condition is not false, it means this stop is valuable to us. |
| 178 | mSlicedConditionState[outputKey] = 0; |
| 179 | changed = true; |
| 180 | } |
| 181 | } else { |
| 182 | // we have history about this output key. |
| 183 | auto& startedCount = outputIt->second; |
| 184 | // assign the old value first. |
| 185 | newCondition = startedCount > 0 ? ConditionState::kTrue : ConditionState::kFalse; |
| 186 | if (matchStart) { |
| 187 | if (startedCount == 0) { |
| 188 | // This condition for this output key will change from false -> true |
| 189 | changed = true; |
| 190 | } |
| 191 | |
| 192 | // it's ok to do ++ here, even if we don't count nesting. The >1 counts will be treated |
| 193 | // as 1 if not counting nesting. |
| 194 | startedCount++; |
| 195 | newCondition = ConditionState::kTrue; |
| 196 | } else { |
| 197 | // This is a stop event. |
| 198 | if (startedCount > 0) { |
| 199 | if (mCountNesting) { |
| 200 | startedCount--; |
| 201 | if (startedCount == 0) { |
| 202 | newCondition = ConditionState::kFalse; |
| 203 | } |
| 204 | } else { |
| 205 | // not counting nesting, so ignore the number of starts, stop now. |
| 206 | startedCount = 0; |
| 207 | newCondition = ConditionState::kFalse; |
| 208 | } |
| 209 | // if everything has stopped for this output key, condition true -> false; |
| 210 | if (startedCount == 0) { |
| 211 | changed = true; |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | // if default condition is false, it means we don't need to keep the false values. |
| 216 | if (mInitialValue == ConditionState::kFalse && startedCount == 0) { |
| 217 | mSlicedConditionState.erase(outputIt); |
| 218 | VLOG("erase key %s", outputKey.c_str()); |
| 219 | } |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | // dump all dimensions for debugging |
| 224 | if (DEBUG) { |
| 225 | print(mSlicedConditionState, mName); |
| 226 | } |
| 227 | |
| 228 | conditionChangedCache[mIndex] = changed; |
| 229 | conditionCache[mIndex] = newCondition; |
| 230 | |
Stefan Lafon | 12d01fa | 2017-12-04 20:56:09 -0800 | [diff] [blame] | 231 | VLOG("SimplePredicate %s nonSlicedChange? %d", mName.c_str(), |
Yao Chen | 967b205 | 2017-11-07 16:36:43 -0800 | [diff] [blame] | 232 | conditionChangedCache[mIndex] == true); |
| 233 | } |
| 234 | |
| 235 | void SimpleConditionTracker::evaluateCondition(const LogEvent& event, |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 236 | const vector<MatchingState>& eventMatcherValues, |
| 237 | const vector<sp<ConditionTracker>>& mAllConditions, |
| 238 | vector<ConditionState>& conditionCache, |
Yao Chen | 967b205 | 2017-11-07 16:36:43 -0800 | [diff] [blame] | 239 | vector<bool>& conditionChangedCache) { |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 240 | if (conditionCache[mIndex] != ConditionState::kNotEvaluated) { |
| 241 | // it has been evaluated. |
Yao Chen | d41c422 | 2017-11-15 19:26:14 -0800 | [diff] [blame] | 242 | VLOG("Yes, already evaluated, %s %d", mName.c_str(), conditionCache[mIndex]); |
Yao Chen | 967b205 | 2017-11-07 16:36:43 -0800 | [diff] [blame] | 243 | return; |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 244 | } |
| 245 | |
David Chen | c18abed | 2017-11-22 16:47:59 -0800 | [diff] [blame] | 246 | if (mStopAllLogMatcherIndex >= 0 && mStopAllLogMatcherIndex < int(eventMatcherValues.size()) && |
Yao Chen | 967b205 | 2017-11-07 16:36:43 -0800 | [diff] [blame] | 247 | eventMatcherValues[mStopAllLogMatcherIndex] == MatchingState::kMatched) { |
| 248 | handleStopAll(conditionCache, conditionChangedCache); |
| 249 | return; |
| 250 | } |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 251 | |
Yao Chen | 967b205 | 2017-11-07 16:36:43 -0800 | [diff] [blame] | 252 | int matchedState = -1; |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 253 | // Note: The order to evaluate the following start, stop, stop_all matters. |
| 254 | // The priority of overwrite is stop_all > stop > start. |
| 255 | if (mStartLogMatcherIndex >= 0 && |
| 256 | eventMatcherValues[mStartLogMatcherIndex] == MatchingState::kMatched) { |
Yao Chen | 967b205 | 2017-11-07 16:36:43 -0800 | [diff] [blame] | 257 | matchedState = 1; |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | if (mStopLogMatcherIndex >= 0 && |
| 261 | eventMatcherValues[mStopLogMatcherIndex] == MatchingState::kMatched) { |
Yao Chen | 967b205 | 2017-11-07 16:36:43 -0800 | [diff] [blame] | 262 | matchedState = 0; |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 263 | } |
| 264 | |
Yao Chen | 967b205 | 2017-11-07 16:36:43 -0800 | [diff] [blame] | 265 | if (matchedState < 0) { |
Yao Chen | d41c422 | 2017-11-15 19:26:14 -0800 | [diff] [blame] | 266 | // The event doesn't match this condition. So we just report existing condition values. |
Yao Chen | 967b205 | 2017-11-07 16:36:43 -0800 | [diff] [blame] | 267 | conditionChangedCache[mIndex] = false; |
Yao Chen | d41c422 | 2017-11-15 19:26:14 -0800 | [diff] [blame] | 268 | if (mSliced) { |
| 269 | // if the condition result is sliced. metrics won't directly get value from the |
| 270 | // cache, so just set any value other than kNotEvaluated. |
| 271 | conditionCache[mIndex] = ConditionState::kUnknown; |
Yao Chen | d41c422 | 2017-11-15 19:26:14 -0800 | [diff] [blame] | 272 | } else { |
Yangster | 7c334a1 | 2017-11-22 14:24:24 -0800 | [diff] [blame] | 273 | const auto& itr = mSlicedConditionState.find(DEFAULT_DIMENSION_KEY); |
| 274 | if (itr == mSlicedConditionState.end()) { |
| 275 | // condition not sliced, but we haven't seen the matched start or stop yet. so |
| 276 | // return initial value. |
| 277 | conditionCache[mIndex] = mInitialValue; |
| 278 | } else { |
| 279 | // return the cached condition. |
| 280 | conditionCache[mIndex] = |
| 281 | itr->second > 0 ? ConditionState::kTrue : ConditionState::kFalse; |
| 282 | } |
Yao Chen | d41c422 | 2017-11-15 19:26:14 -0800 | [diff] [blame] | 283 | } |
Yangster | 7c334a1 | 2017-11-22 14:24:24 -0800 | [diff] [blame] | 284 | |
Yao Chen | 967b205 | 2017-11-07 16:36:43 -0800 | [diff] [blame] | 285 | return; |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 286 | } |
| 287 | |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 288 | // outputKey is the output values. e.g, uid:1234 |
| 289 | const std::vector<DimensionsValue> outputValues = getDimensionKeys(event, mOutputDimensions); |
| 290 | if (outputValues.size() == 0) { |
| 291 | // The original implementation would generate an empty string dimension hash when condition |
| 292 | // is not sliced. |
| 293 | handleConditionEvent( |
| 294 | DEFAULT_DIMENSION_KEY, matchedState == 1, conditionCache, conditionChangedCache); |
| 295 | } else if (outputValues.size() == 1) { |
| 296 | handleConditionEvent(HashableDimensionKey(outputValues[0]), matchedState == 1, |
| 297 | conditionCache, conditionChangedCache); |
| 298 | } else { |
| 299 | // If this event has multiple nodes in the attribution chain, this log event probably will |
| 300 | // generate multiple dimensions. If so, we will find if the condition changes for any |
| 301 | // dimension and ask the corresponding metric producer to verify whether the actual sliced |
| 302 | // condition has changed or not. |
| 303 | // A high level assumption is that a predicate is either sliced or unsliced. We will never |
| 304 | // have both sliced and unsliced version of a predicate. |
| 305 | for (const DimensionsValue& outputValue : outputValues) { |
| 306 | vector<ConditionState> dimensionalConditionCache(conditionCache.size(), |
| 307 | ConditionState::kNotEvaluated); |
| 308 | vector<bool> dimensionalConditionChangedCache(conditionChangedCache.size(), false); |
| 309 | |
| 310 | handleConditionEvent(HashableDimensionKey(outputValue), matchedState == 1, |
| 311 | dimensionalConditionCache, dimensionalConditionChangedCache); |
| 312 | |
| 313 | OrConditionState(dimensionalConditionCache, &conditionCache); |
| 314 | OrBooleanVector(dimensionalConditionChangedCache, &conditionChangedCache); |
| 315 | } |
| 316 | } |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | void SimpleConditionTracker::isConditionMet( |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 320 | const ConditionKey& conditionParameters, |
Yangster | 7c334a1 | 2017-11-22 14:24:24 -0800 | [diff] [blame] | 321 | const vector<sp<ConditionTracker>>& allConditions, |
| 322 | vector<ConditionState>& conditionCache) const { |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 323 | const auto pair = conditionParameters.find(mName); |
Yao Chen | 967b205 | 2017-11-07 16:36:43 -0800 | [diff] [blame] | 324 | |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 325 | if (pair == conditionParameters.end() && mOutputDimensions.child_size() > 0) { |
Stefan Lafon | 12d01fa | 2017-12-04 20:56:09 -0800 | [diff] [blame] | 326 | ALOGE("Predicate %s output has dimension, but it's not specified in the query!", |
Yao Chen | 967b205 | 2017-11-07 16:36:43 -0800 | [diff] [blame] | 327 | mName.c_str()); |
| 328 | conditionCache[mIndex] = mInitialValue; |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 329 | return; |
| 330 | } |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 331 | std::vector<HashableDimensionKey> defaultKeys = {DEFAULT_DIMENSION_KEY}; |
| 332 | const std::vector<HashableDimensionKey> &keys = |
| 333 | (pair == conditionParameters.end()) ? defaultKeys : pair->second; |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 334 | |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 335 | ConditionState conditionState = ConditionState::kNotEvaluated; |
| 336 | for (const auto& key : keys) { |
| 337 | auto startedCountIt = mSlicedConditionState.find(key); |
| 338 | if (startedCountIt != mSlicedConditionState.end()) { |
| 339 | conditionState = conditionState | |
| 340 | (startedCountIt->second > 0 ? ConditionState::kTrue : ConditionState::kFalse); |
| 341 | } else { |
| 342 | conditionState = conditionState | mInitialValue; |
| 343 | } |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 344 | } |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 345 | conditionCache[mIndex] = conditionState; |
Stefan Lafon | 12d01fa | 2017-12-04 20:56:09 -0800 | [diff] [blame] | 346 | VLOG("Predicate %s return %d", mName.c_str(), conditionCache[mIndex]); |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | } // namespace statsd |
| 350 | } // namespace os |
| 351 | } // namespace android |