los_trace.h 6.8 KB
Newer Older
W
wenjun 已提交
1
/*
M
mamingshuai 已提交
2 3
 * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
W
wenjun 已提交
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this list of
 *    conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
 *    of conditions and the following disclaimer in the documentation and/or other materials
 *    provided with the distribution.
 *
 * 3. Neither the name of the copyright holder nor the names of its contributors may be used
 *    to endorse or promote products derived from this software without specific prior written
 *    permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

M
mamingshuai 已提交
32 33
#ifndef _LOS_TRACE_H
#define _LOS_TRACE_H
W
wenjun 已提交
34

M
mamingshuai 已提交
35
#include "los_trace_frame.h"
W
wenjun 已提交
36 37 38 39 40 41 42 43
#include "los_base.h"

#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */

M
mamingshuai 已提交
44 45
/* Provide a mechanism for kernel tracking. Record the data to global buffer,
 * and you can get the data from /proc/ktrace.
W
wenjun 已提交
46 47 48 49 50 51
 */

/**
 * @ingroup los_trace
 * Task error code: User type is invalid when register new trace.
 *
M
mamingshuai 已提交
52
 * Value: 0x02001400
W
wenjun 已提交
53 54 55
 *
 * Solution: Use valid type to regeister the new trace.
 */
M
mamingshuai 已提交
56
#define LOS_ERRNO_TRACE_TYPE_INVALID    LOS_ERRNO_OS_ERROR(LOS_MOD_TRACE, 0x00)
W
wenjun 已提交
57 58 59 60 61

/**
 * @ingroup los_trace
 * Task error code: The callback function is null when register new trace.
 *
M
mamingshuai 已提交
62
 * Value: 0x02001401
W
wenjun 已提交
63 64 65
 *
 * Solution: Use valid callback function to regeister the new trace.
 */
M
mamingshuai 已提交
66
#define LOS_ERRNO_TRACE_FUNCTION_NULL   LOS_ERRNO_OS_ERROR(LOS_MOD_TRACE, 0x01)
W
wenjun 已提交
67 68 69

/**
 * @ingroup los_trace
M
mamingshuai 已提交
70
 * Task error code: The type is already registered.
W
wenjun 已提交
71
 *
M
mamingshuai 已提交
72
 * Value: 0x02001402
W
wenjun 已提交
73
 *
M
mamingshuai 已提交
74
 * Solution: Use valid type to regeister the new trace.
W
wenjun 已提交
75
 */
M
mamingshuai 已提交
76
#define LOS_ERRNO_TRACE_TYPE_EXISTED    LOS_ERRNO_OS_ERROR(LOS_MOD_TRACE, 0x02)
W
wenjun 已提交
77 78 79

/**
 * @ingroup los_trace
M
mamingshuai 已提交
80 81 82 83 84
 * Task error code: The type is not registered.
 *
 * Value: 0x02001403
 *
 * Solution: Use valid type to regeister the new trace.
W
wenjun 已提交
85
 */
M
mamingshuai 已提交
86
#define LOS_ERRNO_TRACE_TYPE_NOT_EXISTED    LOS_ERRNO_OS_ERROR(LOS_MOD_TRACE, 0x03)
W
wenjun 已提交
87 88 89 90 91 92 93 94 95

/**
* @ingroup  los_trace
* @brief Define the type of a function used to record trace.
*
* @par Description:
* This API is used to define the type of a recording trace function and call it after task or interrupt switch.
* @attention None.
*
M
mamingshuai 已提交
96 97 98
* @param  inBuf     [IN]  Type #UINT8 * The buffer saved trace information.
* @param  bufLen    [IN]  Type #UINT32  The buffer len.
* @param  ap        [IN]  Type #va_list The trace data list.
W
wenjun 已提交
99
*
M
mamingshuai 已提交
100
* @retval trace frame length.
W
wenjun 已提交
101 102 103 104
* @par Dependency:
* <ul><li>los_trace.h: the header file that contains the API declaration.</li></ul>
* @see
*/
M
mamingshuai 已提交
105
typedef INT32 (*WriteHook)(UINT8 *inBuf, UINT32 bufLen, va_list ap);
W
wenjun 已提交
106 107 108 109 110 111

/**
 * @ingroup los_trace
 * Stands for the trace type can be registered.
 */
typedef enum {
M
mamingshuai 已提交
112 113
    LOS_TRACE_TYPE_MIN  = 0,
    LOS_TRACE_TYPE_MAX  = 15,
W
wenjun 已提交
114 115
} TraceType;

M
mamingshuai 已提交
116 117 118 119
typedef enum {
    LOS_TRACE_DISABLE = 0,
    LOS_TRACE_ENABLE = 1,
} TraceSwitch;
W
wenjun 已提交
120 121 122 123 124 125 126 127 128 129 130 131

/**
 * @ingroup los_trace
 * @brief main trace function is called by user to logger the information.
 *
 * @par Description:
 * This API is used to trace the infomation.
 * @attention
 * <ul>
 * <li>This API can be called only after trace type is intialized. Otherwise, the trace will be failed.</li>
 * </ul>
 *
M
mamingshuai 已提交
132 133
 * @param  traceType    [IN] TraceType Type of trace information.
 * @param  ...          [IN] The trace data.
W
wenjun 已提交
134
 *
M
mamingshuai 已提交
135
 * @retval None.
W
wenjun 已提交
136 137 138 139 140
 *
 * @par Dependency:
 * <ul><li>los_trace.h: the header file that contains the API declaration.</li></ul>
 * @see LOS_Trace
 */
M
mamingshuai 已提交
141
VOID LOS_Trace(TraceType traceType, ...);
W
wenjun 已提交
142 143 144 145 146 147 148 149 150 151 152 153 154 155

/**
 * @ingroup los_trace
 * @brief intialize the trace when the system startup.
 *
 * @par Description:
 * This API is used to intilize the trace for system level.
 * @attention
 * <ul>
 * <li>This API can be called only after the memory is initialized. Otherwise, the CPU usage fails to be obtained.</li>
 * </ul>
 *
 * @param None.
 *
M
mamingshuai 已提交
156
 * @retval None.
W
wenjun 已提交
157 158 159 160
 * @par Dependency:
 * <ul><li>los_trace.h: the header file that contains the API declaration.</li></ul>
 * @see LOS_TraceInit
 */
M
mamingshuai 已提交
161
VOID LOS_TraceInit(VOID);
W
wenjun 已提交
162 163 164 165 166 167 168 169 170 171 172 173 174

/**
 * @ingroup los_trace
 * @brief register the hook for specific trace type.
 *
 * @par Description:
 * This API is used to register the hook for specific trace type.
 * @attention
 * <ul>
 * <li>This API can be called only after that trace type, input hookfnc and trace's data struct are established.</li>
 * Otherwise, the trace will be failed.</li>
 * </ul>
 *
M
mamingshuai 已提交
175 176 177 178
 * @param  traceType    [IN] TraceType. Type of trace information.
 * @param  inhook       [IN] WriteHook. It's a callback function to store the useful trace information.
 * @param  typeStr      [IN] const CHAR *. The trace name of trace type.
 * @param  onOff        [IN] TraceSwitch. It only can be LOS_TRACE_DISABLE or LOS_TRACE_ENABLE.
W
wenjun 已提交
179 180 181
 *
 * @retval #LOS_ERRNO_TRACE_NO_MEMORY          0x02001400: The memory is not enough for initilize.
 * @retval #LOS_ERRNO_TRACE_TYPE_INVALID       0x02001401: The trace type is invalid. Valid type is from
M
mamingshuai 已提交
182
 *                                                         LOS_TRACE_TYPE_MAX
W
wenjun 已提交
183 184 185 186 187 188 189 190
 * @retval #LOS_ERRNO_TRACE_FUNCTION_NULL      0x02001402: The input callback function is NULL
 * @retval #LOS_ERRNO_TRACE_MAX_SIZE_INVALID   0x02001403: The information maxmum size is 0 to store.
 * @retval #LOS_OK                             0x00000000: The registeration is successful.
 *
 * @par Dependency:
 * <ul><li>los_trace.h: the header file that contains the API declaration.</li></ul>
 * @see LOS_TraceUserReg
 */
M
mamingshuai 已提交
191
UINT32 LOS_TraceReg(TraceType traceType, WriteHook inHook, const CHAR *typeStr, TraceSwitch onOff);
W
wenjun 已提交
192

M
mamingshuai 已提交
193
UINT32 LOS_TraceUnreg(TraceType traceType);
W
wenjun 已提交
194

M
mamingshuai 已提交
195 196 197 198 199 200 201 202 203
UINT8 *LOS_TraceBufDataGet(UINT32 *desLen, UINT32 *relLen);

VOID LOS_TraceSwitch(TraceSwitch onOff);

UINT32 LOS_TraceTypeSwitch(TraceType traceType, TraceSwitch onOff);

#ifdef LOSCFG_FS_VFS
INT32 LOS_Trace2File(const CHAR *filename);
#endif
W
wenjun 已提交
204 205 206 207 208 209 210 211

#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */

#endif