blob: 5542ac43269e3f9a4c4cc6c845cd09347a7b47f0 [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 "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
29using android::hardware::power::Boost;
30using android::hardware::power::Mode;
31using android::hardware::power::V1_0::Feature;
32using android::hardware::power::V1_0::PowerHint;
33using IPower1_0 = android::hardware::power::V1_0::IPower;
34using IPower1_1 = android::hardware::power::V1_1::IPower;
35
36using namespace android;
37
38template <class R, class I, class... Args0, class... Args1>
39static 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
52static void BM_PowerHalHidlBenchmarks_setFeature(benchmark::State& state) {
53 runBenchmark(state, &IPower1_0::setFeature, Feature::POWER_FEATURE_DOUBLE_TAP_TO_WAKE, false);
54}
55
56static void BM_PowerHalHidlBenchmarks_setInteractive(benchmark::State& state) {
57 runBenchmark(state, &IPower1_0::setInteractive, false);
58}
59
60static void BM_PowerHalHidlBenchmarks_powerHint(benchmark::State& state) {
61 runBenchmark(state, &IPower1_0::powerHint, PowerHint::INTERACTION, 0);
62}
63
64static void BM_PowerHalHidlBenchmarks_powerHintAsync(benchmark::State& state) {
65 runBenchmark(state, &IPower1_1::powerHintAsync, PowerHint::INTERACTION, 0);
66}
67
68BENCHMARK(BM_PowerHalHidlBenchmarks_setFeature);
69BENCHMARK(BM_PowerHalHidlBenchmarks_setInteractive);
70BENCHMARK(BM_PowerHalHidlBenchmarks_powerHint);
71BENCHMARK(BM_PowerHalHidlBenchmarks_powerHintAsync);