SimpleLogMatchingTracker.cpp revision 9fc9edf95a308f5884bf541cac81ce1f41aba0ba
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 true // STOPSHIP if true 18#include "Log.h" 19 20#include "SimpleLogMatchingTracker.h" 21 22#include <log/logprint.h> 23 24namespace android { 25namespace os { 26namespace statsd { 27 28using std::string; 29using std::unique_ptr; 30using std::unordered_map; 31using std::vector; 32 33 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 75