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 "hitrace/hitraceid.h"
17
18 #include <cstdint>
19
20 #include "hitrace/hitracechainc.h"
21
22 namespace OHOS {
23 namespace HiviewDFX {
24
HiTraceId()25 HiTraceId::HiTraceId()
26 {
27 id_.valid = HITRACE_ID_INVALID;
28 id_.ver = 0;
29 id_.chainId = 0;
30 id_.flags = 0;
31 id_.spanId = 0;
32 id_.parentSpanId = 0;
33 }
34
HiTraceId(const HiTraceIdStruct & id)35 HiTraceId::HiTraceId(const HiTraceIdStruct& id) : id_(id)
36 {}
37
HiTraceId(const uint8_t * pIdArray,int len)38 HiTraceId::HiTraceId(const uint8_t* pIdArray, int len)
39 {
40 id_ = HiTraceChainBytesToId(pIdArray, len);
41 }
42
IsValid() const43 bool HiTraceId::IsValid() const
44 {
45 return HiTraceChainIsValid(&id_);
46 }
47
IsFlagEnabled(HiTraceFlag flag) const48 bool HiTraceId::IsFlagEnabled(HiTraceFlag flag) const
49 {
50 return HiTraceChainIsFlagEnabled(&id_, flag);
51 }
52
EnableFlag(HiTraceFlag flag)53 void HiTraceId::EnableFlag(HiTraceFlag flag)
54 {
55 HiTraceChainEnableFlag(&id_, flag);
56 return;
57 }
58
GetFlags() const59 int HiTraceId::GetFlags() const
60 {
61 return HiTraceChainGetFlags(&id_);
62 }
63
SetFlags(int flags)64 void HiTraceId::SetFlags(int flags)
65 {
66 HiTraceChainSetFlags(&id_, flags);
67 return;
68 }
69
GetChainId() const70 uint64_t HiTraceId::GetChainId() const
71 {
72 return HiTraceChainGetChainId(&id_);
73 }
74
SetChainId(uint64_t chainId)75 void HiTraceId::SetChainId(uint64_t chainId)
76 {
77 HiTraceChainSetChainId(&id_, chainId);
78 return;
79 }
80
GetSpanId() const81 uint64_t HiTraceId::GetSpanId() const
82 {
83 return HiTraceChainGetSpanId(&id_);
84 }
85
SetSpanId(uint64_t spanId)86 void HiTraceId::SetSpanId(uint64_t spanId)
87 {
88 HiTraceChainSetSpanId(&id_, spanId);
89 return;
90 }
91
GetParentSpanId() const92 uint64_t HiTraceId::GetParentSpanId() const
93 {
94 return HiTraceChainGetParentSpanId(&id_);
95 }
96
SetParentSpanId(uint64_t parentSpanId)97 void HiTraceId::SetParentSpanId(uint64_t parentSpanId)
98 {
99 HiTraceChainSetParentSpanId(&id_, parentSpanId);
100 return;
101 }
102
ToBytes(uint8_t * pIdArray,int len) const103 int HiTraceId::ToBytes(uint8_t* pIdArray, int len) const
104 {
105 return HiTraceChainIdToBytes(&id_, pIdArray, len);
106 }
107
108 } // namespace HiviewDFX
109 } // namespace OHOS
110