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/PowerStatsCollector.h> 21 22 #include <benchmark/benchmark.h> 23 24 /* 25 Pixel 9 Pro XL 26 (tolerance is the amount of time a cached value is valid). 27 ------------------------------------------------------------------------------------------ 28 Benchmark Time CPU Iteration 29 ------------------------------------------------------------------------------------------ 30 audio_powerstatscollector_benchmark: 31 #BM_StatsToleranceMs/0 6.346578290999787E7 ns 2069264.56 ns 100 32 #BM_StatsToleranceMs/50 454.12461256065177 ns 203.1644161064639 ns 2615571 33 #BM_StatsToleranceMs/100 167.74983887731364 ns 101.99598388920647 ns 5436852 34 #BM_StatsToleranceMs/200 102.57950838168422 ns 79.40969988086803 ns 7600815 35 #BM_StatsToleranceMs/500 86.87348495571898 ns 75.24841434306252 ns 9789318 36 */ 37 38 // We check how expensive it is to query stats depending 39 // on the tolerance to reuse the cached values. 40 // A tolerance of 0 means we always fetch stats. BM_StatsToleranceMs(benchmark::State & state)41static void BM_StatsToleranceMs(benchmark::State& state) { 42 auto& collector = android::media::psh_utils::PowerStatsCollector::getCollector(); 43 const int64_t toleranceNs = state.range(0) * 1'000'000; 44 while (state.KeepRunning()) { 45 collector.getStats(toleranceNs); 46 benchmark::ClobberMemory(); 47 } 48 } 49 50 // Here we test various time tolerances (given in milliseconds here) 51 BENCHMARK(BM_StatsToleranceMs)->Arg(0)->Arg(50)->Arg(100)->Arg(200)->Arg(500); 52 53 BENCHMARK_MAIN(); 54