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 <android/system/suspend/1.0/ISystemSuspend.h> 18 #include <android/system/suspend/internal/ISuspendControlServiceInternal.h> 19 #include <benchmark/benchmark.h> 20 #include <binder/IServiceManager.h> 21 22 using android::IBinder; 23 using android::sp; 24 using android::system::suspend::internal::ISuspendControlServiceInternal; 25 using android::system::suspend::internal::WakeLockInfo; 26 using android::system::suspend::V1_0::ISystemSuspend; 27 using android::system::suspend::V1_0::IWakeLock; 28 using android::system::suspend::V1_0::WakeLockType; 29 BM_acquireWakeLock(benchmark::State & state)30static void BM_acquireWakeLock(benchmark::State& state) { 31 static sp<ISystemSuspend> suspendService = ISystemSuspend::getService(); 32 33 while (state.KeepRunning()) { 34 suspendService->acquireWakeLock(WakeLockType::PARTIAL, "BenchmarkWakeLock"); 35 } 36 } 37 BENCHMARK(BM_acquireWakeLock); 38 BM_getWakeLockStats(benchmark::State & state)39static void BM_getWakeLockStats(benchmark::State& state) { 40 static sp<IBinder> controlInternal = 41 android::defaultServiceManager()->getService(android::String16("suspend_control_internal")); 42 static sp<ISuspendControlServiceInternal> controlServiceInternal = 43 android::interface_cast<ISuspendControlServiceInternal>(controlInternal); 44 45 while (state.KeepRunning()) { 46 std::vector<WakeLockInfo> wlStats; 47 controlServiceInternal->getWakeLockStats(&wlStats); 48 } 49 } 50 BENCHMARK(BM_getWakeLockStats); 51 52 BENCHMARK_MAIN(); 53