1b0e7dd80Sopenharmony_ci/*
2b0e7dd80Sopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd.
3b0e7dd80Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4b0e7dd80Sopenharmony_ci * you may not use this file except in compliance with the License.
5b0e7dd80Sopenharmony_ci * You may obtain a copy of the License at
6b0e7dd80Sopenharmony_ci *
7b0e7dd80Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8b0e7dd80Sopenharmony_ci *
9b0e7dd80Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10b0e7dd80Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11b0e7dd80Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12b0e7dd80Sopenharmony_ci * See the License for the specific language governing permissions and
13b0e7dd80Sopenharmony_ci * limitations under the License.
14b0e7dd80Sopenharmony_ci */
15b0e7dd80Sopenharmony_ci
16b0e7dd80Sopenharmony_ci#include <__config>
17b0e7dd80Sopenharmony_ci#include <cstdint>
18b0e7dd80Sopenharmony_ci#include <cstring>
19b0e7dd80Sopenharmony_ci#include <unistd.h>
20b0e7dd80Sopenharmony_ci#include <iosfwd>
21b0e7dd80Sopenharmony_ci#include <iostream>
22b0e7dd80Sopenharmony_ci#include <ostream>
23b0e7dd80Sopenharmony_ci#include <thread>
24b0e7dd80Sopenharmony_ci#include <vector>
25b0e7dd80Sopenharmony_ci
26b0e7dd80Sopenharmony_ci#include "hitrace_meter.h"
27b0e7dd80Sopenharmony_ci
28b0e7dd80Sopenharmony_ciusing namespace std;
29b0e7dd80Sopenharmony_cinamespace {
30b0e7dd80Sopenharmony_ciconstexpr int SLEEP_ONE_SECOND = 1;
31b0e7dd80Sopenharmony_ciconstexpr int SLEEP_TWO_SECOND = 2;
32b0e7dd80Sopenharmony_ciconstexpr int USLEEP_HALF_SECOND = 500000;
33b0e7dd80Sopenharmony_ciconstexpr int CYCLE_TIMES = 3;
34b0e7dd80Sopenharmony_ciconstexpr int32_t TASK_ID = 111;
35b0e7dd80Sopenharmony_ciconst vector<uint64_t> LABEL_TAGS = {
36b0e7dd80Sopenharmony_ci    HITRACE_TAG_OHOS,
37b0e7dd80Sopenharmony_ci    HITRACE_TAG_INTERCONNECTION,
38b0e7dd80Sopenharmony_ci    HITRACE_TAG_DLP_CREDENTIAL,
39b0e7dd80Sopenharmony_ci    HITRACE_TAG_ACCESS_CONTROL,
40b0e7dd80Sopenharmony_ci    HITRACE_TAG_NET,
41b0e7dd80Sopenharmony_ci    HITRACE_TAG_NWEB,
42b0e7dd80Sopenharmony_ci    HITRACE_TAG_HUKS,
43b0e7dd80Sopenharmony_ci    HITRACE_TAG_USERIAM,
44b0e7dd80Sopenharmony_ci    HITRACE_TAG_DISTRIBUTED_AUDIO,
45b0e7dd80Sopenharmony_ci    HITRACE_TAG_DLSM,
46b0e7dd80Sopenharmony_ci    HITRACE_TAG_FILEMANAGEMENT,
47b0e7dd80Sopenharmony_ci    HITRACE_TAG_ABILITY_MANAGER,
48b0e7dd80Sopenharmony_ci    HITRACE_TAG_ZCAMERA,
49b0e7dd80Sopenharmony_ci    HITRACE_TAG_ZMEDIA,
50b0e7dd80Sopenharmony_ci    HITRACE_TAG_ZIMAGE,
51b0e7dd80Sopenharmony_ci    HITRACE_TAG_ZAUDIO,
52b0e7dd80Sopenharmony_ci    HITRACE_TAG_DISTRIBUTEDDATA,
53b0e7dd80Sopenharmony_ci    HITRACE_TAG_MDFS,
54b0e7dd80Sopenharmony_ci    HITRACE_TAG_GRAPHIC_AGP,
55b0e7dd80Sopenharmony_ci    HITRACE_TAG_ACE,
56b0e7dd80Sopenharmony_ci    HITRACE_TAG_NOTIFICATION,
57b0e7dd80Sopenharmony_ci    HITRACE_TAG_MISC,
58b0e7dd80Sopenharmony_ci    HITRACE_TAG_MULTIMODALINPUT,
59b0e7dd80Sopenharmony_ci    HITRACE_TAG_SENSORS,
60b0e7dd80Sopenharmony_ci    HITRACE_TAG_MSDP,
61b0e7dd80Sopenharmony_ci    HITRACE_TAG_DSOFTBUS,
62b0e7dd80Sopenharmony_ci    HITRACE_TAG_RPC,
63b0e7dd80Sopenharmony_ci    HITRACE_TAG_ARK,
64b0e7dd80Sopenharmony_ci    HITRACE_TAG_WINDOW_MANAGER,
65b0e7dd80Sopenharmony_ci    HITRACE_TAG_ACCOUNT_MANAGER,
66b0e7dd80Sopenharmony_ci    HITRACE_TAG_DISTRIBUTED_SCREEN,
67b0e7dd80Sopenharmony_ci    HITRACE_TAG_DISTRIBUTED_CAMERA,
68b0e7dd80Sopenharmony_ci    HITRACE_TAG_DISTRIBUTED_HARDWARE_FWK,
69b0e7dd80Sopenharmony_ci    HITRACE_TAG_GLOBAL_RESMGR,
70b0e7dd80Sopenharmony_ci    HITRACE_TAG_DEVICE_MANAGER,
71b0e7dd80Sopenharmony_ci    HITRACE_TAG_SAMGR,
72b0e7dd80Sopenharmony_ci    HITRACE_TAG_POWER,
73b0e7dd80Sopenharmony_ci    HITRACE_TAG_DISTRIBUTED_SCHEDULE,
74b0e7dd80Sopenharmony_ci    HITRACE_TAG_DEVICE_PROFILE,
75b0e7dd80Sopenharmony_ci    HITRACE_TAG_DISTRIBUTED_INPUT,
76b0e7dd80Sopenharmony_ci    HITRACE_TAG_BLUETOOTH,
77b0e7dd80Sopenharmony_ci    HITRACE_TAG_ACCESSIBILITY_MANAGER,
78b0e7dd80Sopenharmony_ci    HITRACE_TAG_APP
79b0e7dd80Sopenharmony_ci};
80b0e7dd80Sopenharmony_ci
81b0e7dd80Sopenharmony_civoid FuncA()
82b0e7dd80Sopenharmony_ci{
83b0e7dd80Sopenharmony_ci    cout << "funcA" << endl;
84b0e7dd80Sopenharmony_ci    usleep(USLEEP_HALF_SECOND);
85b0e7dd80Sopenharmony_ci}
86b0e7dd80Sopenharmony_ci
87b0e7dd80Sopenharmony_civoid FuncB()
88b0e7dd80Sopenharmony_ci{
89b0e7dd80Sopenharmony_ci    cout << "funcB" << endl;
90b0e7dd80Sopenharmony_ci    usleep(USLEEP_HALF_SECOND);
91b0e7dd80Sopenharmony_ci}
92b0e7dd80Sopenharmony_ci
93b0e7dd80Sopenharmony_civoid FuncC(uint64_t label)
94b0e7dd80Sopenharmony_ci{
95b0e7dd80Sopenharmony_ci    cout << "funcC" << endl;
96b0e7dd80Sopenharmony_ci    int num = 0;
97b0e7dd80Sopenharmony_ci    for (int i = 0; i < CYCLE_TIMES; i++) {
98b0e7dd80Sopenharmony_ci        CountTrace(label, "count number", ++num);
99b0e7dd80Sopenharmony_ci        usleep(USLEEP_HALF_SECOND);
100b0e7dd80Sopenharmony_ci    }
101b0e7dd80Sopenharmony_ci}
102b0e7dd80Sopenharmony_ci
103b0e7dd80Sopenharmony_civoid ThreadFunc1(uint64_t label)
104b0e7dd80Sopenharmony_ci{
105b0e7dd80Sopenharmony_ci    StartAsyncTrace(label, "testAsync", TASK_ID);
106b0e7dd80Sopenharmony_ci    for (int i = 0; i < CYCLE_TIMES; ++i) {
107b0e7dd80Sopenharmony_ci        cout << "t1" << endl;
108b0e7dd80Sopenharmony_ci        usleep(USLEEP_HALF_SECOND);
109b0e7dd80Sopenharmony_ci    }
110b0e7dd80Sopenharmony_ci}
111b0e7dd80Sopenharmony_ci
112b0e7dd80Sopenharmony_civoid ThreadFunc2(uint64_t label)
113b0e7dd80Sopenharmony_ci{
114b0e7dd80Sopenharmony_ci    for (int i = 0; i < CYCLE_TIMES; ++i) {
115b0e7dd80Sopenharmony_ci        cout << "t2" << endl;
116b0e7dd80Sopenharmony_ci        usleep(USLEEP_HALF_SECOND);
117b0e7dd80Sopenharmony_ci    }
118b0e7dd80Sopenharmony_ci    FinishAsyncTrace(label, "testAsync", TASK_ID);
119b0e7dd80Sopenharmony_ci}
120b0e7dd80Sopenharmony_ci
121b0e7dd80Sopenharmony_civoid FuncMain(uint64_t label)
122b0e7dd80Sopenharmony_ci{
123b0e7dd80Sopenharmony_ci    thread t1(ThreadFunc1, label);
124b0e7dd80Sopenharmony_ci    t1.join();
125b0e7dd80Sopenharmony_ci
126b0e7dd80Sopenharmony_ci    StartTrace(label, "testStart");
127b0e7dd80Sopenharmony_ci    usleep(USLEEP_HALF_SECOND);
128b0e7dd80Sopenharmony_ci
129b0e7dd80Sopenharmony_ci    StartTrace(label, "funcAStart", SLEEP_ONE_SECOND); // 打印起始点
130b0e7dd80Sopenharmony_ci    FuncA();
131b0e7dd80Sopenharmony_ci    FinishTrace(label);
132b0e7dd80Sopenharmony_ci    usleep(USLEEP_HALF_SECOND);
133b0e7dd80Sopenharmony_ci
134b0e7dd80Sopenharmony_ci    thread t2(ThreadFunc2, label);
135b0e7dd80Sopenharmony_ci    t2.join();
136b0e7dd80Sopenharmony_ci
137b0e7dd80Sopenharmony_ci    StartTrace(label, "funcBStart", SLEEP_TWO_SECOND);
138b0e7dd80Sopenharmony_ci    FuncB();
139b0e7dd80Sopenharmony_ci    FinishTrace(label);
140b0e7dd80Sopenharmony_ci    sleep(SLEEP_ONE_SECOND);
141b0e7dd80Sopenharmony_ci
142b0e7dd80Sopenharmony_ci    FinishTrace(label);
143b0e7dd80Sopenharmony_ci    FuncC(label);
144b0e7dd80Sopenharmony_ci}
145b0e7dd80Sopenharmony_ci} // namespace
146b0e7dd80Sopenharmony_ci
147b0e7dd80Sopenharmony_ciint main()
148b0e7dd80Sopenharmony_ci{
149b0e7dd80Sopenharmony_ci    for (auto tag : LABEL_TAGS) {
150b0e7dd80Sopenharmony_ci        FuncMain(tag);
151b0e7dd80Sopenharmony_ci    }
152b0e7dd80Sopenharmony_ci    return 0;
153b0e7dd80Sopenharmony_ci}
154