MetricProducer.cpp revision 2087716f2bdca90c7c3034d556ac12911bd8018e
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 18namespace android { 19namespace os { 20namespace statsd { 21 22using std::map; 23 24void MetricProducer::onMatchedLogEventLocked(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 bool condition; 32 map<string, std::vector<HashableDimensionKey>> conditionKeys; 33 if (mConditionSliced) { 34 for (const auto& link : mConditionLinks) { 35 conditionKeys.insert(std::make_pair(link.condition(), 36 getDimensionKeysForCondition(event, link))); 37 } 38 if (mWizard->query(mConditionTrackerIndex, conditionKeys) != ConditionState::kTrue) { 39 condition = false; 40 } else { 41 condition = true; 42 } 43 } else { 44 condition = mCondition; 45 } 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 } 57} 58 59} // namespace statsd 60} // namespace os 61} // namespace android 62