blob: 815baf77e5a5304305b7babc9329851cd9ded03b [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 Chencaf339d2017-10-06 16:01:10 -070017#define DEBUG true // 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
Yao Chencaf339d2017-10-06 16:01:10 -070022#include <log/logprint.h>
23
Joe Onorato9fc9edf2017-10-15 20:08:52 -070024namespace android {
25namespace os {
26namespace statsd {
27
Yao Chencaf339d2017-10-06 16:01:10 -070028using std::string;
29using std::unique_ptr;
30using std::unordered_map;
31using std::vector;
32
Yao Chencaf339d2017-10-06 16:01:10 -070033
34SimpleLogMatchingTracker::SimpleLogMatchingTracker(const string& name, const int index,
35 const SimpleLogEntryMatcher& matcher)
36 : LogMatchingTracker(name, index), mMatcher(matcher) {
37 for (int i = 0; i < matcher.tag_size(); i++) {
38 mTagIds.insert(matcher.tag(i));
39 }
40 mInitialized = true;
41}
42
43SimpleLogMatchingTracker::~SimpleLogMatchingTracker() {
44}
45
46bool SimpleLogMatchingTracker::init(const vector<LogEntryMatcher>& allLogMatchers,
47 const vector<sp<LogMatchingTracker>>& allTrackers,
48 const unordered_map<string, int>& matcherMap,
49 vector<bool>& stack) {
50 // no need to do anything.
51 return true;
52}
53
54void SimpleLogMatchingTracker::onLogEvent(const LogEventWrapper& event,
55 const vector<sp<LogMatchingTracker>>& allTrackers,
56 vector<MatchingState>& matcherResults) {
57 if (matcherResults[mIndex] != MatchingState::kNotComputed) {
58 VLOG("Matcher %s already evaluated ", mName.c_str());
59 return;
60 }
61
62 if (mTagIds.find(event.tagId) == mTagIds.end()) {
63 matcherResults[mIndex] = MatchingState::kNotMatched;
64 return;
65 }
66
67 bool matched = matchesSimple(mMatcher, event);
68 matcherResults[mIndex] = matched ? MatchingState::kMatched : MatchingState::kNotMatched;
69 VLOG("Stats SimpleLogMatcher %s matched? %d", mName.c_str(), matched);
70}
71
72} // namespace statsd
73} // namespace os
74} // namespace android