1b0e7dd80Sopenharmony_ci/*
2b0e7dd80Sopenharmony_ci * Copyright (c) 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/hitracechain.h"
17b0e7dd80Sopenharmony_ci#include "hitracechain_inner.h"
18b0e7dd80Sopenharmony_ci
19b0e7dd80Sopenharmony_ciusing namespace std;
20b0e7dd80Sopenharmony_ci
21b0e7dd80Sopenharmony_cinamespace OHOS {
22b0e7dd80Sopenharmony_cinamespace HiviewDFX {
23b0e7dd80Sopenharmony_ci
24b0e7dd80Sopenharmony_ciHiTraceId HiTraceChain::Begin(const string& name, int flags)
25b0e7dd80Sopenharmony_ci{
26b0e7dd80Sopenharmony_ci    return HiTraceId(::HiTraceChainBegin(name.c_str(), flags));
27b0e7dd80Sopenharmony_ci}
28b0e7dd80Sopenharmony_ci
29b0e7dd80Sopenharmony_civoid HiTraceChain::End(const HiTraceId& id)
30b0e7dd80Sopenharmony_ci{
31b0e7dd80Sopenharmony_ci    ::HiTraceChainEnd(&(id.id_));
32b0e7dd80Sopenharmony_ci    return;
33b0e7dd80Sopenharmony_ci}
34b0e7dd80Sopenharmony_ci
35b0e7dd80Sopenharmony_ciHiTraceId HiTraceChain::GetId()
36b0e7dd80Sopenharmony_ci{
37b0e7dd80Sopenharmony_ci    return HiTraceId(::HiTraceChainGetId());
38b0e7dd80Sopenharmony_ci}
39b0e7dd80Sopenharmony_ci
40b0e7dd80Sopenharmony_civoid HiTraceChain::SetId(const HiTraceId& id)
41b0e7dd80Sopenharmony_ci{
42b0e7dd80Sopenharmony_ci    ::HiTraceChainSetId(&(id.id_));
43b0e7dd80Sopenharmony_ci    return;
44b0e7dd80Sopenharmony_ci}
45b0e7dd80Sopenharmony_ci
46b0e7dd80Sopenharmony_civoid HiTraceChain::ClearId()
47b0e7dd80Sopenharmony_ci{
48b0e7dd80Sopenharmony_ci    ::HiTraceChainClearId();
49b0e7dd80Sopenharmony_ci    return;
50b0e7dd80Sopenharmony_ci}
51b0e7dd80Sopenharmony_ci
52b0e7dd80Sopenharmony_ciHiTraceId HiTraceChain::CreateSpan()
53b0e7dd80Sopenharmony_ci{
54b0e7dd80Sopenharmony_ci    return HiTraceId(::HiTraceChainCreateSpan());
55b0e7dd80Sopenharmony_ci}
56b0e7dd80Sopenharmony_ci
57b0e7dd80Sopenharmony_civoid HiTraceChain::Tracepoint(HiTraceTracepointType type, const HiTraceId& id, const char* fmt, ...)
58b0e7dd80Sopenharmony_ci{
59b0e7dd80Sopenharmony_ci    va_list args;
60b0e7dd80Sopenharmony_ci
61b0e7dd80Sopenharmony_ci    va_start(args, fmt);
62b0e7dd80Sopenharmony_ci    ::HiTraceChainTracepointInner(HITRACE_CM_DEFAULT, type, &(id.id_), fmt, args);
63b0e7dd80Sopenharmony_ci    va_end(args);
64b0e7dd80Sopenharmony_ci
65b0e7dd80Sopenharmony_ci    return;
66b0e7dd80Sopenharmony_ci}
67b0e7dd80Sopenharmony_ci
68b0e7dd80Sopenharmony_civoid HiTraceChain::Tracepoint(HiTraceCommunicationMode mode, HiTraceTracepointType type, const HiTraceId& id,
69b0e7dd80Sopenharmony_ci    const char* fmt, ...)
70b0e7dd80Sopenharmony_ci{
71b0e7dd80Sopenharmony_ci    va_list args;
72b0e7dd80Sopenharmony_ci
73b0e7dd80Sopenharmony_ci    va_start(args, fmt);
74b0e7dd80Sopenharmony_ci    ::HiTraceChainTracepointInner(mode, type, &(id.id_), fmt, args);
75b0e7dd80Sopenharmony_ci    va_end(args);
76b0e7dd80Sopenharmony_ci
77b0e7dd80Sopenharmony_ci    return;
78b0e7dd80Sopenharmony_ci}
79b0e7dd80Sopenharmony_ci
80b0e7dd80Sopenharmony_ciHiTraceId HiTraceChain::SaveAndSet(const HiTraceId& id)
81b0e7dd80Sopenharmony_ci{
82b0e7dd80Sopenharmony_ci    return HiTraceId(::HiTraceChainSaveAndSetId(&(id.id_)));
83b0e7dd80Sopenharmony_ci}
84b0e7dd80Sopenharmony_ci
85b0e7dd80Sopenharmony_civoid HiTraceChain::Restore(const HiTraceId& id)
86b0e7dd80Sopenharmony_ci{
87b0e7dd80Sopenharmony_ci    ::HiTraceChainRestoreId(&(id.id_));
88b0e7dd80Sopenharmony_ci}
89b0e7dd80Sopenharmony_ci} // namespace HiviewDFX
90b0e7dd80Sopenharmony_ci} // namespace OHOS
91