blob: a3a1f4e171f680ac61a940807f332ff6c4c57a0c [file] [log] [blame]
Lais Andrade159eb6a2020-06-24 15:11:05 +00001/*
2 * Copyright (C) 2020 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 LOG_TAG "PowerHalControllerBenchmarks"
18
19#include <android/hardware/power/Boost.h>
20#include <android/hardware/power/Mode.h>
21
22#include <benchmark/benchmark.h>
23
24#include <powermanager/PowerHalController.h>
25
26using android::hardware::power::Boost;
27using android::hardware::power::Mode;
28using android::power::PowerHalController;
29
30using namespace android;
31
32static void BM_PowerHalControllerBenchmarks_init(benchmark::State& state) {
33 while (state.KeepRunning()) {
34 PowerHalController controller;
35 controller.init();
36 }
37}
38
39static void BM_PowerHalControllerBenchmarks_initCached(benchmark::State& state) {
40 PowerHalController controller;
41 // First connection out of test.
42 controller.init();
43
44 while (state.KeepRunning()) {
45 controller.init();
46 }
47}
48
49static void BM_PowerHalControllerBenchmarks_setBoost(benchmark::State& state) {
50 while (state.KeepRunning()) {
51 PowerHalController controller;
52 controller.setBoost(Boost::INTERACTION, 0);
53 }
54}
55
56static void BM_PowerHalControllerBenchmarks_setBoostCached(benchmark::State& state) {
57 PowerHalController controller;
58 // First call out of test, to cache supported boost.
59 controller.setBoost(Boost::INTERACTION, 0);
60
61 while (state.KeepRunning()) {
62 controller.setBoost(Boost::INTERACTION, 0);
63 }
64}
65
66static void BM_PowerHalControllerBenchmarks_setMode(benchmark::State& state) {
67 while (state.KeepRunning()) {
68 PowerHalController controller;
69 controller.setMode(Mode::INTERACTIVE, false);
70 }
71}
72
73static void BM_PowerHalControllerBenchmarks_setModeCached(benchmark::State& state) {
74 PowerHalController controller;
75 // First call out of test, to cache supported mode.
76 controller.setMode(Mode::INTERACTIVE, false);
77
78 while (state.KeepRunning()) {
79 controller.setMode(Mode::INTERACTIVE, false);
80 }
81}
82
83BENCHMARK(BM_PowerHalControllerBenchmarks_init);
84BENCHMARK(BM_PowerHalControllerBenchmarks_initCached);
85BENCHMARK(BM_PowerHalControllerBenchmarks_setBoost);
86BENCHMARK(BM_PowerHalControllerBenchmarks_setBoostCached);
87BENCHMARK(BM_PowerHalControllerBenchmarks_setMode);
88BENCHMARK(BM_PowerHalControllerBenchmarks_setModeCached);