1 /* 2 * Copyright (C) 2024 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 "audio_token_benchmark" 18 #include <utils/Log.h> 19 20 #include <psh_utils/Token.h> 21 22 #include <benchmark/benchmark.h> 23 24 /* 25 Pixel 9 Pro XL 26 ------------------------------------------------------------------------------------------ 27 Benchmark Time CPU Iteration 28 ------------------------------------------------------------------------------------------ 29 audio_token_benchmark: 30 #BM_ClientToken 494.6548907301575 ns 492.4932166101717 ns 1376819 31 #BM_ThreadToken 140.34316175293938 ns 139.91778452790845 ns 5000397 32 #BM_TrackToken 944.0571625384163 ns 893.7912613357879 ns 643096 33 */ 34 BM_ClientToken(benchmark::State & state)35static void BM_ClientToken(benchmark::State& state) { 36 constexpr pid_t kPid = 10; 37 constexpr uid_t kUid = 100; 38 while (state.KeepRunning()) { 39 auto token = android::media::psh_utils::createAudioClientToken( 40 kPid, kUid); 41 benchmark::ClobberMemory(); 42 } 43 } 44 45 BENCHMARK(BM_ClientToken); 46 BM_ThreadToken(benchmark::State & state)47static void BM_ThreadToken(benchmark::State& state) { 48 constexpr pid_t kTid = 20; 49 constexpr const char* kWakeLockTag = "thread"; 50 while (state.KeepRunning()) { 51 auto token = android::media::psh_utils::createAudioThreadToken( 52 kTid, kWakeLockTag); 53 benchmark::ClobberMemory(); 54 } 55 } 56 57 BENCHMARK(BM_ThreadToken); 58 BM_TrackToken(benchmark::State & state)59static void BM_TrackToken(benchmark::State& state) { 60 constexpr pid_t kPid = 10; 61 constexpr uid_t kUid = 100; 62 auto clientToken = android::media::psh_utils::createAudioClientToken( 63 kPid, kUid); 64 while (state.KeepRunning()) { 65 auto token = android::media::psh_utils::createAudioTrackToken(kUid); 66 benchmark::ClobberMemory(); 67 } 68 } 69 70 BENCHMARK(BM_TrackToken); 71 72 BENCHMARK_MAIN(); 73