1 /* 2 * Copyright (c) 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 "frameworks/base/log/trace_id.h" 17 18 #include "hitrace/trace.h" 19 20 namespace OHOS::Ace { 21 22 class TraceIdImpl : public TraceId { 23 public: TraceIdImpl()24 TraceIdImpl() 25 { 26 traceId_ = std::make_unique<OHOS::HiviewDFX::HiTraceId>(OHOS::HiviewDFX::HiTraceChain::GetId()); 27 } 28 29 ~TraceIdImpl() = default; 30 SetTraceId()31 void SetTraceId() override 32 { 33 if (traceId_ && traceId_->IsValid()) { 34 OHOS::HiviewDFX::HiTraceChain::SetId(*(traceId_.get())); 35 } 36 } 37 ClearTraceId()38 void ClearTraceId() override 39 { 40 OHOS::HiviewDFX::HiTraceChain::ClearId(); 41 } 42 43 private: 44 std::unique_ptr<OHOS::HiviewDFX::HiTraceId> traceId_; 45 }; 46 CreateTraceId()47TraceId* TraceId::CreateTraceId() 48 { 49 return new TraceIdImpl(); 50 } 51 52 } // namespace OHOS::Ace