1 /* 2 * Copyright (C) 2023 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 <benchmark/benchmark.h> 18 #include <cutils/trace.h> 19 #include <string> 20 21 #include "trace_enabler.h" 22 BM_TracingOffAtraceBegin(benchmark::State & state)23static void BM_TracingOffAtraceBegin(benchmark::State& state) { 24 disable_app_atrace(); 25 std::string name(state.range(0), '0'); 26 for (auto _ : state) { 27 atrace_begin(ATRACE_TAG_APP, name.c_str()); 28 } 29 } 30 BM_TracingOffAtraceEnd(benchmark::State & state)31static void BM_TracingOffAtraceEnd(benchmark::State& state) { 32 disable_app_atrace(); 33 for (auto _ : state) { 34 atrace_end(ATRACE_TAG_APP); 35 } 36 } 37 BM_TracingOnAtraceBegin(benchmark::State & state)38static void BM_TracingOnAtraceBegin(benchmark::State& state) { 39 enable_atrace_for_single_app("*libatrace_rust_benchmark_cc"); 40 std::string name(state.range(0), '0'); 41 for (auto _ : state) { 42 atrace_begin(ATRACE_TAG_APP, name.c_str()); 43 } 44 disable_app_atrace(); 45 } 46 BM_TracingOnAtraceEnd(benchmark::State & state)47static void BM_TracingOnAtraceEnd(benchmark::State& state) { 48 enable_atrace_for_single_app("*libatrace_rust_benchmark_cc"); 49 for (auto _ : state) { 50 atrace_end(ATRACE_TAG_APP); 51 } 52 disable_app_atrace(); 53 } 54 55 // Register the function as a benchmark 56 BENCHMARK(BM_TracingOffAtraceBegin)->Arg(10)->Arg(1000); 57 BENCHMARK(BM_TracingOffAtraceEnd); 58 BENCHMARK(BM_TracingOnAtraceBegin)->Arg(10)->Arg(1000); 59 BENCHMARK(BM_TracingOnAtraceEnd); 60 61 BENCHMARK_MAIN();