blob: beb90155f183084d4d37bc44dea9110901505874 [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 */
Yao Chenb7041772017-10-20 16:59:25 -070016
Yao Chen8a8d16c2018-02-08 14:50:40 -080017#define DEBUG true // STOPSHIP if true
18#include "Log.h"
19#include "MetricProducer.h"
Yangster-mac93694462018-01-22 20:49:31 -080020
Yao Chenb7041772017-10-20 16:59:25 -070021namespace android {
22namespace os {
23namespace statsd {
24
25using std::map;
26
Chenjie Yua7259ab2017-12-10 08:31:05 -080027void MetricProducer::onMatchedLogEventLocked(const size_t matcherIndex, const LogEvent& event) {
Yao Chenb7041772017-10-20 16:59:25 -070028 uint64_t eventTimeNs = event.GetTimestampNs();
29 // this is old event, maybe statsd restarted?
30 if (eventTimeNs < mStartTimeNs) {
31 return;
32 }
33
Yao Chenb7041772017-10-20 16:59:25 -070034 bool condition;
Yangster-mac94e197c2018-01-02 16:03:03 -080035 ConditionKey conditionKey;
Yangster-mac93694462018-01-22 20:49:31 -080036
37 std::unordered_set<HashableDimensionKey> dimensionKeysInCondition;
Yao Chenb7041772017-10-20 16:59:25 -070038 if (mConditionSliced) {
Yao Chen8a8d16c2018-02-08 14:50:40 -080039 for (const auto& link : mMetric2ConditionLinks) {
40 getDimensionForCondition(event, link, &conditionKey[link.conditionId]);
Yao Chenb7041772017-10-20 16:59:25 -070041 }
Yao Chen8a8d16c2018-02-08 14:50:40 -080042
Yangster-mac93694462018-01-22 20:49:31 -080043 auto conditionState =
44 mWizard->query(mConditionTrackerIndex, conditionKey, mDimensionsInCondition,
45 &dimensionKeysInCondition);
46 condition = (conditionState == ConditionState::kTrue);
Yao Chenb7041772017-10-20 16:59:25 -070047 } else {
48 condition = mCondition;
49 }
Yangster-mac20877162017-12-22 17:19:39 -080050
Yao Chen8a8d16c2018-02-08 14:50:40 -080051 vector<HashableDimensionKey> dimensionInWhatValues;
52 if (mDimensionsInWhat.size() > 0) {
53 filterValues(mDimensionsInWhat, event.getValues(), &dimensionInWhatValues);
Yangster-mac93694462018-01-22 20:49:31 -080054 }
55
56 if (dimensionInWhatValues.empty() && dimensionKeysInCondition.empty()) {
57 onMatchedLogEventInternalLocked(
58 matcherIndex, DEFAULT_METRIC_DIMENSION_KEY, conditionKey, condition, event);
59 } else if (dimensionKeysInCondition.empty()) {
Yao Chen8a8d16c2018-02-08 14:50:40 -080060 for (const HashableDimensionKey& whatValue : dimensionInWhatValues) {
61 onMatchedLogEventInternalLocked(matcherIndex,
62 MetricDimensionKey(whatValue, DEFAULT_DIMENSION_KEY),
63 conditionKey, condition, event);
Yangster-mac93694462018-01-22 20:49:31 -080064 }
65 } else if (dimensionInWhatValues.empty()) {
66 for (const auto& conditionDimensionKey : dimensionKeysInCondition) {
67 onMatchedLogEventInternalLocked(
68 matcherIndex,
69 MetricDimensionKey(DEFAULT_DIMENSION_KEY, conditionDimensionKey),
70 conditionKey, condition, event);
Yangster-mac20877162017-12-22 17:19:39 -080071 }
72 } else {
Yao Chen8a8d16c2018-02-08 14:50:40 -080073 for (const auto& whatValue : dimensionInWhatValues) {
Yangster-mac93694462018-01-22 20:49:31 -080074 for (const auto& conditionDimensionKey : dimensionKeysInCondition) {
75 onMatchedLogEventInternalLocked(
Yao Chen8a8d16c2018-02-08 14:50:40 -080076 matcherIndex, MetricDimensionKey(whatValue, conditionDimensionKey),
77 conditionKey, condition, event);
Yangster-mac93694462018-01-22 20:49:31 -080078 }
79 }
Yangster-mac20877162017-12-22 17:19:39 -080080 }
Yao Chenb7041772017-10-20 16:59:25 -070081}
82
83} // namespace statsd
84} // namespace os
yro2b0f8862017-11-06 14:27:31 -080085} // namespace android