blob: 4ed8289ab133dcd1cc77c8a457c8370507ce046f [file] [log] [blame]
Yao Chenb7041772017-10-20 16:59:25 -07001/*
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
Chenjie Yua7259ab2017-12-10 08:31:05 -080024void MetricProducer::onMatchedLogEventLocked(const size_t matcherIndex, const LogEvent& event) {
Yao Chenb7041772017-10-20 16:59:25 -070025 uint64_t eventTimeNs = event.GetTimestampNs();
26 // this is old event, maybe statsd restarted?
27 if (eventTimeNs < mStartTimeNs) {
28 return;
29 }
30
Yao Chenb7041772017-10-20 16:59:25 -070031 bool condition;
Yangster-mac20877162017-12-22 17:19:39 -080032 map<string, std::vector<HashableDimensionKey>> conditionKeys;
Yao Chenb7041772017-10-20 16:59:25 -070033 if (mConditionSliced) {
34 for (const auto& link : mConditionLinks) {
Yangster-mac20877162017-12-22 17:19:39 -080035 conditionKeys.insert(std::make_pair(link.condition(),
36 getDimensionKeysForCondition(event, link)));
Yao Chenb7041772017-10-20 16:59:25 -070037 }
38 if (mWizard->query(mConditionTrackerIndex, conditionKeys) != ConditionState::kTrue) {
39 condition = false;
40 } else {
41 condition = true;
42 }
43 } else {
44 condition = mCondition;
45 }
Yangster-mac20877162017-12-22 17:19:39 -080046
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 Chenb7041772017-10-20 16:59:25 -070057}
58
59} // namespace statsd
60} // namespace os
yro2b0f8862017-11-06 14:27:31 -080061} // namespace android