1 /*
2  * Copyright (c) 2024 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 
16 #include <benchmark/benchmark.h>
17 #include <string>
18 #include <vector>
19 #include "dfx_log.h"
20 #include "dfx_map.h"
21 #include "dfx_maps.h"
22 
23 #undef LOG_DOMAIN
24 #undef LOG_TAG
25 #define LOG_DOMAIN 0xD002D11
26 #define LOG_TAG "DfxMaps"
27 
28 using namespace OHOS::HiviewDFX;
29 using namespace std;
30 
31 /**
32 * @tc.name: BenchmarkMapsCreateAll
33 * @tc.desc: Maps Create
34 * @tc.type: FUNC
35 */
BenchmarkMapsCreateAll(benchmark::State & state)36 static void BenchmarkMapsCreateAll(benchmark::State& state)
37 {
38     for (const auto& _ : state) {
39         auto dfxMaps = DfxMaps::Create();
40         LOGU("%s:: maps.size: %zu", __func__, dfxMaps->GetMapsSize());
41     }
42 }
43 BENCHMARK(BenchmarkMapsCreateAll);
44 
45 /**
46 * @tc.name: BenchmarkMapsCreateOnlyExec
47 * @tc.desc: Maps Create
48 * @tc.type: FUNC
49 */
BenchmarkMapsCreateOnlyExec(benchmark::State & state)50 static void BenchmarkMapsCreateOnlyExec(benchmark::State& state)
51 {
52     for (const auto& _ : state) {
53         auto dfxMaps = DfxMaps::Create(0, false);
54         LOGU("%s:: maps.size: %zu", __func__, dfxMaps->GetMapsSize());
55     }
56 }
57 BENCHMARK(BenchmarkMapsCreateOnlyExec);
58 
59 /**
60 * @tc.name: BenchmarkMapsCreateMapIndex
61 * @tc.desc: Maps Create
62 * @tc.type: FUNC
63 */
BenchmarkMapsCreateMapIndex(benchmark::State & state)64 static void BenchmarkMapsCreateMapIndex(benchmark::State& state)
65 {
66     std::vector<std::shared_ptr<DfxMap>> maps {};
67     std::vector<int> mapIndex {};
68     for (const auto& _ : state) {
69         if (DfxMaps::Create(0, maps, mapIndex)) {
70             LOGU("%s:: maps.size: %zu", __func__, maps.size());
71         }
72     }
73 }
74 BENCHMARK(BenchmarkMapsCreateMapIndex);