blob: 423da5bd3cf8a3423bfb0acc66f4db70a57d8a55 [file] [log] [blame]
Yao Chencaf339d2017-10-06 16:01:10 -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
Yao Chen729093d2017-10-16 10:33:26 -070017#define DEBUG false // STOPSHIP if true
Joe Onorato9fc9edf2017-10-15 20:08:52 -070018#include "Log.h"
Yao Chencaf339d2017-10-06 16:01:10 -070019
Salud Lemusf63fa892020-08-12 00:56:58 +000020#include "SimpleAtomMatchingTracker.h"
Joe Onorato9fc9edf2017-10-15 20:08:52 -070021
Joe Onorato9fc9edf2017-10-15 20:08:52 -070022namespace android {
23namespace os {
24namespace statsd {
25
Yao Chencaf339d2017-10-06 16:01:10 -070026using std::unordered_map;
27using std::vector;
28
Salud Lemusf63fa892020-08-12 00:56:58 +000029SimpleAtomMatchingTracker::SimpleAtomMatchingTracker(const int64_t& id, const int index,
30 const uint64_t protoHash,
31 const SimpleAtomMatcher& matcher,
32 const sp<UidMap>& uidMap)
33 : AtomMatchingTracker(id, index, protoHash), mMatcher(matcher), mUidMap(uidMap) {
Yangster-mac20877162017-12-22 17:19:39 -080034 if (!matcher.has_atom_id()) {
Yao Chen729093d2017-10-16 10:33:26 -070035 mInitialized = false;
36 } else {
Yangster-mac20877162017-12-22 17:19:39 -080037 mAtomIds.insert(matcher.atom_id());
Yao Chen729093d2017-10-16 10:33:26 -070038 mInitialized = true;
Yao Chencaf339d2017-10-06 16:01:10 -070039 }
Yao Chencaf339d2017-10-06 16:01:10 -070040}
41
Salud Lemusf63fa892020-08-12 00:56:58 +000042SimpleAtomMatchingTracker::~SimpleAtomMatchingTracker() {
Yao Chencaf339d2017-10-06 16:01:10 -070043}
44
Salud Lemusf63fa892020-08-12 00:56:58 +000045bool SimpleAtomMatchingTracker::init(const vector<AtomMatcher>& allAtomMatchers,
46 const vector<sp<AtomMatchingTracker>>& allAtomMatchingTrackers,
47 const unordered_map<int64_t, int>& matcherMap,
48 vector<bool>& stack) {
Yao Chencaf339d2017-10-06 16:01:10 -070049 // no need to do anything.
Yao Chen729093d2017-10-16 10:33:26 -070050 return mInitialized;
Yao Chencaf339d2017-10-06 16:01:10 -070051}
52
Tej Singh090ffd72020-08-17 20:27:17 -070053bool SimpleAtomMatchingTracker::onConfigUpdated(
54 const AtomMatcher& matcher, const int index,
55 const unordered_map<int64_t, int>& atomMatchingTrackerMap) {
56 mIndex = index;
57 // Do not need to update mMatcher since the matcher must be identical across the update.
58 return mInitialized;
59}
60
Salud Lemusf63fa892020-08-12 00:56:58 +000061void SimpleAtomMatchingTracker::onLogEvent(
62 const LogEvent& event, const vector<sp<AtomMatchingTracker>>& allAtomMatchingTrackers,
63 vector<MatchingState>& matcherResults) {
Yao Chencaf339d2017-10-06 16:01:10 -070064 if (matcherResults[mIndex] != MatchingState::kNotComputed) {
Yangster-mac94e197c2018-01-02 16:03:03 -080065 VLOG("Matcher %lld already evaluated ", (long long)mId);
Yao Chencaf339d2017-10-06 16:01:10 -070066 return;
67 }
68
Yangster-mac20877162017-12-22 17:19:39 -080069 if (mAtomIds.find(event.GetTagId()) == mAtomIds.end()) {
Yao Chencaf339d2017-10-06 16:01:10 -070070 matcherResults[mIndex] = MatchingState::kNotMatched;
71 return;
72 }
73
Yangster-mac20877162017-12-22 17:19:39 -080074 bool matched = matchesSimple(mUidMap, mMatcher, event);
Yao Chencaf339d2017-10-06 16:01:10 -070075 matcherResults[mIndex] = matched ? MatchingState::kMatched : MatchingState::kNotMatched;
Salud Lemus8d213db2020-08-15 02:53:56 +000076 VLOG("Stats SimpleAtomMatcher %lld matched? %d", (long long)mId, matched);
Yao Chencaf339d2017-10-06 16:01:10 -070077}
78
79} // namespace statsd
80} // namespace os
81} // namespace android