blob: 082daf5a1916b27378e9d2d10b3b7b42f06722df [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
20#include "SimpleLogMatchingTracker.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
Yao Chencaf339d2017-10-06 16:01:10 -070029
Yangster-mac94e197c2018-01-02 16:03:03 -080030SimpleLogMatchingTracker::SimpleLogMatchingTracker(const int64_t& id, const int index,
Yangster-mac20877162017-12-22 17:19:39 -080031 const SimpleAtomMatcher& matcher,
32 const UidMap& uidMap)
Yangster-mac94e197c2018-01-02 16:03:03 -080033 : LogMatchingTracker(id, index), 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
42SimpleLogMatchingTracker::~SimpleLogMatchingTracker() {
43}
44
Stefan Lafonb8c9aa82017-12-03 14:27:25 -080045bool SimpleLogMatchingTracker::init(const vector<AtomMatcher>& allLogMatchers,
Yao Chencaf339d2017-10-06 16:01:10 -070046 const vector<sp<LogMatchingTracker>>& allTrackers,
Yangster-mac94e197c2018-01-02 16:03:03 -080047 const unordered_map<int64_t, int>& matcherMap,
Yao Chencaf339d2017-10-06 16:01:10 -070048 vector<bool>& stack) {
49 // no need to do anything.
Yao Chen729093d2017-10-16 10:33:26 -070050 return mInitialized;
Yao Chencaf339d2017-10-06 16:01:10 -070051}
52
Joe Onoratoc4dfae52017-10-17 23:38:21 -070053void SimpleLogMatchingTracker::onLogEvent(const LogEvent& event,
Yao Chencaf339d2017-10-06 16:01:10 -070054 const vector<sp<LogMatchingTracker>>& allTrackers,
55 vector<MatchingState>& matcherResults) {
56 if (matcherResults[mIndex] != MatchingState::kNotComputed) {
Yangster-mac94e197c2018-01-02 16:03:03 -080057 VLOG("Matcher %lld already evaluated ", (long long)mId);
Yao Chencaf339d2017-10-06 16:01:10 -070058 return;
59 }
60
Yangster-mac20877162017-12-22 17:19:39 -080061 if (mAtomIds.find(event.GetTagId()) == mAtomIds.end()) {
Yao Chencaf339d2017-10-06 16:01:10 -070062 matcherResults[mIndex] = MatchingState::kNotMatched;
63 return;
64 }
65
Yangster-mac20877162017-12-22 17:19:39 -080066 bool matched = matchesSimple(mUidMap, mMatcher, event);
Yao Chencaf339d2017-10-06 16:01:10 -070067 matcherResults[mIndex] = matched ? MatchingState::kMatched : MatchingState::kNotMatched;
Yangster-mac94e197c2018-01-02 16:03:03 -080068 VLOG("Stats SimpleLogMatcher %lld matched? %d", (long long)mId, matched);
Yao Chencaf339d2017-10-06 16:01:10 -070069}
70
71} // namespace statsd
72} // namespace os
73} // namespace android