1 /* 2 * Copyright 2019 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 #include <aidl/android/system/suspend/ISystemSuspend.h> 18 #include <aidl/android/system/suspend/IWakeLock.h> 19 #include <android/binder_manager.h> 20 #include <android/system/suspend/internal/ISuspendControlServiceInternal.h> 21 #include <benchmark/benchmark.h> 22 #include <binder/IServiceManager.h> 23 24 using aidl::android::system::suspend::ISystemSuspend; 25 using aidl::android::system::suspend::IWakeLock; 26 using aidl::android::system::suspend::WakeLockType; 27 using android::IBinder; 28 using android::sp; 29 using android::system::suspend::internal::ISuspendControlServiceInternal; 30 using android::system::suspend::internal::WakeLockInfo; 31 BM_acquireWakeLock(benchmark::State & state)32static void BM_acquireWakeLock(benchmark::State& state) { 33 static const std::string suspendInstance = 34 std::string() + ISystemSuspend::descriptor + "/default"; 35 static std::shared_ptr<ISystemSuspend> suspendService = ISystemSuspend::fromBinder( 36 ndk::SpAIBinder(AServiceManager_waitForService(suspendInstance.c_str()))); 37 38 while (state.KeepRunning()) { 39 std::shared_ptr<IWakeLock> wl = nullptr; 40 suspendService->acquireWakeLock(WakeLockType::PARTIAL, "BenchmarkWakeLock", &wl); 41 } 42 } 43 BENCHMARK(BM_acquireWakeLock); 44 BM_getWakeLockStats(benchmark::State & state)45static void BM_getWakeLockStats(benchmark::State& state) { 46 static sp<IBinder> controlInternal = 47 android::defaultServiceManager()->getService(android::String16("suspend_control_internal")); 48 static sp<ISuspendControlServiceInternal> controlServiceInternal = 49 android::interface_cast<ISuspendControlServiceInternal>(controlInternal); 50 51 while (state.KeepRunning()) { 52 std::vector<WakeLockInfo> wlStats; 53 controlServiceInternal->getWakeLockStats(&wlStats); 54 } 55 } 56 BENCHMARK(BM_getWakeLockStats); 57 58 BENCHMARK_MAIN(); 59