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