blob: 91ef0344da910caedd4d4223decd6351a605cbe2 [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::string;
27using std::unique_ptr;
28using std::unordered_map;
29using std::vector;
30
Yao Chencaf339d2017-10-06 16:01:10 -070031
32SimpleLogMatchingTracker::SimpleLogMatchingTracker(const string& name, const int index,
Yangster-mac20877162017-12-22 17:19:39 -080033 const SimpleAtomMatcher& matcher,
34 const UidMap& uidMap)
35 : LogMatchingTracker(name, index), mMatcher(matcher), mUidMap(uidMap) {
36 if (!matcher.has_atom_id()) {
Yao Chen729093d2017-10-16 10:33:26 -070037 mInitialized = false;
38 } else {
Yangster-mac20877162017-12-22 17:19:39 -080039 mAtomIds.insert(matcher.atom_id());
Yao Chen729093d2017-10-16 10:33:26 -070040 mInitialized = true;
Yao Chencaf339d2017-10-06 16:01:10 -070041 }
Yao Chencaf339d2017-10-06 16:01:10 -070042}
43
44SimpleLogMatchingTracker::~SimpleLogMatchingTracker() {
45}
46
Stefan Lafonb8c9aa82017-12-03 14:27:25 -080047bool SimpleLogMatchingTracker::init(const vector<AtomMatcher>& allLogMatchers,
Yao Chencaf339d2017-10-06 16:01:10 -070048 const vector<sp<LogMatchingTracker>>& allTrackers,
49 const unordered_map<string, int>& matcherMap,
50 vector<bool>& stack) {
51 // no need to do anything.
Yao Chen729093d2017-10-16 10:33:26 -070052 return mInitialized;
Yao Chencaf339d2017-10-06 16:01:10 -070053}
54
Joe Onoratoc4dfae52017-10-17 23:38:21 -070055void SimpleLogMatchingTracker::onLogEvent(const LogEvent& event,
Yao Chencaf339d2017-10-06 16:01:10 -070056 const vector<sp<LogMatchingTracker>>& allTrackers,
57 vector<MatchingState>& matcherResults) {
58 if (matcherResults[mIndex] != MatchingState::kNotComputed) {
59 VLOG("Matcher %s already evaluated ", mName.c_str());
60 return;
61 }
62
Yangster-mac20877162017-12-22 17:19:39 -080063 if (mAtomIds.find(event.GetTagId()) == mAtomIds.end()) {
Yao Chencaf339d2017-10-06 16:01:10 -070064 matcherResults[mIndex] = MatchingState::kNotMatched;
65 return;
66 }
67
Yangster-mac20877162017-12-22 17:19:39 -080068 bool matched = matchesSimple(mUidMap, mMatcher, event);
Yao Chencaf339d2017-10-06 16:01:10 -070069 matcherResults[mIndex] = matched ? MatchingState::kMatched : MatchingState::kNotMatched;
70 VLOG("Stats SimpleLogMatcher %s matched? %d", mName.c_str(), matched);
71}
72
73} // namespace statsd
74} // namespace os
75} // namespace android