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 createLogEventAndLink(LogEvent* event, Metric2Condition *link) { 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 link->conditionId = 1; 42 43 FieldMatcher field_matcher; 44 field_matcher.set_field(event->GetTagId()); 45 auto child = field_matcher.add_child(); 46 child->set_field(1); 47 child->set_position(FIRST); 48 child->add_child()->set_field(1); 49 50 translateFieldMatcher(field_matcher, &link->metricFields); 51 field_matcher.set_field(event->GetTagId() + 1); 52 translateFieldMatcher(field_matcher, &link->conditionFields); 53} 54 55static void BM_GetDimensionInCondition(benchmark::State& state) { 56 Metric2Condition link; 57 LogEvent event(1, 100000); 58 createLogEventAndLink(&event, &link); 59 60 while (state.KeepRunning()) { 61 HashableDimensionKey output; 62 getDimensionForCondition(event.getValues(), link, &output); 63 } 64} 65 66BENCHMARK(BM_GetDimensionInCondition); 67 68 69} // namespace statsd 70} // namespace os 71} // namespace android 72