1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef STARTUP_INIT_BENCHMARK_FWK_H 16 #define STARTUP_INIT_BENCHMARK_FWK_H 17 #include <map> 18 #include <mutex> 19 #include <string> 20 #include <utility> 21 #include <vector> 22 23 namespace init_benchmark_test { 24 using benchmark_func = void (*) (void); 25 extern std::mutex g_benchmarkLock; 26 extern std::map<std::string, std::pair<benchmark_func, std::string>> g_allBenchmarks; 27 28 static int __attribute__((unused)) AddBenchmark(const std::string &funcName, 29 benchmark_func funcPtr, const std::string &arg = "") 30 { 31 g_benchmarkLock.lock(); 32 g_allBenchmarks.emplace(std::string(funcName), std::make_pair(funcPtr, arg)); 33 g_benchmarkLock.unlock(); 34 return 0; 35 } 36 37 #define INIT_BENCHMARK(n) \ 38 int _init_benchmark_##n __attribute__((unused)) = AddBenchmark(std::string(#n), \ 39 reinterpret_cast<benchmark_func>(n)) 40 41 #define INIT_BENCHMARK_WITH_ARG(n, arg) \ 42 int _init_benchmark_##n __attribute__((unused)) = AddBenchmark(std::string(#n), \ 43 reinterpret_cast<benchmark_func>(n), arg) 44 } 45 46 #ifdef __cplusplus 47 #if __cplusplus 48 extern "C" { 49 #endif 50 #endif 51 52 typedef struct bench_opts_t { 53 int cpuNum = -1; 54 long iterNum = 0; 55 } BENCH_OPTS_T; 56 57 void CreateLocalParameterTest(int max); 58 #ifdef __cplusplus 59 #if __cplusplus 60 } 61 #endif 62 #endif 63 #endif // STARTUP_INIT_BENCHMARK_FWK_H