• 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 /**
17  * @addtogroup HiDebug
18  * @{
19  *
20  * @brief Provides debug code define.
21  *
22  * For example, you can use these code for check result or parameter of HiDebug function.
23  *
24  * @since 12
25  */
26 
27 /**
28  * @file hidebug_type.h
29  *
30  * @brief Defines the code of the HiDebug module.
31  *
32  * @kit PerformanceAnalysisKit
33  * @library libohhidebug.so
34  * @syscap SystemCapability.HiviewDFX.HiProfiler.HiDebug
35  * @since 12
36  */
37 
38 #ifndef HIVIEWDFX_HIDEBUG_TYPE_H
39 #define HIVIEWDFX_HIDEBUG_TYPE_H
40 
41 #include <stdint.h>
42 #include <stddef.h>
43 #include <unistd.h>
44 #ifdef __cplusplus
45 extern "C" {
46 #endif // __cplusplus
47 
48 /**
49  * @brief Defines error code
50  *
51  * @since 12
52  */
53 typedef enum HiDebug_ErrorCode {
54     /** Success */
55     HIDEBUG_SUCCESS = 0,
56     /** Invalid argument */
57     HIDEBUG_INVALID_ARGUMENT = 401,
58     /** Have already capture trace */
59     HIDEBUG_TRACE_CAPTURED_ALREADY = 11400102,
60     /** No write permission on the file */
61     HIDEBUG_NO_PERMISSION = 11400103,
62     /** The status of the trace is abnormal */
63     HIDEBUG_TRACE_ABNORMAL = 11400104,
64     /** No trace running */
65     HIDEBUG_NO_TRACE_RUNNING = 11400105,
66     /**
67      * The pc passed to the symbolic function is invalid
68      * @since 20
69      */
70     HIDEBUG_INVALID_SYMBOLIC_PC_ADDRESS = 11400200,
71 } HiDebug_ErrorCode;
72 
73 /**
74  * @brief Defines application cpu usage of all threads structure type.
75  *
76  * @since 12
77  */
78 typedef struct HiDebug_ThreadCpuUsage {
79     /**
80      * Thread id
81      */
82     uint32_t threadId;
83     /**
84      * Cpu usage of thread
85      */
86     double cpuUsage;
87     /**
88      * Next thread cpu usage
89      */
90     struct HiDebug_ThreadCpuUsage *next;
91 } HiDebug_ThreadCpuUsage;
92 
93 /**
94  * @brief Defines pointer of HiDebug_ThreadCpuUsage.
95  *
96  * @since 12
97  */
98 typedef HiDebug_ThreadCpuUsage* HiDebug_ThreadCpuUsagePtr;
99 
100 /**
101  * @brief Defines system memory information structure type.
102  *
103  * @since 12
104  */
105 typedef struct HiDebug_SystemMemInfo {
106     /**
107      * Total system memory size, in kibibytes
108      */
109     uint32_t totalMem;
110     /**
111      * System free memory size, in kibibytes
112      */
113     uint32_t freeMem;
114     /**
115      * System available memory size, in kibibytes
116      */
117     uint32_t availableMem;
118 } HiDebug_SystemMemInfo;
119 
120 /**
121  * @brief Defines application process native memory information structure type.
122  *
123  * @since 12
124  */
125 typedef struct HiDebug_NativeMemInfo {
126     /**
127      * Process proportional set size memory, in kibibytes
128      */
129     uint32_t pss;
130     /**
131      * Virtual set size memory, in kibibytes
132      */
133     uint32_t vss;
134     /**
135      * Resident set size, in kibibytes
136      */
137     uint32_t rss;
138     /**
139      * The size of the shared dirty memory, in kibibytes
140      */
141     uint32_t sharedDirty;
142     /**
143      * The size of the private dirty memory, in kibibytes
144      */
145     uint32_t privateDirty;
146     /**
147      * The size of the shared clean memory, in kibibytes
148      */
149     uint32_t sharedClean;
150     /**
151      * The size of the private clean memory, in kibibytes
152      */
153     uint32_t privateClean;
154 } HiDebug_NativeMemInfo;
155 
156 /**
157  * @brief Defines application process memory limit structure type.
158  *
159  * @since 12
160  */
161 typedef struct HiDebug_MemoryLimit {
162     /**
163      * The limit of the application process's resident set, in kibibytes
164      */
165     uint64_t rssLimit;
166     /**
167      * The limit of the application process's virtual memory, in kibibytes
168      */
169     uint64_t vssLimit;
170 } HiDebug_MemoryLimit;
171 
172 /**
173  * @brief Enum for trace flag.
174  *
175  * @since 12
176  */
177 typedef enum HiDebug_TraceFlag {
178     /** Only capture main thread trace */
179     HIDEBUG_TRACE_FLAG_MAIN_THREAD = 1,
180     /** Capture all thread trace */
181     HIDEBUG_TRACE_FLAG_ALL_THREADS = 2
182 } HiDebug_TraceFlag;
183 
184 /**
185  * @brief Defines structure type of malloc dispatch table.
186  *
187  * @since 20
188 */
189 typedef struct HiDebug_MallocDispatch {
190     void* (*malloc)(size_t);
191     void* (*calloc)(size_t, size_t);
192     void* (*realloc)(void*, size_t);
193     void (*free)(void*);
194     void* (*mmap) (void*, size_t, int, int, int, off_t);
195     int (*munmap) (void*, size_t);
196 } HiDebug_MallocDispatch;
197 
198 /**
199  * @brief Defines Js stack frame content
200  *
201  * @since 20
202  */
203 typedef struct HiDebug_JsStackFrame {
204     /**
205      * The pc relative to the start of current file in /proc/self/maps
206      */
207     uint64_t relativePc;
208 
209     /**
210      * The line number of the source code from url
211      */
212     int32_t line;
213 
214     /**
215      * The column number of the source code from url
216      */
217     int32_t column;
218 
219     /**
220      * The name parsed by pc from /proc/self/maps, maybe NULL
221      */
222     const char* mapName;
223 
224     /**
225      * The functionName of current frame, maybe NULL
226      */
227     const char* functionName;
228 
229     /**
230      * The url of current frame, maybe NULL
231      */
232     const char* url;
233 
234     /**
235      * The packageName of current frame, maybe NULL
236      */
237     const char* packageName;
238 } HiDebug_JsStackFrame;
239 
240 /**
241  * @brief Defines native frame content
242  *
243  * @since 20
244  */
245 typedef struct HiDebug_NativeStackFrame {
246     /**
247      * The pc relative to the start of current file in /proc/self/maps
248      */
249     uint64_t relativePc;
250 
251     /**
252      * The pc relative to the start of current function
253      */
254     uint64_t funcOffset;
255 
256     /**
257      * The name parsed by pc from /proc/self/maps
258      */
259     const char* mapName;
260 
261     /**
262      * The functionName parsed by relativePc from symbol table in elf, maybe NULL
263      */
264     const char* functionName;
265 
266     /**
267      * The buildId parsed from .note.gnu.build-id in elf, maybe NULL
268      */
269     const char* buildId;
270 
271     /**
272      * Reserved, maybe NULL
273      */
274     const char* reserved;
275 } HiDebug_NativeStackFrame;
276 
277 /**
278  * @brief Enum for stack frame type.
279  *
280  * @since 20
281  */
282 typedef enum HiDebug_StackFrameType {
283     /** Type of js frame */
284     HIDEBUG_STACK_FRAME_TYPE_JS = 1,
285     /** Type of native frame */
286     HIDEBUG_STACK_FRAME_TYPE_NATIVE = 2,
287 } HiDebug_StackFrameType;
288 
289 /**
290  * @brief Defines Stack Frame content
291  *
292  * @since 20
293  */
294 typedef struct HiDebug_StackFrame {
295     /**
296      * The type of current frame
297      */
298     HiDebug_StackFrameType type;
299 
300     /** frame content. */
301     union {
302         /** Js stack frame defined in {@link HiDebug_JsStackFrame} */
303         struct HiDebug_JsStackFrame js;
304         /** Native frame defined in {@link HiDebug_NativeStackFrame} */
305         struct HiDebug_NativeStackFrame native;
306     } frame;
307 } HiDebug_StackFrame;
308 
309 /**
310  * @brief To represent a backtrace object
311  *
312  * @since 20
313  */
314 typedef struct HiDebug_Backtrace_Object__* HiDebug_Backtrace_Object;
315 
316 #ifdef __cplusplus
317 }
318 #endif // __cplusplus
319 
320 /**
321  * @brief FFRT tasks.
322  *
323  * @since 12
324  */
325 #define HIDEBUG_TRACE_TAG_FFRT (1ULL << 13)
326 /**
327  * @brief Common library subsystem tag.
328  *
329  * @since 12
330  */
331 #define HIDEBUG_TRACE_TAG_COMMON_LIBRARY (1ULL << 16)
332 /**
333  * @brief HDF subsystem tag.
334  *
335  * @since 12
336  */
337 #define HIDEBUG_TRACE_TAG_HDF (1ULL << 18)
338 /**
339  * @brief Net tag.
340  *
341  * @since 12
342  */
343 #define HIDEBUG_TRACE_TAG_NET (1ULL << 23)
344 /**
345  * @brief NWeb tag.
346  *
347  * @since 12
348  */
349 #define HIDEBUG_TRACE_TAG_NWEB (1ULL << 24)
350 /**
351  * @brief Distributed audio tag.
352  *
353  * @since 12
354  */
355 #define HIDEBUG_TRACE_TAG_DISTRIBUTED_AUDIO (1ULL << 27)
356 /**
357  * @brief File management tag.
358  *
359  * @since 12
360  */
361 #define HIDEBUG_TRACE_TAG_FILE_MANAGEMENT (1ULL << 29)
362 /**
363  * @brief OHOS generic tag.
364  *
365  * @since 12
366  */
367 #define HIDEBUG_TRACE_TAG_OHOS (1ULL << 30)
368 /**
369  * @brief Ability Manager tag.
370  *
371  * @since 12
372  */
373 #define HIDEBUG_TRACE_TAG_ABILITY_MANAGER (1ULL << 31)
374 /**
375  * @brief Camera module tag.
376  *
377  * @since 12
378  */
379 #define HIDEBUG_TRACE_TAG_CAMERA (1ULL << 32)
380 /**
381  * @brief Media module tag.
382  *
383  * @since 12
384  */
385 #define HIDEBUG_TRACE_TAG_MEDIA (1ULL << 33)
386 /**
387  * @brief Image module tag.
388  *
389  * @since 12
390  */
391 #define HIDEBUG_TRACE_TAG_IMAGE (1ULL << 34)
392 /**
393  * @brief Audio module tag.
394  *
395  * @since 12
396  */
397 #define HIDEBUG_TRACE_TAG_AUDIO (1ULL << 35)
398 /**
399  * @brief Distributed data manager module tag.
400  *
401  * @since 12
402  */
403 #define HIDEBUG_TRACE_TAG_DISTRIBUTED_DATA (1ULL << 36)
404 /**
405  * @brief Graphics module tag.
406  *
407  * @since 12
408  */
409 #define HIDEBUG_TRACE_TAG_GRAPHICS (1ULL << 38)
410 /**
411  * @brief ARKUI development framework tag.
412  *
413  * @since 12
414  */
415 #define HIDEBUG_TRACE_TAG_ARKUI (1ULL << 39)
416 /**
417  * @brief Notification module tag.
418  *
419  * @since 12
420  */
421 #define HIDEBUG_TRACE_TAG_NOTIFICATION (1ULL << 40)
422 /**
423  * @brief MISC module tag.
424  *
425  * @since 12
426  */
427 #define HIDEBUG_TRACE_TAG_MISC (1ULL << 41)
428 /**
429  * @brief Multimodal input module tag.
430  *
431  * @since 12
432  */
433 #define HIDEBUG_TRACE_TAG_MULTIMODAL_INPUT (1ULL << 42)
434 /**
435  * @brief RPC tag.
436  *
437  * @since 12
438  */
439 #define HIDEBUG_TRACE_TAG_RPC (1ULL << 46)
440 /**
441  * @brief ARK tag.
442  *
443  * @since 12
444  */
445 #define HIDEBUG_TRACE_TAG_ARK (1ULL << 47)
446 /**
447  * @brief Window manager tag.
448  *
449  * @since 12
450  */
451 #define HIDEBUG_TRACE_TAG_WINDOW_MANAGER (1ULL << 48)
452 /**
453  * @brief Distributed screen tag.
454  *
455  * @since 12
456  */
457 #define HIDEBUG_TRACE_TAG_DISTRIBUTED_SCREEN (1ULL << 50)
458 /**
459  * @brief Distributed camera tag.
460  *
461  * @since 12
462  */
463 #define HIDEBUG_TRACE_TAG_DISTRIBUTED_CAMERA (1ULL << 51)
464 /**
465  * @brief Distributed hardware framework tag.
466  *
467  * @since 12
468  */
469 #define HIDEBUG_TRACE_TAG_DISTRIBUTED_HARDWARE_FRAMEWORK (1ULL << 52)
470 /**
471  * @brief Global resource manager tag.
472  *
473  * @since 12
474  */
475 #define HIDEBUG_TRACE_TAG_GLOBAL_RESOURCE_MANAGER (1ULL << 53)
476 /**
477  * @brief Distributed hardware device manager tag.
478  *
479  * @since 12
480  */
481 #define HIDEBUG_TRACE_TAG_DISTRIBUTED_HARDWARE_DEVICE_MANAGER (1ULL << 54)
482 /**
483  * @brief SA tag.
484  *
485  * @since 12
486  */
487 #define HIDEBUG_TRACE_TAG_SAMGR (1ULL << 55)
488 /**
489  * @brief Power manager tag.
490  *
491  * @since 12
492  */
493 #define HIDEBUG_TRACE_TAG_POWER_MANAGER (1ULL << 56)
494 /**
495  * @brief Distributed scheduler tag.
496  *
497  * @since 12
498  */
499 #define HIDEBUG_TRACE_TAG_DISTRIBUTED_SCHEDULER (1ULL << 57)
500 /**
501  * @brief Distributed input tag.
502  *
503  * @since 12
504  */
505 #define HIDEBUG_TRACE_TAG_DISTRIBUTED_INPUT (1ULL << 59)
506 /**
507  * @brief bluetooth tag.
508  *
509  * @since 12
510  */
511 #define HIDEBUG_TRACE_TAG_BLUETOOTH (1ULL << 60)
512 
513 /** @} */
514 
515 #endif // HIVIEWDFX_HIDEBUG_TYPE_H