1/* 2 * Copyright (C) 2018 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#include <vector> 17#include "benchmark/benchmark.h" 18#include "FieldValue.h" 19#include "HashableDimensionKey.h" 20#include "logd/LogEvent.h" 21#include "stats_log_util.h" 22 23namespace android { 24namespace os { 25namespace statsd { 26 27using std::vector; 28 29static void createLogEventAndMatcher(LogEvent* event, FieldMatcher *field_matcher) { 30 AttributionNodeInternal node; 31 node.set_uid(100); 32 node.set_tag("LOCATION"); 33 34 std::vector<AttributionNodeInternal> nodes = {node, node}; 35 event->write(nodes); 36 event->write(3.2f); 37 event->write("LOCATION"); 38 event->write((int64_t)990); 39 event->init(); 40 41 field_matcher->set_field(1); 42 auto child = field_matcher->add_child(); 43 child->set_field(1); 44 child->set_position(FIRST); 45 child->add_child()->set_field(1); 46} 47 48static void BM_FilterValue(benchmark::State& state) { 49 LogEvent event(1, 100000); 50 FieldMatcher field_matcher; 51 createLogEventAndMatcher(&event, &field_matcher); 52 53 std::vector<Matcher> matchers; 54 translateFieldMatcher(field_matcher, &matchers); 55 56 while (state.KeepRunning()) { 57 HashableDimensionKey output; 58 filterValues(matchers, event.getValues(), &output); 59 } 60} 61 62BENCHMARK(BM_FilterValue); 63 64} // namespace statsd 65} // namespace os 66} // namespace android 67