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
18 #include "FieldValue.h"
19 #include "HashableDimensionKey.h"
20 #include "benchmark/benchmark.h"
21 #include "logd/LogEvent.h"
22 #include "metric_util.h"
23 #include "stats_event.h"
24 #include "stats_log_util.h"
25
26 namespace android {
27 namespace os {
28 namespace statsd {
29
30 using std::vector;
31
createLogEventAndLink(LogEvent * event,Metric2Condition * link)32 static void createLogEventAndLink(LogEvent* event, Metric2Condition *link) {
33 AStatsEvent* statsEvent = AStatsEvent_obtain();
34 AStatsEvent_setAtomId(statsEvent, 1);
35 AStatsEvent_overwriteTimestamp(statsEvent, 100000);
36
37 std::vector<int> attributionUids = {100, 100};
38 std::vector<string> attributionTags = {"LOCATION", "LOCATION"};
39 writeAttribution(statsEvent, attributionUids, attributionTags);
40
41 AStatsEvent_writeFloat(statsEvent, 3.2f);
42 AStatsEvent_writeString(statsEvent, "LOCATION");
43 AStatsEvent_writeInt64(statsEvent, 990);
44
45 parseStatsEventToLogEvent(statsEvent, event);
46
47 link->conditionId = 1;
48
49 FieldMatcher field_matcher;
50 field_matcher.set_field(event->GetTagId());
51 auto child = field_matcher.add_child();
52 child->set_field(1);
53 child->set_position(FIRST);
54 child->add_child()->set_field(1);
55
56 translateFieldMatcher(field_matcher, &link->metricFields);
57 field_matcher.set_field(event->GetTagId() + 1);
58 translateFieldMatcher(field_matcher, &link->conditionFields);
59 }
60
BM_GetDimensionInCondition(benchmark::State & state)61 static void BM_GetDimensionInCondition(benchmark::State& state) {
62 Metric2Condition link;
63 LogEvent event(/*uid=*/0, /*pid=*/0);
64 createLogEventAndLink(&event, &link);
65
66 while (state.KeepRunning()) {
67 HashableDimensionKey output;
68 getDimensionForCondition(event.getValues(), link, &output);
69 }
70 }
71
72 BENCHMARK(BM_GetDimensionInCondition);
73
74
75 } // namespace statsd
76 } // namespace os
77 } // namespace android
78