• 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 OHOS_IPC_IPC_TRACE_H
17 #define OHOS_IPC_IPC_TRACE_H
18 
19 #include <string>
20 
21 namespace OHOS {
22 class IPCTrace {
23 public:
24     /**
25      * @brief Check whether the ipc tag is enabled.
26      * @return Return <b>true</b> if the rpc ipc is enabled; returns <b>false</b> otherwise.
27      * @since 15
28      */
29     static bool IsEnabled();
30 
31     /**
32      * @brief Trace the begin of a ipc context.
33      * @param value Trace information of ipc.
34      * @return void
35      * @since 15
36      */
37     static void Start(const std::string &value);
38 
39     /**
40      * @brief Trace the end of a ipc context.
41      * @return void
42      * @since 15
43      */
44     static void Finish();
45 
46     /**
47      * @brief Trace the begin of an asynchronous context.
48      * @param value Trace information, It must be the same as the value of
49      * the 'FinishAsync' function parameter 'value'.
50      * @param taskId Task identify, It must be the same as the value of the 'FinishAsync' function parameter 'taskId'.
51      * @return void
52      * @since 15
53      */
54     static void StartAsync(const std::string &value, int32_t taskId);
55 
56     /**
57      * @brief Trace the end of an asynchronous context.
58      * @param value Trace information, It must be the same as the value of
59      * the 'StartAsync' function parameter 'value'.
60      * @param taskId Task identify, It must be the same as the value of the 'StartAsync' function parameter 'taskId'.
61      * @return void
62      * @since 15
63      */
64     static void FinishAsync(const std::string &value, int32_t taskId);
65 
66 private:
67     static IPCTrace &GetInstance();
68     IPCTrace();
69     ~IPCTrace();
70     IPCTrace(const IPCTrace &other) = delete;
71     IPCTrace &operator=(const IPCTrace &other) = delete;
72     IPCTrace(IPCTrace &&other) = delete;
73     IPCTrace &operator=(IPCTrace &&other) = delete;
74 
75     void Load();
76     void Unload();
77 
78     using IsTagEnabledFunc = bool(*)(uint64_t);
79     using StartFunc = void(*)(uint64_t, const std::string &);
80     using EndFunc = void(*)(uint64_t);
81     using StartAsyncFunc = void(*)(uint64_t, const std::string &, int32_t);
82     using EndAsyncFunc = void(*)(uint64_t, const std::string &, int32_t);
83 
84     static constexpr uint64_t HITRACE_TAG_RPC = (1ULL << 46);
85     static std::string HITRACE_METER_SO_NAME;
86 
87     void *traceSoHandler_ = nullptr;
88     IsTagEnabledFunc isTagEnabledFunc_ = nullptr;
89     StartFunc startFunc_ = nullptr;
90     EndFunc finishFunc_ = nullptr;
91     StartAsyncFunc startAsyncFunc_ = nullptr;
92     EndAsyncFunc finishAsyncFunc_ = nullptr;
93 };
94 } // namespace OHOS
95 #endif // OHOS_IPC_IPC_TRACE_H