blob: a6dad5104502f63c853bb8f5a1b020b2302980da [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 "PowerHalAidlBenchmarks"
18
19#include <android/hardware/power/Boost.h>
20#include <android/hardware/power/IPower.h>
21#include <android/hardware/power/Mode.h>
22
23#include <benchmark/benchmark.h>
24
25#include <binder/IServiceManager.h>
26
27using android::hardware::power::Boost;
28using android::hardware::power::IPower;
29using android::hardware::power::Mode;
30
31using namespace android;
32
33template <class R, class... Args0, class... Args1>
34static void runBenchmark(benchmark::State& state, R (IPower::*fn)(Args0...), Args1&&... args1) {
35 sp<IPower> hal = waitForVintfService<IPower>();
36
37 if (hal == nullptr) {
38 ALOGI("Power HAL AIDL not available, skipping test...");
39 return;
40 }
41
42 while (state.KeepRunning()) {
43 (*hal.*fn)(std::forward<Args1>(args1)...);
44 }
45}
46
47static void BM_PowerHalAidlBenchmarks_isBoostSupported(benchmark::State& state) {
48 bool isSupported;
49 runBenchmark(state, &IPower::isBoostSupported, Boost::INTERACTION, &isSupported);
50}
51
52static void BM_PowerHalAidlBenchmarks_isModeSupported(benchmark::State& state) {
53 bool isSupported;
54 runBenchmark(state, &IPower::isModeSupported, Mode::INTERACTIVE, &isSupported);
55}
56
57static void BM_PowerHalAidlBenchmarks_setBoost(benchmark::State& state) {
58 runBenchmark(state, &IPower::setBoost, Boost::INTERACTION, 0);
59}
60
61static void BM_PowerHalAidlBenchmarks_setMode(benchmark::State& state) {
62 runBenchmark(state, &IPower::setMode, Mode::INTERACTIVE, false);
63}
64
65BENCHMARK(BM_PowerHalAidlBenchmarks_isBoostSupported);
66BENCHMARK(BM_PowerHalAidlBenchmarks_isModeSupported);
67BENCHMARK(BM_PowerHalAidlBenchmarks_setBoost);
68BENCHMARK(BM_PowerHalAidlBenchmarks_setMode);