• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 "hitrace/hitraceid.h"
17 
18 namespace OHOS {
19 namespace HiviewDFX {
20 
HiTraceId()21 HiTraceId::HiTraceId()
22 {
23     id_.valid = HITRACE_ID_INVALID;
24     id_.ver = 0;
25     id_.chainId = 0;
26     id_.flags = 0;
27     id_.spanId = 0;
28     id_.parentSpanId = 0;
29 }
30 
HiTraceId(const HiTraceIdStruct & id)31 HiTraceId::HiTraceId(const HiTraceIdStruct& id) : id_(id)
32 {}
33 
HiTraceId(const uint8_t * pIdArray,int len)34 HiTraceId::HiTraceId(const uint8_t* pIdArray, int len)
35 {
36     id_ = HiTraceBytesToId(pIdArray, len);
37 }
38 
IsValid() const39 bool HiTraceId::IsValid() const
40 {
41     return HiTraceIsValid(&id_);
42 }
43 
IsFlagEnabled(HiTraceFlag flag) const44 bool HiTraceId::IsFlagEnabled(HiTraceFlag flag) const
45 {
46     return HiTraceIsFlagEnabled(&id_, flag);
47 }
48 
EnableFlag(HiTraceFlag flag)49 void HiTraceId::EnableFlag(HiTraceFlag flag)
50 {
51     HiTraceEnableFlag(&id_, flag);
52     return;
53 }
54 
GetFlags() const55 int HiTraceId::GetFlags() const
56 {
57     return HiTraceGetFlags(&id_);
58 }
59 
SetFlags(int flags)60 void HiTraceId::SetFlags(int flags)
61 {
62     HiTraceSetFlags(&id_, flags);
63     return;
64 }
65 
GetChainId() const66 uint64_t HiTraceId::GetChainId() const
67 {
68     return HiTraceGetChainId(&id_);
69 }
70 
SetChainId(uint64_t chainId)71 void HiTraceId::SetChainId(uint64_t chainId)
72 {
73     HiTraceSetChainId(&id_, chainId);
74     return;
75 }
76 
GetSpanId() const77 uint64_t HiTraceId::GetSpanId() const
78 {
79     return HiTraceGetSpanId(&id_);
80 }
81 
SetSpanId(uint64_t spanId)82 void HiTraceId::SetSpanId(uint64_t spanId)
83 {
84     HiTraceSetSpanId(&id_, spanId);
85     return;
86 }
87 
GetParentSpanId() const88 uint64_t HiTraceId::GetParentSpanId() const
89 {
90     return HiTraceGetParentSpanId(&id_);
91 }
92 
SetParentSpanId(uint64_t parentSpanId)93 void HiTraceId::SetParentSpanId(uint64_t parentSpanId)
94 {
95     HiTraceSetParentSpanId(&id_, parentSpanId);
96     return;
97 }
98 
ToBytes(uint8_t * pIdArray,int len) const99 int HiTraceId::ToBytes(uint8_t* pIdArray, int len) const
100 {
101     return HiTraceIdToBytes(&id_, pIdArray, len);
102 }
103 
104 } // namespace HiviewDFX
105 } // namespace OHOS