blob: 3c8ce6e7dd1c0e442d8878a737dcf1f307217611 [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
24void 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