1 /*
2  * Copyright (c) 2021-2022 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 "hks_hitrace.h"
17 #ifdef L2_STANDARD
18 #include "hitrace_meter_wrapper.h"
19 
20 static const uint64_t huksLabel = (1ULL << 25);
21 #endif
22 
HksHitraceBegin(const char * name,int flag)23 struct HksHitraceId HksHitraceBegin(const char *name, int flag)
24 {
25 #ifdef L2_STANDARD
26     HiTraceIdStruct traceId = HiTraceChainBegin(name, flag);
27     struct HksHitraceId hitraceId = {
28         .traceId = traceId,
29     };
30     HksTraceMeterStart(huksLabel, name, -1);
31     return hitraceId;
32 #else
33     (void)name;
34     (void)flag;
35     struct HksHitraceId hitraceId = {0};
36     return hitraceId;
37 #endif
38 }
39 
HksHitraceEnd(const struct HksHitraceId * hitraceId)40 void HksHitraceEnd(const struct HksHitraceId *hitraceId)
41 {
42 #ifdef L2_STANDARD
43     HiTraceChainEnd(&hitraceId->traceId);
44     HksTraceMeterFinish(huksLabel);
45 #else
46     (void)hitraceId;
47 #endif
48 }