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 "hitracechain_impl.h"
17 #include <string>
18
19 using namespace OHOS::HiviewDFX;
20
21 #ifndef TRACE_DOMAIN
22 #define TRACE_DOMAIN 0xD002D33
23 #endif
24
25 namespace OHOS {
26 namespace CJSystemapi {
27
Begin(const char * name,int flags)28 HiTraceId HiTraceChainImpl::Begin(const char* name, int flags)
29 {
30 std::string traceName = (name == nullptr) ? "" : name;
31 return HiTraceChain::Begin(traceName, flags, TRACE_DOMAIN);
32 }
33
End(const HiTraceId & id)34 void HiTraceChainImpl::End(const HiTraceId& id)
35 {
36 return HiTraceChain::End(id, TRACE_DOMAIN);
37 }
38
GetId()39 HiTraceId HiTraceChainImpl::GetId()
40 {
41 return HiTraceChain::GetId();
42 }
43
SetId(const HiTraceId & id)44 void HiTraceChainImpl::SetId(const HiTraceId& id)
45 {
46 return HiTraceChain::SetId(id);
47 }
48
ClearId()49 void HiTraceChainImpl::ClearId()
50 {
51 return HiTraceChain::ClearId();
52 }
53
CreateSpan()54 HiTraceId HiTraceChainImpl::CreateSpan()
55 {
56 return HiTraceChain::CreateSpan();
57 }
58
Tracepoint(uint32_t mode,uint32_t type,HiTraceId id,const char * msg)59 void HiTraceChainImpl::Tracepoint(uint32_t mode, uint32_t type, HiTraceId id, const char* msg)
60 {
61 HiTraceCommunicationMode communicationMode = HiTraceCommunicationMode(mode);
62 HiTraceTracepointType tracePointType = HiTraceTracepointType(type);
63 return HiTraceChain::Tracepoint(communicationMode, tracePointType, id, TRACE_DOMAIN, "%s", msg);
64 }
65
IsValid(const HiTraceId & id)66 bool HiTraceChainImpl::IsValid(const HiTraceId& id)
67 {
68 return id.IsValid();
69 }
70
IsFlagEnabled(const HiTraceId & traceId,int32_t flag)71 bool HiTraceChainImpl::IsFlagEnabled(const HiTraceId& traceId, int32_t flag)
72 {
73 HiTraceFlag traceFlag = HiTraceFlag(flag);
74 bool isFalgEnabled = traceId.IsFlagEnabled(traceFlag);
75 return isFalgEnabled;
76 }
77
EnableFlag(HiTraceId & traceId,int32_t flag)78 void HiTraceChainImpl::EnableFlag(HiTraceId& traceId, int32_t flag)
79 {
80 HiTraceFlag traceFlag = HiTraceFlag(flag);
81 traceId.EnableFlag(traceFlag);
82 }
83
84 } // CJSystemapi
85 } // OHOS
86
87