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 | |
| 24 | void MetricProducer::onMatchedLogEvent(const size_t matcherIndex, const LogEvent& event) { |
| 25 | uint64_t eventTimeNs = event.GetTimestampNs(); |
| 26 | // this is old event, maybe statsd restarted? |
| 27 | if (eventTimeNs < mStartTimeNs) { |
| 28 | return; |
| 29 | } |
| 30 | |
| 31 | HashableDimensionKey eventKey; |
| 32 | |
| 33 | if (mDimension.size() > 0) { |
| 34 | vector<KeyValuePair> key = getDimensionKey(event, mDimension); |
| 35 | eventKey = getHashableKey(key); |
| 36 | // Add the HashableDimensionKey->vector<KeyValuePair> to the map, because StatsLogReport |
| 37 | // expects vector<KeyValuePair>. |
| 38 | if (mDimensionKeyMap.find(eventKey) == mDimensionKeyMap.end()) { |
| 39 | mDimensionKeyMap[eventKey] = key; |
| 40 | } |
| 41 | } else { |
| 42 | eventKey = DEFAULT_DIMENSION_KEY; |
| 43 | } |
| 44 | |
| 45 | bool condition; |
| 46 | |
| 47 | map<string, HashableDimensionKey> conditionKeys; |
| 48 | if (mConditionSliced) { |
| 49 | for (const auto& link : mConditionLinks) { |
| 50 | HashableDimensionKey conditionKey = getDimensionKeyForCondition(event, link); |
| 51 | conditionKeys[link.condition()] = conditionKey; |
| 52 | } |
| 53 | if (mWizard->query(mConditionTrackerIndex, conditionKeys) != ConditionState::kTrue) { |
| 54 | condition = false; |
| 55 | } else { |
| 56 | condition = true; |
| 57 | } |
| 58 | } else { |
| 59 | condition = mCondition; |
| 60 | } |
| 61 | |
| 62 | onMatchedLogEventInternal(matcherIndex, eventKey, conditionKeys, condition, event); |
| 63 | } |
| 64 | |
| 65 | } // namespace statsd |
| 66 | } // namespace os |
| 67 | } // namespace android |