| 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 "PowerHalHidlBenchmarks" | 
|  | 18 |  | 
|  | 19 | #include <android/hardware/power/1.1/IPower.h> | 
|  | 20 | #include <android/hardware/power/Boost.h> | 
|  | 21 | #include <android/hardware/power/IPower.h> | 
|  | 22 | #include <android/hardware/power/Mode.h> | 
|  | 23 |  | 
|  | 24 | #include <benchmark/benchmark.h> | 
|  | 25 |  | 
|  | 26 | #include <hardware/power.h> | 
|  | 27 | #include <hardware_legacy/power.h> | 
|  | 28 |  | 
|  | 29 | using android::hardware::power::Boost; | 
|  | 30 | using android::hardware::power::Mode; | 
|  | 31 | using android::hardware::power::V1_0::Feature; | 
|  | 32 | using android::hardware::power::V1_0::PowerHint; | 
|  | 33 | using IPower1_0 = android::hardware::power::V1_0::IPower; | 
|  | 34 | using IPower1_1 = android::hardware::power::V1_1::IPower; | 
|  | 35 |  | 
|  | 36 | using namespace android; | 
|  | 37 |  | 
|  | 38 | template <class R, class I, class... Args0, class... Args1> | 
|  | 39 | static void runBenchmark(benchmark::State& state, R (I::*fn)(Args0...), Args1&&... args1) { | 
|  | 40 | sp<I> hal = I::getService(); | 
|  | 41 |  | 
|  | 42 | if (hal == nullptr) { | 
|  | 43 | ALOGI("Power HAL HIDL not available, skipping test..."); | 
|  | 44 | return; | 
|  | 45 | } | 
|  | 46 |  | 
|  | 47 | while (state.KeepRunning()) { | 
|  | 48 | (*hal.*fn)(std::forward<Args1>(args1)...); | 
|  | 49 | } | 
|  | 50 | } | 
|  | 51 |  | 
|  | 52 | static void BM_PowerHalHidlBenchmarks_setFeature(benchmark::State& state) { | 
|  | 53 | runBenchmark(state, &IPower1_0::setFeature, Feature::POWER_FEATURE_DOUBLE_TAP_TO_WAKE, false); | 
|  | 54 | } | 
|  | 55 |  | 
|  | 56 | static void BM_PowerHalHidlBenchmarks_setInteractive(benchmark::State& state) { | 
|  | 57 | runBenchmark(state, &IPower1_0::setInteractive, false); | 
|  | 58 | } | 
|  | 59 |  | 
|  | 60 | static void BM_PowerHalHidlBenchmarks_powerHint(benchmark::State& state) { | 
|  | 61 | runBenchmark(state, &IPower1_0::powerHint, PowerHint::INTERACTION, 0); | 
|  | 62 | } | 
|  | 63 |  | 
|  | 64 | static void BM_PowerHalHidlBenchmarks_powerHintAsync(benchmark::State& state) { | 
|  | 65 | runBenchmark(state, &IPower1_1::powerHintAsync, PowerHint::INTERACTION, 0); | 
|  | 66 | } | 
|  | 67 |  | 
|  | 68 | BENCHMARK(BM_PowerHalHidlBenchmarks_setFeature); | 
|  | 69 | BENCHMARK(BM_PowerHalHidlBenchmarks_setInteractive); | 
|  | 70 | BENCHMARK(BM_PowerHalHidlBenchmarks_powerHint); | 
|  | 71 | BENCHMARK(BM_PowerHalHidlBenchmarks_powerHintAsync); |