• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 __FFRT_TRACE_CHAIN_H__
17 #define __FFRT_TRACE_CHAIN_H__
18 
19 #include "tm/task_base.h"
20 #include "dfx/log/ffrt_log_api.h"
21 
22 namespace ffrt {
23 
24 class TraceChainAdapter {
25 public:
26     static TraceChainAdapter& Instance();
27 
28     HiTraceIdStruct HiTraceChainGetId();
29     void HiTraceChainClearId();
30     void HiTraceChainRestoreId(const HiTraceIdStruct* pId);
31     HiTraceIdStruct HiTraceChainCreateSpan();
32     HiTraceIdStruct HiTraceChainBegin(const char* name, int flags);
33     void HiTraceChainEnd(const HiTraceIdStruct* pId);
34 
35 private:
36     TraceChainAdapter();
37     ~TraceChainAdapter();
38     void Load();
39     void UnLoad();
40 
41     void* handle_ = nullptr;
42 
43     using HiTraceChainGetIdFunc = HiTraceIdStruct (*)();
44     using HiTraceChainClearIdFunc = void (*)();
45     using HiTraceChainRestoreIdFunc = void (*)(const HiTraceIdStruct*);
46     using HiTraceChainCreateSpanFunc = HiTraceIdStruct (*)();
47     using HiTraceChainBeginFunc = HiTraceIdStruct (*)(const char*, int);
48     using HiTraceChainEndFunc = void (*)(const HiTraceIdStruct*);
49 
50     HiTraceChainGetIdFunc getIdFunc_ = nullptr;
51     HiTraceChainClearIdFunc clearIdFunc_ = nullptr;
52     HiTraceChainRestoreIdFunc restoreIdFunc_ = nullptr;
53     HiTraceChainCreateSpanFunc createSpanFunc_ = nullptr;
54     HiTraceChainBeginFunc beginChainFunc_ = nullptr;
55     HiTraceChainEndFunc endChainFunc_ = nullptr;
56 };
57 } // namespace ffrt
58 
59 #endif // __FFRT_TRACE_CHAIN_H__