Yao Chen | b704177 | 2017-10-20 16:59:25 -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 | */ |
Yao Chen | b704177 | 2017-10-20 16:59:25 -0700 | [diff] [blame] | 16 | |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame^] | 17 | #define DEBUG true // STOPSHIP if true |
| 18 | #include "Log.h" |
| 19 | #include "MetricProducer.h" |
Yangster-mac | 9369446 | 2018-01-22 20:49:31 -0800 | [diff] [blame] | 20 | |
Yao Chen | b704177 | 2017-10-20 16:59:25 -0700 | [diff] [blame] | 21 | namespace android { |
| 22 | namespace os { |
| 23 | namespace statsd { |
| 24 | |
| 25 | using std::map; |
| 26 | |
Chenjie Yu | a7259ab | 2017-12-10 08:31:05 -0800 | [diff] [blame] | 27 | void MetricProducer::onMatchedLogEventLocked(const size_t matcherIndex, const LogEvent& event) { |
Yao Chen | b704177 | 2017-10-20 16:59:25 -0700 | [diff] [blame] | 28 | uint64_t eventTimeNs = event.GetTimestampNs(); |
| 29 | // this is old event, maybe statsd restarted? |
| 30 | if (eventTimeNs < mStartTimeNs) { |
| 31 | return; |
| 32 | } |
| 33 | |
Yao Chen | b704177 | 2017-10-20 16:59:25 -0700 | [diff] [blame] | 34 | bool condition; |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 35 | ConditionKey conditionKey; |
Yangster-mac | 9369446 | 2018-01-22 20:49:31 -0800 | [diff] [blame] | 36 | |
| 37 | std::unordered_set<HashableDimensionKey> dimensionKeysInCondition; |
Yao Chen | b704177 | 2017-10-20 16:59:25 -0700 | [diff] [blame] | 38 | if (mConditionSliced) { |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame^] | 39 | for (const auto& link : mMetric2ConditionLinks) { |
| 40 | getDimensionForCondition(event, link, &conditionKey[link.conditionId]); |
Yao Chen | b704177 | 2017-10-20 16:59:25 -0700 | [diff] [blame] | 41 | } |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame^] | 42 | |
Yangster-mac | 9369446 | 2018-01-22 20:49:31 -0800 | [diff] [blame] | 43 | auto conditionState = |
| 44 | mWizard->query(mConditionTrackerIndex, conditionKey, mDimensionsInCondition, |
| 45 | &dimensionKeysInCondition); |
| 46 | condition = (conditionState == ConditionState::kTrue); |
Yao Chen | b704177 | 2017-10-20 16:59:25 -0700 | [diff] [blame] | 47 | } else { |
| 48 | condition = mCondition; |
| 49 | } |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 50 | |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame^] | 51 | vector<HashableDimensionKey> dimensionInWhatValues; |
| 52 | if (mDimensionsInWhat.size() > 0) { |
| 53 | filterValues(mDimensionsInWhat, event.getValues(), &dimensionInWhatValues); |
Yangster-mac | 9369446 | 2018-01-22 20:49:31 -0800 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | if (dimensionInWhatValues.empty() && dimensionKeysInCondition.empty()) { |
| 57 | onMatchedLogEventInternalLocked( |
| 58 | matcherIndex, DEFAULT_METRIC_DIMENSION_KEY, conditionKey, condition, event); |
| 59 | } else if (dimensionKeysInCondition.empty()) { |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame^] | 60 | for (const HashableDimensionKey& whatValue : dimensionInWhatValues) { |
| 61 | onMatchedLogEventInternalLocked(matcherIndex, |
| 62 | MetricDimensionKey(whatValue, DEFAULT_DIMENSION_KEY), |
| 63 | conditionKey, condition, event); |
Yangster-mac | 9369446 | 2018-01-22 20:49:31 -0800 | [diff] [blame] | 64 | } |
| 65 | } else if (dimensionInWhatValues.empty()) { |
| 66 | for (const auto& conditionDimensionKey : dimensionKeysInCondition) { |
| 67 | onMatchedLogEventInternalLocked( |
| 68 | matcherIndex, |
| 69 | MetricDimensionKey(DEFAULT_DIMENSION_KEY, conditionDimensionKey), |
| 70 | conditionKey, condition, event); |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 71 | } |
| 72 | } else { |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame^] | 73 | for (const auto& whatValue : dimensionInWhatValues) { |
Yangster-mac | 9369446 | 2018-01-22 20:49:31 -0800 | [diff] [blame] | 74 | for (const auto& conditionDimensionKey : dimensionKeysInCondition) { |
| 75 | onMatchedLogEventInternalLocked( |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame^] | 76 | matcherIndex, MetricDimensionKey(whatValue, conditionDimensionKey), |
| 77 | conditionKey, condition, event); |
Yangster-mac | 9369446 | 2018-01-22 20:49:31 -0800 | [diff] [blame] | 78 | } |
| 79 | } |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 80 | } |
Yao Chen | b704177 | 2017-10-20 16:59:25 -0700 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | } // namespace statsd |
| 84 | } // namespace os |
yro | 2b0f886 | 2017-11-06 14:27:31 -0800 | [diff] [blame] | 85 | } // namespace android |