1 /* 2 * Copyright (c) 2018 Intel Corporation 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 #ifndef ZEPHYR_INCLUDE_TRACING_TRACING_MACROS_H_ 7 #define ZEPHYR_INCLUDE_TRACING_TRACING_MACROS_H_ 8 9 #ifndef CONFIG_TRACING 10 11 #define SYS_PORT_TRACING_FUNC(type, func, ...) do { } while (false) 12 #define SYS_PORT_TRACING_FUNC_ENTER(type, func, ...) do { } while (false) 13 #define SYS_PORT_TRACING_FUNC_BLOCKING(type, func, ...) do { } while (false) 14 #define SYS_PORT_TRACING_FUNC_EXIT(type, func, ...) do { } while (false) 15 #define SYS_PORT_TRACING_OBJ_INIT(obj_type, obj, ...) do { } while (false) 16 #define SYS_PORT_TRACING_OBJ_FUNC(obj_type, func, obj, ...) do { } while (false) 17 #define SYS_PORT_TRACING_OBJ_FUNC_ENTER(obj_type, func, obj, ...) do { } while (false) 18 #define SYS_PORT_TRACING_OBJ_FUNC_BLOCKING(obj_type, func, obj, ...) do { } while (false) 19 #define SYS_PORT_TRACING_OBJ_FUNC_EXIT(obj_type, func, obj, ...) do { } while (false) 20 21 #else 22 23 /* Helper macros used by the extended tracing system 24 */ 25 #define _SYS_PORT_TRACING_TYPE_MASK(type) \ 26 sys_port_trace_type_mask_ ## type 27 #define _SYS_PORT_TRACING_FUNC(name, func) \ 28 sys_port_trace_ ## name ## _ ## func 29 #define _SYS_PORT_TRACING_FUNC_ENTER(name, func) \ 30 sys_port_trace_ ## name ## _ ## func ## _enter 31 #define _SYS_PORT_TRACING_FUNC_BLOCKING(name, func) \ 32 sys_port_trace_ ## name ## _ ## func ## _blocking 33 #define _SYS_PORT_TRACING_FUNC_EXIT(name, func) \ 34 sys_port_trace_ ## name ## _ ## func ## _exit 35 #define _SYS_PORT_TRACING_OBJ_INIT(name) \ 36 sys_port_trace_ ## name ## _init 37 #define _SYS_PORT_TRACING_OBJ_FUNC(name, func) \ 38 sys_port_trace_ ## name ## _ ## func 39 #define _SYS_PORT_TRACING_OBJ_FUNC_ENTER(name, func) \ 40 sys_port_trace_ ## name ## _ ## func ## _enter 41 #define _SYS_PORT_TRACING_OBJ_FUNC_BLOCKING(name, func) \ 42 sys_port_trace_ ## name ## _ ## func ## _blocking 43 #define _SYS_PORT_TRACING_OBJ_FUNC_EXIT(name, func) \ 44 sys_port_trace_ ## name ## _ ## func ## _exit 45 46 47 /* Object trace macros part of the system for checking if certain 48 * objects should be traced or not depending on the tracing configuration. 49 */ 50 #if defined(CONFIG_TRACING_THREAD) 51 #define sys_port_trace_type_mask_k_thread(trace_call) trace_call 52 #else 53 #define sys_port_trace_type_mask_k_thread(trace_call) 54 #endif 55 56 #if defined(CONFIG_TRACING_WORK) 57 #define sys_port_trace_type_mask_k_work(trace_call) trace_call 58 #define sys_port_trace_type_mask_k_work_queue(trace_call) trace_call 59 #define sys_port_trace_type_mask_k_work_delayable(trace_call) trace_call 60 #define sys_port_trace_type_mask_k_work_poll(trace_call) trace_call 61 #else 62 #define sys_port_trace_type_mask_k_work(trace_call) 63 #define sys_port_trace_type_mask_k_work_queue(trace_call) 64 #define sys_port_trace_type_mask_k_work_delayable(trace_call) 65 #define sys_port_trace_type_mask_k_work_poll(trace_call) 66 #endif 67 68 #if defined(CONFIG_TRACING_SEMAPHORE) 69 #define sys_port_trace_type_mask_k_sem(trace_call) trace_call 70 #else 71 #define sys_port_trace_type_mask_k_sem(trace_call) 72 #endif 73 74 #if defined(CONFIG_TRACING_MUTEX) 75 #define sys_port_trace_type_mask_k_mutex(trace_call) trace_call 76 #else 77 #define sys_port_trace_type_mask_k_mutex(trace_call) 78 #endif 79 80 #if defined(CONFIG_TRACING_CONDVAR) 81 #define sys_port_trace_type_mask_k_condvar(trace_call) trace_call 82 #else 83 #define sys_port_trace_type_mask_k_condvar(trace_call) 84 #endif 85 86 #if defined(CONFIG_TRACING_QUEUE) 87 #define sys_port_trace_type_mask_k_queue(trace_call) trace_call 88 #else 89 #define sys_port_trace_type_mask_k_queue(trace_call) 90 #endif 91 92 #if defined(CONFIG_TRACING_FIFO) 93 #define sys_port_trace_type_mask_k_fifo(trace_call) trace_call 94 #else 95 #define sys_port_trace_type_mask_k_fifo(trace_call) 96 #endif 97 98 #if defined(CONFIG_TRACING_LIFO) 99 #define sys_port_trace_type_mask_k_lifo(trace_call) trace_call 100 #else 101 #define sys_port_trace_type_mask_k_lifo(trace_call) 102 #endif 103 104 #if defined(CONFIG_TRACING_STACK) 105 #define sys_port_trace_type_mask_k_stack(trace_call) trace_call 106 #else 107 #define sys_port_trace_type_mask_k_stack(trace_call) 108 #endif 109 110 #if defined(CONFIG_TRACING_MESSAGE_QUEUE) 111 #define sys_port_trace_type_mask_k_msgq(trace_call) trace_call 112 #else 113 #define sys_port_trace_type_mask_k_msgq(trace_call) 114 #endif 115 116 #if defined(CONFIG_TRACING_MAILBOX) 117 #define sys_port_trace_type_mask_k_mbox(trace_call) trace_call 118 #else 119 #define sys_port_trace_type_mask_k_mbox(trace_call) 120 #endif 121 122 #if defined(CONFIG_TRACING_PIPE) 123 #define sys_port_trace_type_mask_k_pipe(trace_call) trace_call 124 #else 125 #define sys_port_trace_type_mask_k_pipe(trace_call) 126 #endif 127 128 #if defined(CONFIG_TRACING_HEAP) 129 #define sys_port_trace_type_mask_k_heap(trace_call) trace_call 130 #define sys_port_trace_type_mask_k_heap_sys(trace_call) trace_call 131 #else 132 #define sys_port_trace_type_mask_k_heap(trace_call) 133 #define sys_port_trace_type_mask_k_heap_sys(trace_call) 134 #endif 135 136 #if defined(CONFIG_TRACING_MEMORY_SLAB) 137 #define sys_port_trace_type_mask_k_mem_slab(trace_call) trace_call 138 #else 139 #define sys_port_trace_type_mask_k_mem_slab(trace_call) 140 #endif 141 142 #if defined(CONFIG_TRACING_TIMER) 143 #define sys_port_trace_type_mask_k_timer(trace_call) trace_call 144 #else 145 #define sys_port_trace_type_mask_k_timer(trace_call) 146 #endif 147 148 149 150 151 /** 152 * @def SYS_PORT_TRACING_OBJ_MASK 153 * 154 * @brief Checks if an object type should be traced or not. 155 * 156 * @param type Tracing event type/object 157 * @param trace_call Tracing call 158 */ 159 #define SYS_PORT_TRACING_TYPE_MASK(type, trace_call) \ 160 _SYS_PORT_TRACING_TYPE_MASK(type)(trace_call) 161 162 163 164 165 /** 166 * @def SYS_PORT_TRACING_FUNC 167 * 168 * @brief Tracing macro for function calls which are not directly 169 * associated with a specific type of object. 170 * 171 * @param type Type of tracing event or object type 172 * @param func Name of the function responsible for the call. This does not need to exactly 173 * match the name of the function but should rather match what the user called in case of 174 * system calls etc. That is, we can often omit the z_vrfy/z_impl part of the name. 175 * @param ... Additional parameters relevant to the tracing call 176 */ 177 #define SYS_PORT_TRACING_FUNC(type, func, ...) \ 178 do { \ 179 _SYS_PORT_TRACING_FUNC(type, func)(__VA_ARGS__); \ 180 } while (false) 181 182 /** 183 * @def SYS_PORT_TRACING_FUNC_ENTER 184 * 185 * @brief Tracing macro for the entry into a function that might or might not return 186 * a value. 187 * 188 * @param type Type of tracing event or object type 189 * @param func Name of the function responsible for the call. This does not need to exactly 190 * match the name of the function but should rather match what the user called in case of 191 * system calls etc. That is, we can often omit the z_vrfy/z_impl part of the name. 192 * @param ... Additional parameters relevant to the tracing call 193 */ 194 #define SYS_PORT_TRACING_FUNC_ENTER(type, func, ...) \ 195 do { \ 196 _SYS_PORT_TRACING_FUNC_ENTER(type, func)(__VA_ARGS__); \ 197 } while (false) 198 199 /** 200 * @def SYS_PORT_TRACING_FUNC_BLOCKING 201 * 202 * @brief Tracing macro for when a function blocks during its execution. 203 * 204 * @param type Type of tracing event or object type 205 * @param func Name of the function responsible for the call. This does not need to exactly 206 * match the name of the function but should rather match what the user called in case of 207 * system calls etc. That is, we can often omit the z_vrfy/z_impl part of the name. 208 * @param ... Additional parameters relevant to the tracing call 209 */ 210 #define SYS_PORT_TRACING_FUNC_BLOCKING(type, func, ...) \ 211 do { \ 212 _SYS_PORT_TRACING_FUNC_BLOCKING(type, func)(__VA_ARGS__); \ 213 } while (false) 214 215 /** 216 * @def SYS_PORT_TRACING_FUNC_EXIT 217 * 218 * @brief Tracing macro for when a function ends its execution. Potential return values 219 * can be given as additional arguments. 220 * 221 * @param type Type of tracing event or object type 222 * @param func Name of the function responsible for the call. This does not need to exactly 223 * match the name of the function but should rather match what the user called in case of 224 * system calls etc. That is, we can often omit the z_vrfy/z_impl part of the name. 225 * @param ... Additional parameters relevant to the tracing call 226 */ 227 #define SYS_PORT_TRACING_FUNC_EXIT(type, func, ...) \ 228 do { \ 229 _SYS_PORT_TRACING_FUNC_EXIT(type, func)(__VA_ARGS__); \ 230 } while (false) 231 232 /** 233 * @def SYS_PORT_TRACING_OBJ_INIT 234 * 235 * @brief Tracing macro for the initialization of an object. 236 * 237 * @param obj_type The type of object associated with the call (k_thread, k_sem, k_mutex etc.) 238 * @param obj Object 239 */ 240 #define SYS_PORT_TRACING_OBJ_INIT(obj_type, obj, ...) \ 241 do { \ 242 SYS_PORT_TRACING_TYPE_MASK(obj_type, \ 243 _SYS_PORT_TRACING_OBJ_INIT(obj_type)(obj, ##__VA_ARGS__)); \ 244 } while (false) 245 246 /** 247 * @def SYS_PORT_TRACING_OBJ_FUNC 248 * 249 * @brief Tracing macro for simple object function calls often without returns or branching. 250 * 251 * @param obj_type The type of object associated with the call (k_thread, k_sem, k_mutex etc.) 252 * @param func Name of the function responsible for the call. This does not need to exactly 253 * match the name of the function but should rather match what the user called in case of 254 * system calls etc. That is, we can often omit the z_vrfy/z_impl part of the name. 255 * @param obj Object 256 * @param ... Additional parameters relevant to the tracing call 257 */ 258 #define SYS_PORT_TRACING_OBJ_FUNC(obj_type, func, obj, ...) \ 259 do { \ 260 SYS_PORT_TRACING_TYPE_MASK(obj_type, \ 261 _SYS_PORT_TRACING_OBJ_FUNC(obj_type, func)(obj, ##__VA_ARGS__)); \ 262 } while (false) 263 264 /** 265 * @def SYS_PORT_TRACING_OBJ_FUNC_ENTER 266 * 267 * @brief Tracing macro for the entry into a function that might or might not return 268 * a value. 269 * 270 * @param obj_type The type of object associated with the call (k_thread, k_sem, k_mutex etc.) 271 * @param func Name of the function responsible for the call. This does not need to exactly 272 * match the name of the function but should rather match what the user called in case of 273 * system calls etc. That is, we can often omit the z_vrfy/z_impl part of the name. 274 * @param obj Object 275 * @param ... Additional parameters relevant to the tracing call 276 */ 277 #define SYS_PORT_TRACING_OBJ_FUNC_ENTER(obj_type, func, obj, ...) \ 278 do { \ 279 SYS_PORT_TRACING_TYPE_MASK(obj_type, \ 280 _SYS_PORT_TRACING_OBJ_FUNC_ENTER(obj_type, func)(obj, ##__VA_ARGS__)); \ 281 } while (false) 282 283 /** 284 * @def SYS_PORT_TRACING_OBJ_FUNC_BLOCKING 285 * 286 * @brief Tracing macro for when a function blocks during its execution. 287 * 288 * @param obj_type The type of object associated with the call (k_thread, k_sem, k_mutex etc.) 289 * @param func Name of the function responsible for the call. This does not need to exactly 290 * match the name of the function but should rather match what the user called in case of 291 * system calls etc. That is, we can often omit the z_vrfy/z_impl part of the name. 292 * @param obj Object 293 * @param ... Additional parameters relevant to the tracing call 294 */ 295 #define SYS_PORT_TRACING_OBJ_FUNC_BLOCKING(obj_type, func, obj, timeout, ...) \ 296 do { \ 297 SYS_PORT_TRACING_TYPE_MASK(obj_type, \ 298 _SYS_PORT_TRACING_OBJ_FUNC_BLOCKING(obj_type, func) \ 299 (obj, timeout, ##__VA_ARGS__)); \ 300 } while (false) 301 302 /** 303 * @def SYS_PORT_TRACING_OBJ_FUNC_EXIT 304 * 305 * @brief Tracing macro for when a function ends its execution. Potential return values 306 * can be given as additional arguments. 307 * 308 * @param obj_type The type of object associated with the call (k_thread, k_sem, k_mutex etc.) 309 * @param func Name of the function responsible for the call. This does not need to exactly 310 * match the name of the function but should rather match what the user called in case of 311 * system calls etc. That is, we can often omit the z_vrfy/z_impl part of the name. 312 * @param obj Object 313 * @param ... Additional parameters relevant to the tracing call 314 */ 315 #define SYS_PORT_TRACING_OBJ_FUNC_EXIT(obj_type, func, obj, ...) \ 316 do { \ 317 SYS_PORT_TRACING_TYPE_MASK(obj_type, \ 318 _SYS_PORT_TRACING_OBJ_FUNC_EXIT(obj_type, func)(obj, ##__VA_ARGS__)); \ 319 } while (false) 320 #endif /* CONFIG_TRACING */ 321 #endif 322