blob: e74924a81fbf66665cb820b3142873538be08d55 [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-mac94e197c2018-01-02 16:03:03 -080032 ConditionKey conditionKey;
Yao Chenb7041772017-10-20 16:59:25 -070033 if (mConditionSliced) {
34 for (const auto& link : mConditionLinks) {
Yangster-mac7ba8fc32018-01-24 16:16:46 -080035 getDimensionKeysForCondition(event, link, &conditionKey[link.condition()]);
Yao Chenb7041772017-10-20 16:59:25 -070036 }
Yangster-mac94e197c2018-01-02 16:03:03 -080037 if (mWizard->query(mConditionTrackerIndex, conditionKey) != ConditionState::kTrue) {
Yao Chenb7041772017-10-20 16:59:25 -070038 condition = false;
39 } else {
40 condition = true;
41 }
42 } else {
43 condition = mCondition;
44 }
Yangster-mac20877162017-12-22 17:19:39 -080045
Yangster-mac7ba8fc32018-01-24 16:16:46 -080046 if (mDimensions.has_field() && mDimensions.child_size() > 0) {
47 vector<DimensionsValue> dimensionValues;
48 getDimensionKeys(event, mDimensions, &dimensionValues);
Yangster-mac20877162017-12-22 17:19:39 -080049 for (const DimensionsValue& dimensionValue : dimensionValues) {
50 onMatchedLogEventInternalLocked(
Yangster-mac94e197c2018-01-02 16:03:03 -080051 matcherIndex, HashableDimensionKey(dimensionValue), conditionKey, condition, event);
Yangster-mac20877162017-12-22 17:19:39 -080052 }
53 } else {
54 onMatchedLogEventInternalLocked(
Yangster-mac94e197c2018-01-02 16:03:03 -080055 matcherIndex, DEFAULT_DIMENSION_KEY, conditionKey, condition, event);
Yangster-mac20877162017-12-22 17:19:39 -080056 }
Yao Chenb7041772017-10-20 16:59:25 -070057}
58
59} // namespace statsd
60} // namespace os
yro2b0f8862017-11-06 14:27:31 -080061} // namespace android