Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 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 | |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 17 | #define DEBUG true // STOPSHIP if true |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame^] | 18 | #include "Log.h" |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 19 | |
| 20 | #include "SimpleLogMatchingTracker.h" |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame^] | 21 | |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 22 | #include <log/logprint.h> |
| 23 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame^] | 24 | namespace android { |
| 25 | namespace os { |
| 26 | namespace statsd { |
| 27 | |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 28 | using std::string; |
| 29 | using std::unique_ptr; |
| 30 | using std::unordered_map; |
| 31 | using std::vector; |
| 32 | |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 33 | |
| 34 | SimpleLogMatchingTracker::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 | |
| 43 | SimpleLogMatchingTracker::~SimpleLogMatchingTracker() { |
| 44 | } |
| 45 | |
| 46 | bool 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 | |
| 54 | void 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 |