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 | |
| 17 | #define LOG_TAG "SimpleLogMatchingTracker" |
| 18 | #define DEBUG true // STOPSHIP if true |
| 19 | #define VLOG(...) \ |
| 20 | if (DEBUG) ALOGD(__VA_ARGS__); |
| 21 | |
| 22 | #include "SimpleLogMatchingTracker.h" |
| 23 | #include <cutils/log.h> |
| 24 | #include <log/logprint.h> |
| 25 | |
| 26 | using std::string; |
| 27 | using std::unique_ptr; |
| 28 | using std::unordered_map; |
| 29 | using std::vector; |
| 30 | |
| 31 | namespace android { |
| 32 | namespace os { |
| 33 | namespace statsd { |
| 34 | |
| 35 | SimpleLogMatchingTracker::SimpleLogMatchingTracker(const string& name, const int index, |
| 36 | const SimpleLogEntryMatcher& matcher) |
| 37 | : LogMatchingTracker(name, index), mMatcher(matcher) { |
| 38 | for (int i = 0; i < matcher.tag_size(); i++) { |
| 39 | mTagIds.insert(matcher.tag(i)); |
| 40 | } |
| 41 | mInitialized = true; |
| 42 | } |
| 43 | |
| 44 | SimpleLogMatchingTracker::~SimpleLogMatchingTracker() { |
| 45 | } |
| 46 | |
| 47 | bool SimpleLogMatchingTracker::init(const vector<LogEntryMatcher>& allLogMatchers, |
| 48 | const vector<sp<LogMatchingTracker>>& allTrackers, |
| 49 | const unordered_map<string, int>& matcherMap, |
| 50 | vector<bool>& stack) { |
| 51 | // no need to do anything. |
| 52 | return true; |
| 53 | } |
| 54 | |
| 55 | void SimpleLogMatchingTracker::onLogEvent(const LogEventWrapper& event, |
| 56 | 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 | |
| 63 | if (mTagIds.find(event.tagId) == mTagIds.end()) { |
| 64 | matcherResults[mIndex] = MatchingState::kNotMatched; |
| 65 | return; |
| 66 | } |
| 67 | |
| 68 | bool matched = matchesSimple(mMatcher, event); |
| 69 | 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 |