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 <statslog_statsdtest.h>
17
18 #include "benchmark/benchmark.h"
19
20 namespace android {
21 namespace os {
22 namespace statsd {
23
BM_StatsEventObtain(benchmark::State & state)24 static void BM_StatsEventObtain(benchmark::State& state) {
25 while (state.KeepRunning()) {
26 AStatsEvent* event = AStatsEvent_obtain();
27 benchmark::DoNotOptimize(event);
28 AStatsEvent_release(event);
29 }
30 }
31 BENCHMARK(BM_StatsEventObtain);
32
BM_StatsWrite(benchmark::State & state)33 static void BM_StatsWrite(benchmark::State& state) {
34 int32_t parent_uid = 0;
35 int32_t isolated_uid = 100;
36 int32_t event = 1;
37 while (state.KeepRunning()) {
38 util::stats_write(util::ISOLATED_UID_CHANGED, parent_uid, isolated_uid, event++);
39 }
40 }
41 BENCHMARK(BM_StatsWrite);
42
BM_StatsWriteViaQueue(benchmark::State & state)43 static void BM_StatsWriteViaQueue(benchmark::State& state) {
44 // writes dedicated atom which known to be put into the queue for the test purpose
45 int32_t uid = 0;
46 int32_t label = 100;
47 int32_t a_state = 1;
48 while (state.KeepRunning()) {
49 benchmark::DoNotOptimize(
50 util::stats_write(util::APP_BREADCRUMB_REPORTED, uid, label, a_state++));
51 }
52 }
53 BENCHMARK(BM_StatsWriteViaQueue);
54
55 } // namespace statsd
56 } // namespace os
57 } // namespace android
58