1 /*
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
17 #define DEBUG false // STOPSHIP if true
18 #include "Log.h"
19
20 #include "SimpleLogMatchingTracker.h"
21
22 namespace android {
23 namespace os {
24 namespace statsd {
25
26 using std::string;
27 using std::unique_ptr;
28 using std::unordered_map;
29 using std::vector;
30
31
SimpleLogMatchingTracker(const int64_t & id,const int index,const SimpleAtomMatcher & matcher,const UidMap & uidMap)32 SimpleLogMatchingTracker::SimpleLogMatchingTracker(const int64_t& id, const int index,
33 const SimpleAtomMatcher& matcher,
34 const UidMap& uidMap)
35 : LogMatchingTracker(id, index), mMatcher(matcher), mUidMap(uidMap) {
36 if (!matcher.has_atom_id()) {
37 mInitialized = false;
38 } else {
39 mAtomIds.insert(matcher.atom_id());
40 mInitialized = true;
41 }
42 }
43
~SimpleLogMatchingTracker()44 SimpleLogMatchingTracker::~SimpleLogMatchingTracker() {
45 }
46
init(const vector<AtomMatcher> & allLogMatchers,const vector<sp<LogMatchingTracker>> & allTrackers,const unordered_map<int64_t,int> & matcherMap,vector<bool> & stack)47 bool SimpleLogMatchingTracker::init(const vector<AtomMatcher>& allLogMatchers,
48 const vector<sp<LogMatchingTracker>>& allTrackers,
49 const unordered_map<int64_t, int>& matcherMap,
50 vector<bool>& stack) {
51 // no need to do anything.
52 return mInitialized;
53 }
54
onLogEvent(const LogEvent & event,const vector<sp<LogMatchingTracker>> & allTrackers,vector<MatchingState> & matcherResults)55 void SimpleLogMatchingTracker::onLogEvent(const LogEvent& event,
56 const vector<sp<LogMatchingTracker>>& allTrackers,
57 vector<MatchingState>& matcherResults) {
58 if (matcherResults[mIndex] != MatchingState::kNotComputed) {
59 VLOG("Matcher %lld already evaluated ", (long long)mId);
60 return;
61 }
62
63 if (mAtomIds.find(event.GetTagId()) == mAtomIds.end()) {
64 matcherResults[mIndex] = MatchingState::kNotMatched;
65 return;
66 }
67
68 bool matched = matchesSimple(mUidMap, mMatcher, event);
69 matcherResults[mIndex] = matched ? MatchingState::kMatched : MatchingState::kNotMatched;
70 VLOG("Stats SimpleLogMatcher %lld matched? %d", (long long)mId, matched);
71 }
72
73 } // namespace statsd
74 } // namespace os
75 } // namespace android
76