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 | */ |
| 16 | #include "MetricProducer.h" |
| 17 | |
| 18 | namespace android { |
| 19 | namespace os { |
| 20 | namespace statsd { |
| 21 | |
| 22 | using std::map; |
| 23 | |
Chenjie Yu | a7259ab | 2017-12-10 08:31:05 -0800 | [diff] [blame] | 24 | void MetricProducer::onMatchedLogEventLocked(const size_t matcherIndex, const LogEvent& event) { |
Yao Chen | b704177 | 2017-10-20 16:59:25 -0700 | [diff] [blame] | 25 | uint64_t eventTimeNs = event.GetTimestampNs(); |
| 26 | // this is old event, maybe statsd restarted? |
| 27 | if (eventTimeNs < mStartTimeNs) { |
| 28 | return; |
| 29 | } |
| 30 | |
Yao Chen | b704177 | 2017-10-20 16:59:25 -0700 | [diff] [blame] | 31 | bool condition; |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 32 | map<string, std::vector<HashableDimensionKey>> conditionKeys; |
Yao Chen | b704177 | 2017-10-20 16:59:25 -0700 | [diff] [blame] | 33 | if (mConditionSliced) { |
| 34 | for (const auto& link : mConditionLinks) { |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 35 | conditionKeys.insert(std::make_pair(link.condition(), |
| 36 | getDimensionKeysForCondition(event, link))); |
Yao Chen | b704177 | 2017-10-20 16:59:25 -0700 | [diff] [blame] | 37 | } |
| 38 | if (mWizard->query(mConditionTrackerIndex, conditionKeys) != ConditionState::kTrue) { |
| 39 | condition = false; |
| 40 | } else { |
| 41 | condition = true; |
| 42 | } |
| 43 | } else { |
| 44 | condition = mCondition; |
| 45 | } |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 46 | |
| 47 | if (mDimensions.child_size() > 0) { |
| 48 | vector<DimensionsValue> dimensionValues = getDimensionKeys(event, mDimensions); |
| 49 | for (const DimensionsValue& dimensionValue : dimensionValues) { |
| 50 | onMatchedLogEventInternalLocked( |
| 51 | matcherIndex, HashableDimensionKey(dimensionValue), conditionKeys, condition, event); |
| 52 | } |
| 53 | } else { |
| 54 | onMatchedLogEventInternalLocked( |
| 55 | matcherIndex, DEFAULT_DIMENSION_KEY, conditionKeys, condition, event); |
| 56 | } |
Yao Chen | b704177 | 2017-10-20 16:59:25 -0700 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | } // namespace statsd |
| 60 | } // namespace os |
yro | 2b0f886 | 2017-11-06 14:27:31 -0800 | [diff] [blame] | 61 | } // namespace android |