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