1 // Copyright 2020 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 // https://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, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14 //==============================================================================
15 // This file contains the backend hooks and implementation details for trace.
16
17 #pragma once
18
19 #include "pw_preprocessor/arguments.h"
20 #include "pw_preprocessor/concat.h"
21 #include "pw_trace_backend/trace_backend.h"
22
23 // Default: Flag value if none set
24 #ifndef PW_TRACE_FLAGS_DEFAULT
25 #define PW_TRACE_FLAGS_DEFAULT 0
26 #endif // PW_TRACE_FLAGS_DEFAULT
27
28 // Default: PW_TRACE_TRACE_ID_DEFAULT
29 #ifndef PW_TRACE_TRACE_ID_DEFAULT
30 #define PW_TRACE_TRACE_ID_DEFAULT 0
31 #endif // PW_TRACE_TRACE_ID_DEFAULT
32
33 // Default: PW_TRACE_GROUP_LABEL_DEFAULT
34 #ifndef PW_TRACE_GROUP_LABEL_DEFAULT
35 #define PW_TRACE_GROUP_LABEL_DEFAULT ""
36 #endif // PW_TRACE_GROUP_LABEL_DEFAULT
37
38 // These macros can be used to determine if a trace type contrains span or group
39 // label
40 #ifndef PW_TRACE_HAS_TRACE_ID
41 #define PW_TRACE_HAS_TRACE_ID(TRACE_TYPE) \
42 ((TRACE_TYPE) == PW_TRACE_TYPE_ASYNC_START || \
43 (TRACE_TYPE) == PW_TRACE_TYPE_ASYNC_INSTANT || \
44 (TRACE_TYPE) == PW_TRACE_TYPE_ASYNC_END)
45 #endif // PW_TRACE_HAS_TRACE_ID
46 #ifndef PW_TRACE_HAS_GROUP_LABEL
47 #define PW_TRACE_HAS_GROUP_LABEL(TRACE_TYPE) (false)
48 #endif // PW_TRACE_HAS_GROUP_LABEL
49
50 // Default: behaviour for unimplemented trace event types
51 #ifndef _PW_TRACE_DISABLED
_pw_trace_disabled(int x,...)52 static inline void _pw_trace_disabled(int x, ...) { (void)x; }
53 // `_PW_TRACE_DISABLED` must be called with at least one arg.
54 #define _PW_TRACE_DISABLED(...) \
55 do { \
56 _pw_trace_disabled(0, ##__VA_ARGS__); \
57 } while (false)
58 #endif // _PW_TRACE_DISABLED
59
60 // Default: label used for PW_TRACE_FUNCTION trace events
61 #ifndef PW_TRACE_FUNCTION_LABEL
62 #define PW_TRACE_FUNCTION_LABEL __PRETTY_FUNCTION__
63 #endif
64
65 // Control to enable/disable tracing. If 0, no traces are emitted.
66 //
67 // Defaults to enabled.
68 #ifndef PW_TRACE_ENABLE
69 #define PW_TRACE_ENABLE 1
70 #endif // PW_TRACE_ENABLE
71
72 #define _PW_TRACE_IF_ENABLED(event_type, flags, label, group_label, trace_id) \
73 do { \
74 if ((PW_TRACE_ENABLE) != 0) { \
75 PW_TRACE(event_type, flags, label, group_label, trace_id); \
76 } \
77 } while (0)
78
79 #define _PW_TRACE_DATA_IF_ENABLED(event_type, \
80 flags, \
81 label, \
82 group_label, \
83 trace_id, \
84 data_format_string, \
85 data, \
86 size) \
87 do { \
88 if ((PW_TRACE_ENABLE) != 0) { \
89 PW_TRACE_DATA(event_type, \
90 flags, \
91 label, \
92 group_label, \
93 trace_id, \
94 data_format_string, \
95 data, \
96 size); \
97 } \
98 } while (0)
99
100 // This block handles:
101 // - PW_TRACE_INSTANT(label)
102 // - PW_TRACE_INSTANT_FLAG(flag, label)
103 // Which creates a trace event with the type: PW_TRACE_TYPE_INSTANT
104 // NOTE: If this type is not defined by the backend this trace is removed.
105 #ifdef PW_TRACE_TYPE_INSTANT
106 #define _PW_TRACE_INSTANT_ARGS2(flag, label) \
107 _PW_TRACE_IF_ENABLED(PW_TRACE_TYPE_INSTANT, \
108 flag, \
109 label, \
110 PW_TRACE_GROUP_LABEL_DEFAULT, \
111 PW_TRACE_TRACE_ID_DEFAULT)
112 #else // PW_TRACE_TYPE_INSTANT
113 #define _PW_TRACE_INSTANT_ARGS2(...) _PW_TRACE_DISABLED(__VA_ARGS__)
114 #endif // PW_TRACE_TYPE_INSTANT
115
116 // This block handles:
117 // - PW_TRACE_INSTANT(label, group)
118 // - PW_TRACE_INSTANT_FLAG(flag, label, group)
119 // Which creates a trace event with the type: PW_TRACE_TYPE_INSTANT_GROUP
120 // NOTE: If this type is not defined by the backend this trace is removed.
121 #ifdef PW_TRACE_TYPE_INSTANT_GROUP
122 #define _PW_TRACE_INSTANT_ARGS3(flag, label, group) \
123 _PW_TRACE_IF_ENABLED(PW_TRACE_TYPE_INSTANT_GROUP, \
124 flag, \
125 label, \
126 group, \
127 PW_TRACE_TRACE_ID_DEFAULT)
128 #else // PW_TRACE_TYPE_INSTANT_GROUP
129 #define _PW_TRACE_INSTANT_ARGS3(...) _PW_TRACE_DISABLED(__VA_ARGS__)
130 #endif // PW_TRACE_TYPE_INSTANT_GROUP
131
132 // This block handles:
133 // - PW_TRACE_INSTANT(label, group, trace_id)
134 // - PW_TRACE_INSTANT_FLAG(flag, label, group, trace_id)
135 // Which creates a trace event with the type: PW_TRACE_TYPE_ASYNC_INSTANT
136 // NOTE: If this type is not defined by the backend this trace is removed.
137 #ifdef PW_TRACE_TYPE_ASYNC_INSTANT
138 #define _PW_TRACE_INSTANT_ARGS4(flag, label, group, trace_id) \
139 _PW_TRACE_IF_ENABLED( \
140 PW_TRACE_TYPE_ASYNC_INSTANT, flag, label, group, trace_id)
141 #else // PW_TRACE_TYPE_ASYNC_INSTANT
142 #define _PW_TRACE_INSTANT_ARGS4(...) _PW_TRACE_DISABLED(__VA_ARGS__)
143 #endif // PW_TRACE_TYPE_ASYNC_INSTANT
144
145 // This block handles:
146 // - PW_TRACE_START(label)
147 // - PW_TRACE_START_FLAG(flag, label)
148 // Which creates a trace event with the type: PW_TRACE_TYPE_DURATION_START
149 // NOTE: If this type is not defined by the backend this trace is removed.
150 #ifdef PW_TRACE_TYPE_DURATION_START
151 #define _PW_TRACE_START_ARGS2(flag, label) \
152 _PW_TRACE_IF_ENABLED(PW_TRACE_TYPE_DURATION_START, \
153 flag, \
154 label, \
155 PW_TRACE_GROUP_LABEL_DEFAULT, \
156 PW_TRACE_TRACE_ID_DEFAULT)
157 #else // PW_TRACE_TYPE_DURATION_START
158 #define _PW_TRACE_START_ARGS2(...) _PW_TRACE_DISABLED(__VA_ARGS__)
159 #endif // PW_TRACE_TYPE_DURATION_START
160
161 // This block handles:
162 // - PW_TRACE_START(label, group)
163 // - PW_TRACE_START_FLAG(flag, label, group)
164 // Which creates a trace event with the type: PW_TRACE_TYPE_DURATION_GROUP_START
165 // NOTE: If this type is not defined by the backend this trace is removed.
166 #ifdef PW_TRACE_TYPE_DURATION_GROUP_START // Disabled if backend doesn't define
167 // this
168 #define _PW_TRACE_START_ARGS3(flag, label, group) \
169 _PW_TRACE_IF_ENABLED(PW_TRACE_TYPE_DURATION_GROUP_START, \
170 flag, \
171 label, \
172 group, \
173 PW_TRACE_TRACE_ID_DEFAULT)
174 #else // PW_TRACE_TYPE_DURATION_GROUP_START
175 #define _PW_TRACE_START_ARGS3(...) _PW_TRACE_DISABLED(__VA_ARGS__)
176 #endif // PW_TRACE_TYPE_DURATION_GROUP_START
177
178 // This block handles:
179 // - PW_TRACE_START(label, group, trace_id)
180 // - PW_TRACE_START_FLAG(flag, label, group, trace_id)
181 // Which creates a trace event with the type: PW_TRACE_TYPE_ASYNC_START
182 // NOTE: If this type is not defined by the backend this trace is removed.
183 #ifdef PW_TRACE_TYPE_ASYNC_START
184 #define _PW_TRACE_START_ARGS4(flag, label, group, trace_id) \
185 _PW_TRACE_IF_ENABLED(PW_TRACE_TYPE_ASYNC_START, flag, label, group, trace_id)
186 #else // PW_TRACE_TYPE_ASYNC_START
187 #define _PW_TRACE_START_ARGS4(...) _PW_TRACE_DISABLED(__VA_ARGS__)
188 #endif // PW_TRACE_TYPE_ASYNC_START
189
190 // This block handles:
191 // - PW_TRACE_END(labe)
192 // - PW_TRACE_END_FLAG(flag, label)
193 // Which creates a trace event with the type: PW_TRACE_TYPE_DURATION_END
194 // NOTE: If this type is not defined by the backend this trace is removed.
195 #ifdef PW_TRACE_TYPE_DURATION_END
196 #define _PW_TRACE_END_ARGS2(flag, label) \
197 _PW_TRACE_IF_ENABLED(PW_TRACE_TYPE_DURATION_END, \
198 flag, \
199 label, \
200 PW_TRACE_GROUP_LABEL_DEFAULT, \
201 PW_TRACE_TRACE_ID_DEFAULT)
202 #else // PW_TRACE_TYPE_DURATION_END
203 #define _PW_TRACE_END_ARGS2(...) _PW_TRACE_DISABLED(__VA_ARGS__)
204 #endif // PW_TRACE_TYPE_DURATION_END
205
206 // This block handles:
207 // - PW_TRACE_END(label, group)
208 // - PW_TRACE_END_FLAG(flag, label, group)
209 // Which creates a trace event with the type: PW_TRACE_TYPE_DURATION_GROUP_END
210 // NOTE: If this type is not defined by the backend this trace is removed.
211 #ifdef PW_TRACE_TYPE_DURATION_GROUP_END
212 #define _PW_TRACE_END_ARGS3(flag, label, group) \
213 _PW_TRACE_IF_ENABLED(PW_TRACE_TYPE_DURATION_GROUP_END, \
214 flag, \
215 label, \
216 group, \
217 PW_TRACE_TRACE_ID_DEFAULT)
218 #else // PW_TRACE_TYPE_DURATION_GROUP_END
219 #define _PW_TRACE_END_ARGS3(...) _PW_TRACE_DISABLED(__VA_ARGS__)
220 #endif // PW_TRACE_TYPE_DURATION_GROUP_END
221
222 // This block handles:
223 // - PW_TRACE_END(label, group, trace_id)
224 // - PW_TRACE_END_FLAG(flag, label, group, trace_id)
225 // Which creates a trace event with the type: PW_TRACE_TYPE_ASYNC_END
226 // NOTE: If this type is not defined by the backend this trace is removed.
227 #ifdef PW_TRACE_TYPE_ASYNC_END
228 #define _PW_TRACE_END_ARGS4(flag, label, group, trace_id) \
229 _PW_TRACE_IF_ENABLED(PW_TRACE_TYPE_ASYNC_END, flag, label, group, trace_id)
230 #else // PW_TRACE_TYPE_ASYNC_END
231 #define _PW_TRACE_END_ARGS4(...) _PW_TRACE_DISABLED(__VA_ARGS__)
232 #endif // PW_TRACE_TYPE_ASYNC_END
233
234 // The pigweed scope objects gets defined inline with the trace event. The
235 // constructor handles the start trace event, and the destructor does the end.
236 #ifndef _PW_TRACE_SCOPE_OBJECT
237 #define _PW_TRACE_SCOPE_OBJECT( \
238 object_name, flag, event_type_start, event_type_end, label, group) \
239 class object_name { \
240 public: \
241 object_name(const object_name&) = delete; \
242 object_name(object_name&&) = delete; \
243 object_name& operator=(const object_name&) = delete; \
244 object_name& operator=(object_name&&) = delete; \
245 \
246 object_name(uint32_t PW_CONCAT(object_name, \
247 _trace_id) = PW_TRACE_TRACE_ID_DEFAULT) \
248 : trace_id_(PW_CONCAT(object_name, _trace_id)) { \
249 _PW_TRACE_IF_ENABLED(event_type_start, flag, label, group, trace_id_); \
250 } \
251 ~object_name() { \
252 _PW_TRACE_IF_ENABLED(event_type_end, flag, label, group, trace_id_); \
253 } \
254 \
255 private: \
256 const uint32_t trace_id_; \
257 }
258 #endif // _PW_TRACE_SCOPE_OBJECT
259
260 // This block handles:
261 // - PW_TRACE_SCOPE(label)
262 // - PW_TRACE_SCOPE_FLAG(flag, label)
263 // - PW_TRACE_FUNCTION()
264 // - PW_TRACE_FUNCTION_FLAG(flag)
265 // These each generate two trace events:
266 // - PW_TRACE_TYPE_DURATION_START: Where trace event appears in code.
267 // - PW_TRACE_TYPE_DURATION_END: When current scope is lost.
268 // NOTE; If these types are not defined by the backend these traces are removed.
269 #if defined(PW_TRACE_TYPE_DURATION_START) && defined(PW_TRACE_TYPE_DURATION_END)
270 #define _PW_TRACE_SCOPE_ARGS2(flag, label) \
271 _PW_TRACE_SCOPE_OBJECT(PW_CONCAT(_PwTraceScopeObject, __COUNTER__), \
272 flag, \
273 PW_TRACE_TYPE_DURATION_START, \
274 PW_TRACE_TYPE_DURATION_END, \
275 label, \
276 PW_TRACE_GROUP_LABEL_DEFAULT) \
277 PW_CONCAT(_pw_trace_scope_object, __COUNTER__);
278 #define _PW_TRACE_FUNCTION_ARGS0() \
279 _PW_TRACE_SCOPE_ARGS2(PW_TRACE_FLAGS, PW_TRACE_FUNCTION_LABEL)
280 #define _PW_TRACE_FUNCTION_FLAGS_ARGS1(flag) \
281 _PW_TRACE_SCOPE_ARGS2(flag, PW_TRACE_FUNCTION_LABEL)
282 #else // PW_TRACE_TYPE_DURATION_GROUP_END
283 #define _PW_TRACE_SCOPE_ARGS2(...) _PW_TRACE_DISABLED(__VA_ARGS__)
284 #define _PW_TRACE_FUNCTION_ARGS0() // No need to/can't call _PW_TRACE_DISABLED
285 // with zero args.
286 #define _PW_TRACE_FUNCTION_FLAGS_ARGS1(...) _PW_TRACE_DISABLED(__VA_ARGS__)
287 #endif // defined(PW_TRACE_TYPE_DURATION_START) &&
288 // defined(PW_TRACE_TYPE_DURATION_END)
289
290 // This block handles:
291 // - PW_TRACE_SCOPE(label, group)
292 // - PW_TRACE_SCOPE_FLAG(flag, label, group)
293 // - PW_TRACE_FUNCTION(group)
294 // - PW_TRACE_FUNCTION_FLAG(flag, group)
295 // These each generate two trace events:
296 // - PW_TRACE_TYPE_DURATION_GROUP_START: Where trace event appears in code.
297 // - PW_TRACE_TYPE_DURATION_GROUP_END: When current scope is lost.
298 // NOTE; If these types are not defined by the backend these traces are removed.
299 #if defined(PW_TRACE_TYPE_DURATION_GROUP_START) && \
300 defined(PW_TRACE_TYPE_DURATION_GROUP_END)
301 #define _PW_TRACE_SCOPE_ARGS3(flag, label, group) \
302 _PW_TRACE_SCOPE_OBJECT(PW_CONCAT(_PwTraceScopeObject, __COUNTER__), \
303 flag, \
304 PW_TRACE_TYPE_DURATION_GROUP_START, \
305 PW_TRACE_TYPE_DURATION_GROUP_END, \
306 label, \
307 group) \
308 PW_CONCAT(_pw_trace_scope_object, __COUNTER__);
309 #define _PW_TRACE_FUNCTION_ARGS1(group) \
310 _PW_TRACE_SCOPE_ARGS3(PW_TRACE_FLAGS, PW_TRACE_FUNCTION_LABEL, group)
311 #define _PW_TRACE_FUNCTION_FLAGS_ARGS2(flag, group) \
312 _PW_TRACE_SCOPE_ARGS3(flag, PW_TRACE_FUNCTION_LABEL, group)
313 #else // PW_TRACE_TYPE_DURATION_GROUP_END
314 #define _PW_TRACE_SCOPE_ARGS3(...) _PW_TRACE_DISABLED(__VA_ARGS__)
315 #define _PW_TRACE_FUNCTION_ARGS1(...) _PW_TRACE_DISABLED(__VA_ARGS__)
316 #define _PW_TRACE_FUNCTION_FLAGS_ARGS2(...) _PW_TRACE_DISABLED(__VA_ARGS__)
317 #endif // defined(PW_TRACE_TYPE_DURATION_GROUP_START) &&
318 // defined(PW_TRACE_TYPE_DURATION_GROUP_END)
319
320 // This block handles:
321 // - PW_TRACE_SCOPE(label, group, trace_id)
322 // - PW_TRACE_SCOPE_FLAG(flag, label, group, trace_id)
323 // - PW_TRACE_FUNCTION(group, trace_id)
324 // - PW_TRACE_FUNCTION_FLAG(flag, group, trace_id)
325 // These each generate two trace events:
326 // - PW_TRACE_TYPE_ASYNC_START: Where trace event appears in code.
327 // - PW_TRACE_TYPE_ASYNC_END: When current scope is lost.
328 // NOTE: If these types are not defined by the backend these traces are removed.
329 #if defined(PW_TRACE_TYPE_ASYNC_START) && defined(PW_TRACE_TYPE_ASYNC_END)
330 #define _PW_TRACE_SCOPE_ARGS4(flag, label, group, trace_id) \
331 _PW_TRACE_SCOPE_OBJECT(PW_CONCAT(_PwTraceScopeObject, __COUNTER__), \
332 flag, \
333 PW_TRACE_TYPE_ASYNC_START, \
334 PW_TRACE_TYPE_ASYNC_END, \
335 label, \
336 group) \
337 PW_CONCAT(_pw_trace_scope_object, __COUNTER__)(trace_id);
338 #define _PW_TRACE_FUNCTION_ARGS2(group, trace_id) \
339 _PW_TRACE_SCOPE_ARGS4( \
340 PW_TRACE_FLAGS, PW_TRACE_FUNCTION_LABEL, group, trace_id)
341 #define _PW_TRACE_FUNCTION_FLAGS_ARGS3(flag, group, trace_id) \
342 _PW_TRACE_SCOPE_ARGS4(flag, PW_TRACE_FUNCTION_LABEL, group, trace_id)
343 #else // PW_TRACE_TYPE_DURATION_GROUP_END
344 #define _PW_TRACE_SCOPE_ARGS4(...) _PW_TRACE_DISABLED(__VA_ARGS__)
345 #define _PW_TRACE_FUNCTION_ARGS2(...) _PW_TRACE_DISABLED(__VA_ARGS__)
346 #define _PW_TRACE_FUNCTION_FLAGS_ARGS3(...) _PW_TRACE_DISABLED(__VA_ARGS__)
347 #endif // defined(PW_TRACE_TYPE_ASYNC_START) &&
348 // defined(PW_TRACE_TYPE_ASYNC_END)
349
350 // This block handles:
351 // - PW_TRACE_INSTANT_DATA(label,
352 // data_format_string,
353 // data,
354 // size)
355 // - PW_TRACE_INSTANT_DATA_FLAG(flag,
356 // label,
357 // data_format_string,
358 // data,
359 // size)
360 // Which creates a trace event with the type: PW_TRACE_TYPE_INSTANT
361 // NOTE: If this type or PW_TRACE_DATA is not defined by the backend this trace
362 // is removed.
363 #if defined(PW_TRACE_DATA) && defined(PW_TRACE_TYPE_INSTANT)
364 #define _PW_TRACE_INSTANT_DATA_ARGS5( \
365 flag, label, data_format_string, data, size) \
366 _PW_TRACE_DATA_IF_ENABLED(PW_TRACE_TYPE_INSTANT, \
367 flag, \
368 label, \
369 PW_TRACE_GROUP_LABEL_DEFAULT, \
370 PW_TRACE_TRACE_ID_DEFAULT, \
371 data_format_string, \
372 data, \
373 size)
374 #else // defined(PW_TRACE_DATA) && defined(PW_TRACE_TYPE_INSTANT)
375 #define _PW_TRACE_INSTANT_DATA_ARGS5(...) _PW_TRACE_DISABLED(__VA_ARGS__)
376 #endif // defined(PW_TRACE_DATA) && defined(PW_TRACE_TYPE_INSTANT)
377
378 // This block handles:
379 // - PW_TRACE_INSTANT_DATA(label,
380 // group,
381 // data_format_string,
382 // data,
383 // size)
384 // - PW_TRACE_INSTANT_DATA_FLAG(flag,
385 // label,
386 // group,
387 // data_format_string,
388 // data,
389 // size)
390 // Which creates a trace event with the type: PW_TRACE_TYPE_INSTANT_GROUP
391 // NOTE: If this type or PW_TRACE_DATA is not defined by the backend this trace
392 // is removed.
393 #if defined(PW_TRACE_DATA) && defined(PW_TRACE_TYPE_INSTANT_GROUP)
394 #define _PW_TRACE_INSTANT_DATA_ARGS6( \
395 flag, label, group, data_format_string, data, size) \
396 _PW_TRACE_DATA_IF_ENABLED(PW_TRACE_TYPE_INSTANT_GROUP, \
397 flag, \
398 label, \
399 group, \
400 PW_TRACE_TRACE_ID_DEFAULT, \
401 data_format_string, \
402 data, \
403 size)
404 #else // defined(PW_TRACE_DATA) && defined(PW_TRACE_TYPE_INSTANT_GROUP)
405 #define _PW_TRACE_INSTANT_DATA_ARGS6(...) _PW_TRACE_DISABLED(__VA_ARGS__)
406 #endif // defined(PW_TRACE_DATA) && defined(PW_TRACE_TYPE_INSTANT_GROUP)
407
408 // This block handles:
409 // - PW_TRACE_INSTANT_DATA(label,
410 // group,
411 // trace_id
412 // data_format_string,
413 // data,
414 // size)
415 // - PW_TRACE_INSTANT_DATA_FLAG(flag,
416 // label,
417 // group,
418 // trace_id
419 // data_format_string,
420 // data,
421 // size)
422 // Which creates a trace event with the type: PW_TRACE_TYPE_ASYNC_INSTANT
423 // NOTE: If this type or PW_TRACE_DATA is not defined by the backend this trace
424 // is removed.
425 #if defined(PW_TRACE_DATA) && defined(PW_TRACE_TYPE_ASYNC_INSTANT)
426 #define _PW_TRACE_INSTANT_DATA_ARGS7( \
427 flag, label, group, trace_id, data_format_string, data, size) \
428 _PW_TRACE_DATA_IF_ENABLED(PW_TRACE_TYPE_ASYNC_INSTANT, \
429 flag, \
430 label, \
431 group, \
432 trace_id, \
433 data_format_string, \
434 data, \
435 size)
436 #else // defined(PW_TRACE_DATA) && defined(PW_TRACE_TYPE_ASYNC_INSTANT)
437 #define _PW_TRACE_INSTANT_DATA_ARGS7(...) _PW_TRACE_DISABLED(__VA_ARGS__)
438 #endif // defined(PW_TRACE_DATA) && defined(PW_TRACE_TYPE_ASYNC_INSTANT)
439
440 // This block handles:
441 // - PW_TRACE_START_DATA(label,
442 // data_format_string,
443 // data,
444 // size)
445 // - PW_TRACE_START_DATA_FLAG(flag,
446 // label,
447 // data_format_string,
448 // data,
449 // size)
450 // Which creates a trace event with the type: PW_TRACE_TYPE_DURATION_START
451 // NOTE: If this type or PW_TRACE_DATA is not defined by the backend this trace
452 // is removed.
453 #if defined(PW_TRACE_DATA) && defined(PW_TRACE_TYPE_DURATION_START)
454 #define _PW_TRACE_START_DATA_ARGS5( \
455 flag, label, data_format_string, data, size) \
456 _PW_TRACE_DATA_IF_ENABLED(PW_TRACE_TYPE_DURATION_START, \
457 flag, \
458 label, \
459 PW_TRACE_GROUP_LABEL_DEFAULT, \
460 PW_TRACE_TRACE_ID_DEFAULT, \
461 data_format_string, \
462 data, \
463 size)
464 #else // defined(PW_TRACE_DATA) && defined(PW_TRACE_TYPE_DURATION_START)
465 #define _PW_TRACE_START_DATA_ARGS5(...) _PW_TRACE_DISABLED(__VA_ARGS__)
466 #endif // defined(PW_TRACE_DATA) && defined(PW_TRACE_TYPE_DURATION_START)
467
468 // This block handles:
469 // - PW_TRACE_START_DATA(label,
470 // group,
471 // data_format_string,
472 // data,
473 // size)
474 // - PW_TRACE_START_DATA_FLAG(flag,
475 // label,
476 // group,
477 // data_format_string,
478 // data,
479 // size)
480 // Which creates a trace event with the type: PW_TRACE_TYPE_DURATION_GROUP_START
481 // NOTE: If this type or PW_TRACE_DATA is not defined by the backend this trace
482 // is removed.
483 #if defined(PW_TRACE_DATA) && defined(PW_TRACE_TYPE_DURATION_GROUP_START)
484 #define _PW_TRACE_START_DATA_ARGS6( \
485 flag, label, group, data_format_string, data, size) \
486 _PW_TRACE_DATA_IF_ENABLED(PW_TRACE_TYPE_DURATION_GROUP_START, \
487 flag, \
488 label, \
489 group, \
490 PW_TRACE_TRACE_ID_DEFAULT, \
491 data_format_string, \
492 data, \
493 size)
494 #else // defined(PW_TRACE_DATA) && defined(PW_TRACE_TYPE_DURATION_START)
495 #define _PW_TRACE_START_DATA_ARGS6(...) _PW_TRACE_DISABLED(__VA_ARGS__)
496 #endif // defined(PW_TRACE_DATA) && defined(PW_TRACE_TYPE_DURATION_START)
497
498 // This block handles:
499 // - PW_TRACE_START_DATA(label,
500 // group,
501 // trace_id
502 // data_format_string,
503 // data,
504 // size)
505 // - PW_TRACE_START_DATA_FLAG(flag,
506 // label,
507 // group,
508 // trace_id
509 // data_format_string,
510 // data,
511 // size)
512 // Which creates a trace event with the type: PW_TRACE_TYPE_ASYNC_START
513 // NOTE: If this type or PW_TRACE_DATA is not defined by the backend this trace
514 // is removed.
515 #if defined(PW_TRACE_DATA) && defined(PW_TRACE_TYPE_ASYNC_START)
516 #define _PW_TRACE_START_DATA_ARGS7( \
517 flag, label, group, trace_id, data_format_string, data, size) \
518 _PW_TRACE_DATA_IF_ENABLED(PW_TRACE_TYPE_ASYNC_START, \
519 flag, \
520 label, \
521 group, \
522 trace_id, \
523 data_format_string, \
524 data, \
525 size)
526 #else // defined(PW_TRACE_DATA) && defined(PW_TRACE_TYPE_ASYNC_START)
527 #define _PW_TRACE_START_DATA_ARGS7(...) _PW_TRACE_DISABLED(__VA_ARGS__)
528 #endif // defined(PW_TRACE_DATA) && defined(PW_TRACE_TYPE_ASYNC_START)
529
530 // This block handles:
531 // - PW_TRACE_END_DATA(label,
532 // data_format_string,
533 // data,
534 // size)
535 // - PW_TRACE_END_DATA_FLAG(flag,
536 // label,
537 // data_format_string,
538 // data,
539 // size)
540 // Which creates a trace event with the type: PW_TRACE_TYPE_DURATION_END
541 // NOTE: If this type or PW_TRACE_DATA is not defined by the backend this trace
542 // is removed.
543 #if defined(PW_TRACE_DATA) && defined(PW_TRACE_TYPE_DURATION_END)
544 #define _PW_TRACE_END_DATA_ARGS5(flag, label, data_format_string, data, size) \
545 _PW_TRACE_DATA_IF_ENABLED(PW_TRACE_TYPE_DURATION_END, \
546 flag, \
547 label, \
548 PW_TRACE_GROUP_LABEL_DEFAULT, \
549 PW_TRACE_TRACE_ID_DEFAULT, \
550 data_format_string, \
551 data, \
552 size)
553 #else // defined(PW_TRACE_DATA) && defined(PW_TRACE_TYPE_DURATION_START)
554 #define _PW_TRACE_END_DATA_ARGS5(...) _PW_TRACE_DISABLED(__VA_ARGS__)
555 #endif // defined(PW_TRACE_DATA) && defined(PW_TRACE_TYPE_DURATION_START)
556
557 // This block handles:
558 // - PW_TRACE_END_DATA(label,
559 // group,
560 // data_format_string,
561 // data,
562 // size)
563 // - PW_TRACE_END_DATA_FLAG(flag,
564 // label,
565 // group,
566 // data_format_string,
567 // data,
568 // size)
569 // Which creates a trace event with the type: PW_TRACE_TYPE_DURATION_GROUP_END
570 // NOTE: If this type or PW_TRACE_DATA is not defined by the backend this trace
571 // is removed.
572 #if defined(PW_TRACE_DATA) && defined(PW_TRACE_TYPE_DURATION_GROUP_END)
573 #define _PW_TRACE_END_DATA_ARGS6( \
574 flag, label, group, data_format_string, data, size) \
575 _PW_TRACE_DATA_IF_ENABLED(PW_TRACE_TYPE_DURATION_GROUP_END, \
576 flag, \
577 label, \
578 group, \
579 PW_TRACE_TRACE_ID_DEFAULT, \
580 data_format_string, \
581 data, \
582 size)
583 #else // defined(PW_TRACE_DATA) && defined(PW_TRACE_TYPE_DURATION_GROUP_END)
584 #define _PW_TRACE_END_DATA_ARGS6(...) _PW_TRACE_DISABLED(__VA_ARGS__)
585 #endif // defined(PW_TRACE_DATA) && defined(PW_TRACE_TYPE_DURATION_GROUP_END)
586
587 // This block handles:
588 // - PW_TRACE_END_DATA(label,
589 // group,
590 // trace_id
591 // data_format_string,
592 // data,
593 // size)
594 // - PW_TRACE_END_DATA_FLAG(flag,
595 // label,
596 // group,
597 // trace_id
598 // data_format_string,
599 // data,
600 // size)
601 // Which creates a trace event with the type: PW_TRACE_TYPE_ASYNC_END
602 // NOTE: If this type or PW_TRACE_DATA is not defined by the backend this trace
603 // is removed.
604 #if defined(PW_TRACE_DATA) && defined(PW_TRACE_TYPE_ASYNC_END)
605 #define _PW_TRACE_END_DATA_ARGS7( \
606 flag, label, group, trace_id, data_format_string, data, size) \
607 _PW_TRACE_DATA_IF_ENABLED(PW_TRACE_TYPE_ASYNC_END, \
608 flag, \
609 label, \
610 group, \
611 trace_id, \
612 data_format_string, \
613 data, \
614 size)
615 #else // defined(PW_TRACE_DATA) && defined(PW_TRACE_TYPE_ASYNC_END)
616 #define _PW_TRACE_END_DATA_ARGS7(...) _PW_TRACE_DISABLED(__VA_ARGS__)
617 #endif // defined(PW_TRACE_DATA) && defined(PW_TRACE_TYPE_ASYNC_END)
618