• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 #ifndef HITRACECHAIN_FFI_H
17 #define HITRACECHAIN_FFI_H
18 
19 #include "hitraceid.h"
20 
21 #ifndef HITRACE_UNITTEST
22 #include "cj_ffi/cj_common_ffi.h"
23 #else
24 #define FFI_EXPORT
25 #endif
26 
27 #include <cstdint>
28 
29 extern "C" {
30     struct CHiTraceId {
31         uint64_t chainId;
32         uint64_t spanId;
33         uint64_t parentSpanId;
34         int32_t flags;
35     };
36 
Parse(OHOS::HiviewDFX::HiTraceId id)37     static CHiTraceId Parse(OHOS::HiviewDFX::HiTraceId id)
38     {
39         CHiTraceId traceId;
40         traceId.chainId = id.GetChainId();
41         traceId.spanId = id.GetSpanId();
42         traceId.parentSpanId = id.GetParentSpanId();
43         traceId.flags = id.GetFlags();
44         return traceId;
45     }
46 
Parse(CHiTraceId id)47     static OHOS::HiviewDFX::HiTraceId Parse(CHiTraceId id)
48     {
49         OHOS::HiviewDFX::HiTraceId traceId;
50         traceId.SetChainId(id.chainId);
51         traceId.SetSpanId(id.spanId);
52         traceId.SetParentSpanId(id.parentSpanId);
53         traceId.SetFlags(id.flags);
54         return traceId;
55     }
56 
57     FFI_EXPORT CHiTraceId FfiOHOSHiTraceChainBegin(const char* name, int flag);
58     FFI_EXPORT void FfiOHOSHiTraceChainEnd(CHiTraceId id);
59     FFI_EXPORT CHiTraceId FfiOHOSHiTraceChainGetId();
60     FFI_EXPORT void FfiOHOSHiTraceChainSetId(CHiTraceId id);
61     FFI_EXPORT void FfiOHOSHiTraceChainClearId();
62     FFI_EXPORT CHiTraceId FfiOHOSHiTraceChainCreateSpan();
63     FFI_EXPORT void FfiOHOSHiTraceChainTracepoint(uint32_t mode, uint32_t type, CHiTraceId id, const char* str);
64     FFI_EXPORT bool FfiOHOSHiTraceChainIsValid(CHiTraceId id);
65     FFI_EXPORT bool FfiOHOSHiTraceChainIsFlagEnabled(CHiTraceId id, int32_t flag);
66     FFI_EXPORT void FfiOHOSHiTraceChainEnableFlag(CHiTraceId id, int32_t flag);
67 }
68 
69 #endif