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