• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
3  * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice, this list of
9  *    conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice, this list
12  *    of conditions and the following disclaimer in the documentation and/or other materials
13  *    provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors may be used
16  *    to endorse or promote products derived from this software without specific prior written
17  *    permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 /**
33  * @defgroup los_trace Trace
34  * @ingroup kernel
35  */
36 
37 #ifndef _LOS_TRACE_H
38 #define _LOS_TRACE_H
39 
40 #include "los_task.h"
41 #include "los_base.h"
42 
43 #ifdef __cplusplus
44 #if __cplusplus
45 extern "C" {
46 #endif /* __cplusplus */
47 #endif /* __cplusplus */
48 
49 #ifdef LOSCFG_TRACE_CONTROL_AGENT
50 
51 /**
52  * @ingroup los_trace
53  * Trace Control agent task's priority.
54  */
55 #define LOSCFG_TRACE_TASK_PRIORITY                              2
56 #endif
57 
58 #define LOSCFG_TRACE_OBJ_MAX_NAME_SIZE                          LOS_TASK_NAMELEN
59 
60 #define LOS_TRACE_LR_RECORD                                     5
61 #define LOS_TRACE_LR_IGNORE                                     0
62 /**
63  * @ingroup los_trace
64  * Trace records the max number of objects(kernel object, like tasks), range is [0, LOSCFG_BASE_CORE_TSK_LIMIT].
65  * if set to 0, trace will not record any object.
66  */
67 #define LOSCFG_TRACE_OBJ_MAX_NUM                                0
68 
69 /**
70  * @ingroup los_trace
71  * Trace tlv encode buffer size, the buffer is used to encode one piece raw frame to tlv message in online mode.
72  */
73 #define LOSCFG_TRACE_TLV_BUF_SIZE                               100
74 
75 /**
76  * @ingroup los_trace
77  * Trace error code: init trace failed.
78  *
79  * Value: 0x02001400
80  *
81  * Solution: Follow the trace State Machine.
82  */
83 #define LOS_ERRNO_TRACE_ERROR_STATUS               LOS_ERRNO_OS_ERROR(LOS_MOD_TRACE, 0x00)
84 
85 /**
86  * @ingroup los_trace
87  * Trace error code: Insufficient memory for trace buf init.
88  *
89  * Value: 0x02001401
90  *
91  * Solution: Expand the configured system memory or decrease the value defined by LOS_TRACE_BUFFER_SIZE.
92  */
93 #define LOS_ERRNO_TRACE_NO_MEMORY                  LOS_ERRNO_OS_ERROR(LOS_MOD_TRACE, 0x01)
94 
95 /**
96  * @ingroup los_trace
97  * Trace error code: Insufficient memory for trace struct.
98  *
99  * Value: 0x02001402
100  *
101  * Solution: Increase trace buffer's size.
102  */
103 #define LOS_ERRNO_TRACE_BUF_TOO_SMALL              LOS_ERRNO_OS_ERROR(LOS_MOD_TRACE, 0x02)
104 
105 /**
106  * @ingroup los_trace
107  * Trace state.
108  */
109 enum TraceState {
110     TRACE_UNINIT = 0,  /**< trace isn't inited */
111     TRACE_INITED,      /**< trace is inited but not started yet */
112     TRACE_STARTED,     /**< trace is started and system is tracing */
113     TRACE_STOPED,      /**< trace is stopped */
114 };
115 
116 /**
117  * @ingroup los_trace
118  * Trace mask is used to filter events in runtime. Each mask keep only one unique bit to 1, and user can define own
119  * module's trace mask.
120  */
121 typedef enum {
122     TRACE_SYS_FLAG          = 0x10,
123     TRACE_HWI_FLAG          = 0x20,
124     TRACE_TASK_FLAG         = 0x40,
125     TRACE_SWTMR_FLAG        = 0x80,
126     TRACE_MEM_FLAG          = 0x100,
127     TRACE_QUE_FLAG          = 0x200,
128     TRACE_EVENT_FLAG        = 0x400,
129     TRACE_SEM_FLAG          = 0x800,
130     TRACE_MUX_FLAG          = 0x1000,
131     TRACE_IPC_FLAG          = 0x2000,
132 
133     TRACE_MAX_FLAG          = 0x80000000,
134     TRACE_USER_DEFAULT_FLAG = 0xFFFFFFF0,
135 } LOS_TRACE_MASK;
136 
137 /**
138  * @ingroup los_trace
139  * Trace event type which indicate the exactly happened events, user can define own module's event type like
140  * TRACE_#MODULE#_FLAG | NUMBER.
141  *                   28                     4
142  *    0 0 0 0 0 0 0 0 X X X X X X X X 0 0 0 0 0 0
143  *    |                                   |     |
144  *             trace_module_flag           number
145  *
146  */
147 typedef enum {
148     /* 0x10~0x1F */
149     SYS_ERROR             = TRACE_SYS_FLAG | 0,
150     SYS_START             = TRACE_SYS_FLAG | 1,
151     SYS_STOP              = TRACE_SYS_FLAG | 2,
152 
153     /* 0x20~0x2F */
154     HWI_CREATE              = TRACE_HWI_FLAG | 0,
155     HWI_CREATE_SHARE        = TRACE_HWI_FLAG | 1,
156     HWI_DELETE              = TRACE_HWI_FLAG | 2,
157     HWI_DELETE_SHARE        = TRACE_HWI_FLAG | 3,
158     HWI_RESPONSE_IN         = TRACE_HWI_FLAG | 4,
159     HWI_RESPONSE_OUT        = TRACE_HWI_FLAG | 5,
160     HWI_ENABLE              = TRACE_HWI_FLAG | 6,
161     HWI_DISABLE             = TRACE_HWI_FLAG | 7,
162     HWI_TRIGGER             = TRACE_HWI_FLAG | 8,
163     HWI_SETPRI              = TRACE_HWI_FLAG | 9,
164     HWI_CLEAR               = TRACE_HWI_FLAG | 10,
165     HWI_SETAFFINITY         = TRACE_HWI_FLAG | 11,
166     HWI_SENDIPI             = TRACE_HWI_FLAG | 12,
167 
168     /* 0x40~0x4F */
169     TASK_CREATE           = TRACE_TASK_FLAG | 0,
170     TASK_PRIOSET          = TRACE_TASK_FLAG | 1,
171     TASK_DELETE           = TRACE_TASK_FLAG | 2,
172     TASK_SUSPEND          = TRACE_TASK_FLAG | 3,
173     TASK_RESUME           = TRACE_TASK_FLAG | 4,
174     TASK_SWITCH           = TRACE_TASK_FLAG | 5,
175     TASK_SIGNAL           = TRACE_TASK_FLAG | 6,
176 
177     /* 0x80~0x8F */
178     SWTMR_CREATE          = TRACE_SWTMR_FLAG | 0,
179     SWTMR_DELETE          = TRACE_SWTMR_FLAG | 1,
180     SWTMR_START           = TRACE_SWTMR_FLAG | 2,
181     SWTMR_STOP            = TRACE_SWTMR_FLAG | 3,
182     SWTMR_EXPIRED         = TRACE_SWTMR_FLAG | 4,
183 
184     /* 0x100~0x10F */
185     MEM_ALLOC             = TRACE_MEM_FLAG | 0,
186     MEM_ALLOC_ALIGN       = TRACE_MEM_FLAG | 1,
187     MEM_REALLOC           = TRACE_MEM_FLAG | 2,
188     MEM_FREE              = TRACE_MEM_FLAG | 3,
189     MEM_INFO_REQ          = TRACE_MEM_FLAG | 4,
190     MEM_INFO              = TRACE_MEM_FLAG | 5,
191 
192     /* 0x200~0x20F */
193     QUEUE_CREATE          = TRACE_QUE_FLAG | 0,
194     QUEUE_DELETE          = TRACE_QUE_FLAG | 1,
195     QUEUE_RW              = TRACE_QUE_FLAG | 2,
196 
197     /* 0x400~0x40F */
198     EVENT_CREATE          = TRACE_EVENT_FLAG | 0,
199     EVENT_DELETE          = TRACE_EVENT_FLAG | 1,
200     EVENT_READ            = TRACE_EVENT_FLAG | 2,
201     EVENT_WRITE           = TRACE_EVENT_FLAG | 3,
202     EVENT_CLEAR           = TRACE_EVENT_FLAG | 4,
203 
204     /* 0x800~0x80F */
205     SEM_CREATE            = TRACE_SEM_FLAG | 0,
206     SEM_DELETE            = TRACE_SEM_FLAG | 1,
207     SEM_PEND              = TRACE_SEM_FLAG | 2,
208     SEM_POST              = TRACE_SEM_FLAG | 3,
209 
210     /* 0x1000~0x100F */
211     MUX_CREATE            = TRACE_MUX_FLAG | 0,
212     MUX_DELETE            = TRACE_MUX_FLAG | 1,
213     MUX_PEND              = TRACE_MUX_FLAG | 2,
214     MUX_POST              = TRACE_MUX_FLAG | 3,
215 
216     /* 0x2000~0x200F */
217     IPC_WRITE_DROP        = TRACE_IPC_FLAG | 0,
218     IPC_WRITE             = TRACE_IPC_FLAG | 1,
219     IPC_READ_DROP         = TRACE_IPC_FLAG | 2,
220     IPC_READ              = TRACE_IPC_FLAG | 3,
221     IPC_TRY_READ          = TRACE_IPC_FLAG | 4,
222     IPC_READ_TIMEOUT      = TRACE_IPC_FLAG | 5,
223     IPC_KILL              = TRACE_IPC_FLAG | 6,
224 } LOS_TRACE_TYPE;
225 
226 /**
227  * @ingroup los_trace
228  * struct to store the trace config information.
229  */
230 typedef struct {
231     UINT32 bigLittleEndian;     /**< big little endian flag */
232     UINT32 clockFreq;           /**< system clock frequency */
233     UINT32 version;             /**< trace version */
234 } TraceBaseHeaderInfo;
235 
236 /**
237  * @ingroup los_trace
238  * struct to store the event information
239  */
240 typedef struct {
241     UINT32  eventType;                               /**< event type */
242     UINT32  curTask;                                 /**< current running task */
243     UINT32  curPid;                                  /**< current running processID */
244     UINT64  curTime;                                 /**< current timestamp */
245     UINTPTR identity;                                /**< subject of the event description */
246 #ifdef LOSCFG_TRACE_FRAME_CORE_MSG
247     struct CoreStatus {
248         UINT32 cpuid      : 8,                       /**< cpuid */
249                hwiActive  : 4,                       /**< whether is in hwi response */
250                taskLockCnt : 4,                      /**< task lock count */
251                paramCount : 4,                       /**< event frame params' number */
252                reserves   : 12;                      /**< reserves */
253     } core;
254 #endif
255 
256 #ifdef LOSCFG_TRACE_FRAME_EVENT_COUNT
257     UINT32  eventCount;                               /**< the sequence of happened events */
258 #endif
259 
260 #ifdef LOS_TRACE_FRAME_LR
261     UINTPTR linkReg[LOS_TRACE_LR_RECORD];
262 #endif
263 
264 #ifdef LOSCFG_TRACE_FRAME_MAX_PARAMS
265     UINTPTR params[LOSCFG_TRACE_FRAME_MAX_PARAMS];    /**< event frame's params */
266 #endif
267 } TraceEventFrame;
268 
269 #ifdef LOSCFG_DRIVERS_TRACE
270 typedef struct {
271     UINT32  eventType;
272     UINTPTR identity;
273     UINTPTR params[3];
274 } UsrEventInfo;
275 #endif
276 
277 /**
278  * @ingroup los_trace
279  * struct to store the kernel obj information, we defined task as kernel obj in this system.
280  */
281 typedef struct {
282     UINT32      id;                                     /**< kernel obj's id */
283     UINT32      prio;                                   /**< kernel obj's priority */
284     CHAR        name[LOSCFG_TRACE_OBJ_MAX_NAME_SIZE];   /**< kernel obj's name */
285 } ObjData;
286 
287 /**
288  * @ingroup los_trace
289  * struct to store the trace data.
290  */
291 typedef struct {
292     TraceBaseHeaderInfo baseInfo;          /**< basic info, include bigLittleEndian flag, system clock freq */
293     UINT16 totalLen;                       /**< trace data's total length */
294     UINT16 objSize;                        /**< sizeof #ObjData */
295     UINT16 frameSize;                      /**< sizeof #TraceEventFrame */
296     UINT16 objOffset;                      /**< the offset of the first obj data to record beginning */
297     UINT16 frameOffset;                    /**< the offset of the first event frame data to record beginning */
298 } OfflineHead;
299 
300 /**
301  * @ingroup  los_trace
302  * @brief Define the type of trace hardware interrupt filter hook function.
303  *
304  * @par Description:
305  * User can register filter function by LOS_TraceHwiFilterHookReg to filter hardware interrupt events. Return true if
306  * user don't need trace the certain number.
307  *
308  * @attention
309  * None.
310  *
311  * @param hwiNum        [IN] Type #UINT32. The hardware interrupt number.
312  * @retval #TRUE        0x00000001: Not record the certain number.
313  * @retval #FALSE       0x00000000: Need record the certain number.
314  *
315  * @par Dependency:
316  * <ul><li>los_trace.h: the header file that contains the API declaration.</li></ul>
317  */
318 typedef BOOL (*TRACE_HWI_FILTER_HOOK)(UINT32 hwiNum);
319 
320 typedef VOID (*TRACE_EVENT_HOOK)(UINT32 eventType, UINTPTR identity, const UINTPTR *params, UINT16 paramCount);
321 extern TRACE_EVENT_HOOK g_traceEventHook;
322 
323 /**
324  * @ingroup los_trace
325  * Trace event params:
326  1. Configure the macro without parameters so as not to record events of this type;
327  2. Configure the macro at least with one parameter to record this type of event;
328  3. User can delete unnecessary parameters which defined in corresponding marco;
329  * @attention
330  * <ul>
331  * <li>The first param is treat as key, keep at least this param if you want trace this event.</li>
332  * <li>All parameters were treated as UINTPTR.</li>
333  * </ul>
334  * eg. Trace an event as:
335  * #define TASK_PRIOSET_PARAMS(taskId, taskStatus, oldPrio, newPrio) taskId, taskStatus, oldPrio, newPrio
336  * eg. Not Trace an event as:
337  * #define TASK_PRIOSET_PARAMS(taskId, taskStatus, oldPrio, newPrio)
338  * eg. Trace only you need parmas as:
339  * #define TASK_PRIOSET_PARAMS(taskId, taskStatus, oldPrio, newPrio) taskId
340  */
341 #define TASK_SWITCH_PARAMS(taskId, oldPriority, oldTaskStatus, newPriority, newTaskStatus) \
342     taskId, oldPriority, oldTaskStatus, newPriority, newTaskStatus
343 #define TASK_PRIOSET_PARAMS(taskId, taskStatus, oldPrio, newPrio) taskId, taskStatus, oldPrio, newPrio
344 #define TASK_CREATE_PARAMS(taskId, taskStatus, prio)     taskId, taskStatus, prio
345 #define TASK_DELETE_PARAMS(taskId, taskStatus, usrStack) taskId, taskStatus, usrStack
346 #define TASK_SUSPEND_PARAMS(taskId, taskStatus, runTaskId) taskId, taskStatus, runTaskId
347 #define TASK_RESUME_PARAMS(taskId, taskStatus, prio)     taskId, taskStatus, prio
348 #define TASK_SIGNAL_PARAMS(taskId, signal, schedFlag)    // taskId, signal, schedFlag
349 
350 #define SWTMR_START_PARAMS(swtmrId, mode, interval)  swtmrId, mode, interval
351 #define SWTMR_DELETE_PARAMS(swtmrId)                                  swtmrId
352 #define SWTMR_EXPIRED_PARAMS(swtmrId)                                 swtmrId
353 #define SWTMR_STOP_PARAMS(swtmrId)                                    swtmrId
354 #define SWTMR_CREATE_PARAMS(swtmrId)                                  swtmrId
355 
356 #define HWI_CREATE_PARAMS(hwiNum, hwiPrio, hwiMode, hwiHandler) hwiNum, hwiPrio, hwiMode, hwiHandler
357 #define HWI_CREATE_SHARE_PARAMS(hwiNum, pDevId, ret)    hwiNum, pDevId, ret
358 #define HWI_DELETE_PARAMS(hwiNum)                       hwiNum
359 #define HWI_DELETE_SHARE_PARAMS(hwiNum, pDevId, ret)    hwiNum, pDevId, ret
360 #define HWI_RESPONSE_IN_PARAMS(hwiNum)                  hwiNum
361 #define HWI_RESPONSE_OUT_PARAMS(hwiNum)                 hwiNum
362 #define HWI_ENABLE_PARAMS(hwiNum)                       hwiNum
363 #define HWI_DISABLE_PARAMS(hwiNum)                      hwiNum
364 #define HWI_TRIGGER_PARAMS(hwiNum)                      hwiNum
365 #define HWI_SETPRI_PARAMS(hwiNum, priority)             hwiNum, priority
366 #define HWI_CLEAR_PARAMS(hwiNum)                        hwiNum
367 #define HWI_SETAFFINITY_PARAMS(hwiNum, cpuMask)         hwiNum, cpuMask
368 #define HWI_SENDIPI_PARAMS(hwiNum, cpuMask)             hwiNum, cpuMask
369 
370 #define EVENT_CREATE_PARAMS(eventCB)                    eventCB
371 #define EVENT_DELETE_PARAMS(eventCB, delRetCode)        eventCB, delRetCode
372 #define EVENT_READ_PARAMS(eventCB, eventId, mask, mode, timeout) \
373     eventCB, eventId, mask, mode, timeout
374 #define EVENT_WRITE_PARAMS(eventCB, eventId, events)    eventCB, eventId, events
375 #define EVENT_CLEAR_PARAMS(eventCB, eventId, events)    eventCB, eventId, events
376 
377 #define QUEUE_CREATE_PARAMS(queueId, queueSz, itemSz, queueAddr, memType) \
378     queueId, queueSz, itemSz, queueAddr, memType
379 #define QUEUE_DELETE_PARAMS(queueId, state, readable)   queueId, state, readable
380 #define QUEUE_RW_PARAMS(queueId, queueSize, bufSize, operateType, readable, writable, timeout) \
381     queueId, queueSize, bufSize, operateType, readable, writable, timeout
382 
383 #define SEM_CREATE_PARAMS(semId, type, count)           semId, type, count
384 #define SEM_DELETE_PARAMS(semId, delRetCode)            semId, delRetCode
385 #define SEM_PEND_PARAMS(semId, count, timeout)          semId, count, timeout
386 #define SEM_POST_PARAMS(semId, type, count)             semId, type, count
387 
388 #define MUX_CREATE_PARAMS(muxId)                        muxId
389 #define MUX_DELETE_PARAMS(muxId, state, count, owner)   muxId, state, count, owner
390 #define MUX_PEND_PARAMS(muxId, count, owner, timeout)   muxId, count, owner, timeout
391 #define MUX_POST_PARAMS(muxId, count, owner)            muxId, count, owner
392 
393 #define MEM_ALLOC_PARAMS(pool, ptr, size)                   pool, ptr, size
394 #define MEM_ALLOC_ALIGN_PARAMS(pool, ptr, size, boundary)   pool, ptr, size, boundary
395 #define MEM_REALLOC_PARAMS(pool, ptr, size)                 pool, ptr, size
396 #define MEM_FREE_PARAMS(pool, ptr)                          pool, ptr
397 #define MEM_INFO_REQ_PARAMS(pool)                           pool
398 #define MEM_INFO_PARAMS(pool, usedSize, freeSize)           pool, usedSize, freeSize
399 
400 #define IPC_WRITE_DROP_PARAMS(dstTid, dstPid, msgType, code, ipcStatus)   \
401     dstTid, dstPid, msgType, code, ipcStatus
402 #define IPC_WRITE_PARAMS(dstTid, dstPid, msgType, code, ipcStatus)        \
403     dstTid, dstPid, msgType, code, ipcStatus
404 #define IPC_READ_DROP_PARAMS(srcTid, srcPid, msgType, code, ipcStatus)    \
405     srcTid, srcPid, msgType, code, ipcStatus
406 #define IPC_READ_PARAMS(srcTid, srcPid, msgType, code, ipcStatus)         \
407     srcTid, srcPid, msgType, code, ipcStatus
408 #define IPC_TRY_READ_PARAMS(msgType, ipcStatus)      msgType, ipcStatus
409 #define IPC_READ_TIMEOUT_PARAMS(msgType, ipcStatus)  msgType, ipcStatus
410 #define IPC_KILL_PARAMS(msgType, ipcStatus)          msgType, ipcStatus
411 
412 #define SYS_ERROR_PARAMS(errno)                         errno
413 
414 #ifdef LOSCFG_KERNEL_TRACE
415 
416 /**
417  * @ingroup los_trace
418  * @brief Trace static code stub.
419  *
420  * @par Description:
421  * This API is used to instrument trace code stub in source code, to track events.
422  * @attention
423  * None.
424  *
425  * @param TYPE           [IN] Type #LOS_TRACE_TYPE. The event type.
426  * @param IDENTITY       [IN] Type #UINTPTR. The subject of this event description.
427  * @param ...            [IN] Type #UINTPTR. This piece of event's params.
428  * @retval None.
429  *
430  * @par Dependency:
431  * <ul><li>los_trace.h: the header file that contains the API declaration.</li></ul>
432  */
433 #define LOS_TRACE(TYPE, IDENTITY, ...)                                             \
434     do {                                                                           \
435         UINTPTR _inner[] = {0, TYPE##_PARAMS((UINTPTR)IDENTITY, ##__VA_ARGS__)};   \
436         UINTPTR _n = sizeof(_inner) / sizeof(UINTPTR);                             \
437         if ((_n > 1) && (g_traceEventHook != NULL)) {                              \
438             g_traceEventHook(TYPE, _inner[1], _n > 2 ? &_inner[2] : NULL, _n - 2); \
439         }                                                                          \
440     } while (0)
441 #else
442 #define LOS_TRACE(TYPE, ...)
443 #endif
444 
445 #ifdef LOSCFG_KERNEL_TRACE
446 
447 /**
448  * @ingroup los_trace
449  * @brief Trace static easier user-defined code stub.
450  *
451  * @par Description:
452  * This API is used to instrument user-defined trace code stub in source code, to track events simply.
453  * @attention
454  * None.
455  *
456  * @param TYPE           [IN] Type #UINT32. The event type, only low 4 bits take effect.
457  * @param IDENTITY       [IN] Type #UINTPTR. The subject of this event description.
458  * @param ...            [IN] Type #UINTPTR. This piece of event's params.
459  * @retval None.
460  *
461  * @par Dependency:
462  * <ul><li>los_trace.h: the header file that contains the API declaration.</li></ul>
463  */
464 #define LOS_TRACE_EASY(TYPE, IDENTITY, ...)                                                                          \
465     do {                                                                                                             \
466         UINTPTR _inner[] = {0, ##__VA_ARGS__};                                                                       \
467         UINTPTR _n = sizeof(_inner) / sizeof(UINTPTR);                                                               \
468         if (g_traceEventHook != NULL) {                                                                              \
469             g_traceEventHook(TRACE_USER_DEFAULT_FLAG | TYPE, (UINTPTR)IDENTITY, _n > 1 ? &_inner[1] : NULL, _n - 1); \
470         }                                                                                                            \
471     } while (0)
472 #else
473 #define LOS_TRACE_EASY(...)
474 #endif
475 
476 /**
477  * @ingroup los_trace
478  * @brief Start trace.
479  *
480  * @par Description:
481  * This API is used to start trace.
482  * @attention
483  * <ul>
484  * <li>Start trace</li>
485  * </ul>
486  *
487  * @param  None.
488  * @retval #LOS_ERRNO_TRACE_ERROR_STATUS        0x02001400: Trace start failed.
489  * @retval #LOS_OK                              0x00000000: Trace start success.
490  *
491  * @par Dependency:
492  * <ul><li>los_trace.h: the header file that contains the API declaration.</li></ul>
493  * @see LOS_TraceStart
494  */
495 extern UINT32 LOS_TraceStart(VOID);
496 
497 /**
498  * @ingroup los_trace
499  * @brief Stop trace.
500  *
501  * @par Description:
502  * This API is used to stop trace.
503  * @attention
504  * <ul>
505  * <li>Stop trace</li>
506  * </ul>
507  *
508  * @param  None.
509  * @retval #None.
510  *
511  * @par Dependency:
512  * <ul><li>los_trace.h: the header file that contains the API declaration.</li></ul>
513  * @see LOS_TraceStop
514  */
515 extern VOID LOS_TraceStop(VOID);
516 
517 /**
518  * @ingroup los_trace
519  * @brief Clear the trace buf.
520  *
521  * @par Description:
522  * Clear the event frames in trace buf only at offline mode.
523  * @attention
524  * <ul>
525  * <li>This API can be called only after that trace buffer has been established.</li>
526  * Otherwise, the trace will be failed.</li>
527  * </ul>
528  *
529  * @param  None.
530  * @retval #NA
531  * @par Dependency:
532  * <ul><li>los_trace.h: the header file that contains the API declaration.</li></ul>
533  * @see LOS_TraceReset
534  */
535 extern VOID LOS_TraceReset(VOID);
536 
537 /**
538  * @ingroup los_trace
539  * @brief Set trace event mask.
540  *
541  * @par Description:
542  * Set trace event mask.
543  * @attention
544  * <ul>
545  * <li>Set trace event filter mask.</li>
546  * <li>The Default mask is (TRACE_HWI_FLAG | TRACE_TASK_FLAG), stands for switch on task and hwi events.</li>
547  * <li>Customize mask according to the type defined in enum LOS_TRACE_MASK to switch on corresponding module's
548  * trace.</li>
549  * <li>The system's trace mask will be overrode by the input parameter.</li>
550  * </ul>
551  *
552  * @param  mask [IN] Type #UINT32. The mask used to filter events of LOS_TRACE_MASK.
553  * @retval #NA.
554  * @par Dependency:
555  * <ul><li>los_trace.h: the header file that contains the API declaration.</li></ul>
556  * @see LOS_TraceEventMaskSet
557  */
558 extern VOID LOS_TraceEventMaskSet(UINT32 mask);
559 
560 /**
561  * @ingroup los_trace
562  * @brief Offline trace buffer display.
563  *
564  * @par Description:
565  * Display trace buf data only at offline mode.
566  * @attention
567  * <ul>
568  * <li>This API can be called only after that trace stopped. Otherwise the trace dump will be failed.</li>
569  * <li>Trace data will be send to pipeline when user set toClient = TRUE. Otherwise it will be formatted and printed
570  * out.</li>
571  * </ul>
572  *
573  * @param toClient           [IN] Type #BOOL. Whether send trace data to Client through pipeline.
574  * @retval #NA
575  *
576  * @par Dependency:
577  * <ul><li>los_trace.h: the header file that contains the API declaration.</li></ul>
578  * @see LOS_TraceRecordDump
579  */
580 extern VOID LOS_TraceRecordDump(BOOL toClient);
581 
582 /**
583  * @ingroup los_trace
584  * @brief Offline trace buffer export.
585  *
586  * @par Description:
587  * Return the trace buf only at offline mode.
588  * @attention
589  * <ul>
590  * <li>This API can be called only after that trace buffer has been established. </li>
591  * <li>The return buffer's address is a critical resource, user can only ready.</li>
592  * </ul>
593  *
594  * @param NA
595  * @retval #OfflineHead*   The trace buffer's address, analyze this buffer according to the structure of
596  * OfflineHead.
597  *
598  * @par Dependency:
599  * <ul><li>los_trace.h: the header file that contains the API declaration.</li></ul>
600  * @see LOS_TraceRecordGet
601  */
602 extern OfflineHead *LOS_TraceRecordGet(VOID);
603 
604 /**
605  * @ingroup los_trace
606  * @brief Hwi num filter hook.
607  *
608  * @par Description:
609  * Hwi filter function.
610  * @attention
611  * <ul>
612  * <li>Filter the hwi events by hwi num</li>
613  * </ul>
614  *
615  * @param  hook [IN] Type #TRACE_HWI_FILTER_HOOK. The user defined hook for hwi num filter,
616  *                             the hook should return true if you don't want trace this hwi num.
617  * @retval #None
618  * @par Dependency:
619  * <ul><li>los_trace.h: the header file that contains the API declaration.</li></ul>
620  * @see LOS_TraceHwiFilterHookReg
621  */
622 extern VOID LOS_TraceHwiFilterHookReg(TRACE_HWI_FILTER_HOOK hook);
623 #ifdef __cplusplus
624 #if __cplusplus
625 }
626 #endif /* __cplusplus */
627 #endif /* __cplusplus */
628 
629 #endif /* _LOS_TRACE_H */
630