| Lais Andrade | 159eb6a | 2020-06-24 15:11:05 +0000 | [diff] [blame] | 1 | /* | 
|  | 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 |  | 
|  | 26 | using android::hardware::power::Boost; | 
|  | 27 | using android::hardware::power::Mode; | 
|  | 28 | using android::power::PowerHalController; | 
|  | 29 |  | 
|  | 30 | using namespace android; | 
|  | 31 |  | 
|  | 32 | static void BM_PowerHalControllerBenchmarks_init(benchmark::State& state) { | 
|  | 33 | while (state.KeepRunning()) { | 
|  | 34 | PowerHalController controller; | 
|  | 35 | controller.init(); | 
|  | 36 | } | 
|  | 37 | } | 
|  | 38 |  | 
|  | 39 | static 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 |  | 
|  | 49 | static void BM_PowerHalControllerBenchmarks_setBoost(benchmark::State& state) { | 
|  | 50 | while (state.KeepRunning()) { | 
|  | 51 | PowerHalController controller; | 
|  | 52 | controller.setBoost(Boost::INTERACTION, 0); | 
|  | 53 | } | 
|  | 54 | } | 
|  | 55 |  | 
|  | 56 | static 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 |  | 
|  | 66 | static void BM_PowerHalControllerBenchmarks_setMode(benchmark::State& state) { | 
|  | 67 | while (state.KeepRunning()) { | 
|  | 68 | PowerHalController controller; | 
|  | 69 | controller.setMode(Mode::INTERACTIVE, false); | 
|  | 70 | } | 
|  | 71 | } | 
|  | 72 |  | 
|  | 73 | static 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 |  | 
|  | 83 | BENCHMARK(BM_PowerHalControllerBenchmarks_init); | 
|  | 84 | BENCHMARK(BM_PowerHalControllerBenchmarks_initCached); | 
|  | 85 | BENCHMARK(BM_PowerHalControllerBenchmarks_setBoost); | 
|  | 86 | BENCHMARK(BM_PowerHalControllerBenchmarks_setBoostCached); | 
|  | 87 | BENCHMARK(BM_PowerHalControllerBenchmarks_setMode); | 
|  | 88 | BENCHMARK(BM_PowerHalControllerBenchmarks_setModeCached); |