2 * SPDX-License-Identifier: MIT
4 * Copyright (C) 2010-2019 EfficiOS Inc. and Linux Foundation
7 #ifndef BABELTRACE2_TRACE_IR_TRACE_CLASS_H
8 #define BABELTRACE2_TRACE_IR_TRACE_CLASS_H
10 /* IWYU pragma: private, include <babeltrace2/babeltrace.h> */
12 #ifndef __BT_IN_BABELTRACE_H
13 # error "Please include <babeltrace2/babeltrace.h> instead."
18 #include <babeltrace2/types.h>
25 @defgroup api-tir-trace-cls Trace class
31 A <strong><em>trace class</em></strong> is the class of \bt_p_trace:
33 @image html trace-structure.png
35 In the illustration above, notice that a trace is an instance of a
38 A trace class is a \ref api-tir "trace IR" metadata object.
40 A trace class is a \ref api-fund-shared-object "shared object": get a
41 new reference with bt_trace_class_get_ref() and put an existing
42 reference with bt_trace_class_put_ref().
44 Some library functions \ref api-fund-freezing "freeze" trace classes on
45 success. The documentation of those functions indicate this
46 postcondition. With a frozen trace class, you can still:
48 - Create and add a \bt_p_stream_cls to it with
49 bt_stream_class_create() or bt_stream_class_create_with_id().
50 - Add a destruction listener to it with
51 bt_trace_class_add_destruction_listener().
53 The type of a trace class is #bt_trace_class.
55 A trace class contains \bt_p_stream_cls. All the stream classes of a
56 given trace class have unique
57 \ref api-tir-stream-cls-prop-id "numeric IDs". Get the number of stream
58 classes in a trace class with bt_trace_class_get_stream_class_count().
59 Borrow a specific stream class from a trace class with
60 bt_trace_class_borrow_stream_class_by_index(),
61 bt_trace_class_borrow_stream_class_by_index_const(),
62 bt_trace_class_borrow_stream_class_by_id(), or
63 bt_trace_class_borrow_stream_class_by_id_const().
65 Set whether or not the \bt_p_stream_cls you create for a trace class get
66 automatic numeric IDs with
67 bt_trace_class_set_assigns_automatic_stream_class_id().
69 Create a default trace class from a \bt_self_comp with
70 bt_trace_class_create().
72 Add to and remove a destruction listener from a trace class with
73 bt_trace_class_add_destruction_listener() and
74 bt_trace_class_remove_destruction_listener().
78 A trace class has the following properties:
82 \anchor api-tir-trace-cls-prop-auto-sc-id
83 Assigns automatic stream class IDs?
86 Whether or not the stream classes you create and add to the trace
87 class get \ref api-tir-stream-cls-prop-id "numeric IDs"
90 Depending on the value of this property, to create a stream class
91 and add it to the trace class:
96 Use bt_stream_class_create().
101 Use bt_stream_class_create_with_id().
105 Use bt_trace_class_set_assigns_automatic_stream_class_id()
106 and bt_trace_class_assigns_automatic_stream_class_id().
110 \anchor api-tir-trace-cls-prop-user-attrs
111 \bt_dt_opt User attributes
114 User attributes of the trace class.
116 User attributes are custom attributes attached to a trace class.
118 Use bt_trace_class_set_user_attributes(),
119 bt_trace_class_borrow_user_attributes(), and
120 bt_trace_class_borrow_user_attributes_const().
131 @typedef struct bt_trace_class bt_trace_class;
146 Creates a default trace class from the \bt_self_comp
147 \bt_p{self_component}.
149 On success, the returned trace class has the following property values:
156 <td>\ref api-tir-trace-cls-prop-auto-sc-id "Assigns automatic stream class IDs?"
159 <td>\ref api-tir-trace-cls-prop-user-attrs "User attributes"
160 <td>Empty \bt_map_val
163 @param[in] self_component
164 Self component from which to create the default trace class.
167 New trace class reference, or \c NULL on memory error.
169 extern bt_trace_class
*bt_trace_class_create(bt_self_component
*self_component
)
175 @name Stream class access
181 Returns the number of \bt_p_stream_cls contained in the trace
182 class \bt_p{trace_class}.
184 @param[in] trace_class
185 Trace class of which to get the number of contained stream classes.
188 Number of contained stream classes in \bt_p{trace_class}.
190 @bt_pre_not_null{trace_class}
192 extern uint64_t bt_trace_class_get_stream_class_count(
193 const bt_trace_class
*trace_class
) __BT_NOEXCEPT
;
197 Borrows the \bt_stream_cls at index \bt_p{index} from the
198 trace class \bt_p{trace_class}.
200 @param[in] trace_class
201 Trace class from which to borrow the stream class at index
204 Index of the stream class to borrow from \bt_p{trace_class}.
208 \em Borrowed reference of the stream class of
209 \bt_p{trace_class} at index \bt_p{index}.
211 The returned pointer remains valid as long as \bt_p{trace_class}
215 @bt_pre_not_null{trace_class}
217 \bt_p{index} is less than the number of stream classes in
218 \bt_p{trace_class} (as returned by
219 bt_trace_class_get_stream_class_count()).
221 @sa bt_trace_class_get_stream_class_count() —
222 Returns the number of stream classes contained in a trace class.
223 @sa bt_trace_class_borrow_stream_class_by_index_const() —
224 \c const version of this function.
226 extern bt_stream_class
*bt_trace_class_borrow_stream_class_by_index(
227 bt_trace_class
*trace_class
, uint64_t index
) __BT_NOEXCEPT
;
231 Borrows the \bt_stream_cls at index \bt_p{index} from the
232 trace class \bt_p{trace_class} (\c const version).
234 See bt_trace_class_borrow_stream_class_by_index().
236 extern const bt_stream_class
*
237 bt_trace_class_borrow_stream_class_by_index_const(
238 const bt_trace_class
*trace_class
,
239 uint64_t index
) __BT_NOEXCEPT
;
243 Borrows the \bt_stream_cls having the numeric ID \bt_p{id} from the
244 trace class \bt_p{trace_class}.
246 If there's no stream class having the numeric ID \bt_p{id} in
247 \bt_p{trace_class}, this function returns \c NULL.
249 @param[in] trace_class
250 Trace class from which to borrow the stream class having the
251 numeric ID \bt_p{id}.
253 ID of the stream class to borrow from \bt_p{trace_class}.
257 \em Borrowed reference of the stream class of
258 \bt_p{trace_class} having the numeric ID \bt_p{id}, or \c NULL
261 The returned pointer remains valid as long as \bt_p{trace_class}
265 @bt_pre_not_null{trace_class}
267 @sa bt_trace_class_borrow_stream_class_by_id_const() —
268 \c const version of this function.
270 extern bt_stream_class
*bt_trace_class_borrow_stream_class_by_id(
271 bt_trace_class
*trace_class
, uint64_t id
) __BT_NOEXCEPT
;
275 Borrows the \bt_stream_cls having the numeric ID \bt_p{id} from the
276 trace class \bt_p{trace_class} (\c const version).
278 See bt_trace_class_borrow_stream_class_by_id().
280 extern const bt_stream_class
*bt_trace_class_borrow_stream_class_by_id_const(
281 const bt_trace_class
*trace_class
, uint64_t id
) __BT_NOEXCEPT
;
292 Sets whether or not the trace class \bt_p{trace_class} automatically
293 assigns a numeric ID to a \bt_stream_cls you create and add to it.
295 See the \ref api-tir-trace-cls-prop-auto-sc-id "assigns automatic stream class IDs?"
298 @param[in] trace_class
299 Trace class of which to set whether or not it assigns automatic
301 @param[in] assigns_automatic_stream_class_id
302 #BT_TRUE to make \bt_p{trace_class} assign automatic stream class
305 @bt_pre_not_null{trace_class}
306 @bt_pre_hot{trace_class}
308 @sa bt_trace_class_assigns_automatic_stream_class_id() —
309 Returns whether or not a trace class automatically assigns
312 extern void bt_trace_class_set_assigns_automatic_stream_class_id(
313 bt_trace_class
*trace_class
,
314 bt_bool assigns_automatic_stream_class_id
) __BT_NOEXCEPT
;
318 Returns whether or not the trace class \bt_p{trace_class}
319 automatically assigns a numeric ID to a \bt_stream_cls you create
322 See the \ref api-tir-trace-cls-prop-auto-sc-id "assigns automatic stream class IDs?"
325 @param[in] trace_class
326 Trace class of which to get whether or not it assigns automatic
330 #BT_TRUE if \bt_p{trace_class} automatically
331 assigns stream class IDs.
333 @bt_pre_not_null{trace_class}
335 @sa bt_trace_class_set_assigns_automatic_stream_class_id() —
336 Sets whether or not a trace class automatically assigns
339 extern bt_bool
bt_trace_class_assigns_automatic_stream_class_id(
340 const bt_trace_class
*trace_class
) __BT_NOEXCEPT
;
344 Sets the user attributes of the trace class \bt_p{trace_class} to
345 \bt_p{user_attributes}.
347 See the \ref api-tir-trace-cls-prop-user-attrs "user attributes"
351 When you create a default trace class with bt_trace_class_create()
352 or bt_trace_class_create_with_id(), the trace class's initial user
353 attributes is an empty \bt_map_val. Therefore you can borrow it with
354 bt_trace_class_borrow_user_attributes() and fill it directly
355 instead of setting a new one with this function.
357 @param[in] trace_class
358 Trace class of which to set the user attributes to
359 \bt_p{user_attributes}.
360 @param[in] user_attributes
361 New user attributes of \bt_p{trace_class}.
363 @bt_pre_not_null{trace_class}
364 @bt_pre_hot{trace_class}
365 @bt_pre_not_null{user_attributes}
366 @bt_pre_is_map_val{user_attributes}
368 @sa bt_trace_class_borrow_user_attributes() —
369 Borrows the user attributes of a trace class.
371 extern void bt_trace_class_set_user_attributes(
372 bt_trace_class
*trace_class
,
373 const bt_value
*user_attributes
) __BT_NOEXCEPT
;
377 Borrows the user attributes of the trace class \bt_p{trace_class}.
379 See the \ref api-tir-trace-cls-prop-user-attrs "user attributes"
383 When you create a default trace class with bt_trace_class_create()
384 or bt_trace_class_create_with_id(), the trace class's initial user
385 attributes is an empty \bt_map_val.
387 @param[in] trace_class
388 Trace class from which to borrow the user attributes.
391 User attributes of \bt_p{trace_class} (a \bt_map_val).
393 @bt_pre_not_null{trace_class}
395 @sa bt_trace_class_set_user_attributes() —
396 Sets the user attributes of a trace class.
397 @sa bt_trace_class_borrow_user_attributes_const() —
398 \c const version of this function.
400 extern bt_value
*bt_trace_class_borrow_user_attributes(
401 bt_trace_class
*trace_class
) __BT_NOEXCEPT
;
405 Borrows the user attributes of the trace class \bt_p{trace_class}
408 See bt_trace_class_borrow_user_attributes().
410 extern const bt_value
*bt_trace_class_borrow_user_attributes_const(
411 const bt_trace_class
*trace_class
) __BT_NOEXCEPT
;
422 User function for bt_trace_class_add_destruction_listener().
424 This is the user function type for a trace class destruction listener.
426 @param[in] trace_class
427 Trace class being destroyed (\ref api-fund-freezing "frozen").
429 User data, as passed as the \bt_p{user_data} parameter of
430 bt_trace_class_add_destruction_listener().
432 @bt_pre_not_null{trace_class}
435 The reference count of \bt_p{trace_class} is not changed.
438 @sa bt_trace_class_add_destruction_listener() —
439 Adds a destruction listener to a trace class.
441 typedef void (* bt_trace_class_destruction_listener_func
)(
442 const bt_trace_class
*trace_class
, void *user_data
);
446 Status codes for bt_trace_class_add_destruction_listener().
448 typedef enum bt_trace_class_add_listener_status
{
453 BT_TRACE_CLASS_ADD_LISTENER_STATUS_OK
= __BT_FUNC_STATUS_OK
,
459 BT_TRACE_CLASS_ADD_LISTENER_STATUS_MEMORY_ERROR
= __BT_FUNC_STATUS_MEMORY_ERROR
,
460 } bt_trace_class_add_listener_status
;
464 Adds a destruction listener having the function \bt_p{user_func}
465 to the trace class \bt_p{trace_class}.
467 All the destruction listener user functions of a trace class are called
468 when it's being destroyed.
470 If \bt_p{listener_id} is not \c NULL, then this function, on success,
471 sets \bt_p{*listener_id} to the ID of the added destruction listener
472 within \bt_p{trace_class}. You can then use this ID to remove the
473 added destruction listener with
474 bt_trace_class_remove_destruction_listener().
476 @param[in] trace_class
477 Trace class to add the destruction listener to.
479 User function of the destruction listener to add to
482 User data to pass as the \bt_p{user_data} parameter of
484 @param[out] listener_id
485 <strong>On success and if not \c NULL</strong>, \bt_p{*listener_id}
486 is the ID of the added destruction listener within
489 @retval #BT_TRACE_CLASS_ADD_LISTENER_STATUS_OK
491 @retval #BT_TRACE_CLASS_ADD_LISTENER_STATUS_MEMORY_ERROR
494 @bt_pre_not_null{trace_class}
495 @bt_pre_not_null{user_func}
497 @sa bt_trace_class_remove_destruction_listener() —
498 Removes a destruction listener from a trace class.
500 extern bt_trace_class_add_listener_status
501 bt_trace_class_add_destruction_listener(
502 const bt_trace_class
*trace_class
,
503 bt_trace_class_destruction_listener_func user_func
,
504 void *user_data
, bt_listener_id
*listener_id
) __BT_NOEXCEPT
;
508 Status codes for bt_trace_class_remove_destruction_listener().
510 typedef enum bt_trace_class_remove_listener_status
{
515 BT_TRACE_CLASS_REMOVE_LISTENER_STATUS_OK
= __BT_FUNC_STATUS_OK
,
521 BT_TRACE_CLASS_REMOVE_LISTENER_STATUS_MEMORY_ERROR
= __BT_FUNC_STATUS_MEMORY_ERROR
,
522 } bt_trace_class_remove_listener_status
;
526 Removes the destruction listener having the ID \bt_p{listener_id}
527 from the trace class \bt_p{trace_class}.
529 The destruction listener to remove from \bt_p{trace_class} was
530 previously added with bt_trace_class_add_destruction_listener().
532 You can call this function when \bt_p{trace_class} is
533 \ref api-fund-freezing "frozen".
535 @param[in] trace_class
536 Trace class from which to remove the destruction listener having
537 the ID \bt_p{listener_id}.
538 @param[in] listener_id
539 ID of the destruction listener to remove from \bt_p{trace_class}.
541 @retval #BT_TRACE_CLASS_REMOVE_LISTENER_STATUS_OK
543 @retval #BT_TRACE_CLASS_REMOVE_LISTENER_STATUS_MEMORY_ERROR
546 @bt_pre_not_null{trace_class}
548 \bt_p{listener_id} is the ID of an existing destruction listener
549 in \bt_p{trace_class}.
551 @sa bt_trace_class_add_destruction_listener() —
552 Adds a destruction listener to a trace class.
554 extern bt_trace_class_remove_listener_status
555 bt_trace_class_remove_destruction_listener(
556 const bt_trace_class
*trace_class
, bt_listener_id listener_id
)
562 @name Reference count
568 Increments the \ref api-fund-shared-object "reference count" of
569 the trace class \bt_p{trace_class}.
571 @param[in] trace_class
573 Trace class of which to increment the reference count.
578 @sa bt_trace_class_put_ref() —
579 Decrements the reference count of a trace class.
581 extern void bt_trace_class_get_ref(
582 const bt_trace_class
*trace_class
) __BT_NOEXCEPT
;
586 Decrements the \ref api-fund-shared-object "reference count" of
587 the trace class \bt_p{trace_class}.
589 @param[in] trace_class
591 Trace class of which to decrement the reference count.
596 @sa bt_trace_class_get_ref() —
597 Increments the reference count of a trace class.
599 extern void bt_trace_class_put_ref(
600 const bt_trace_class
*trace_class
) __BT_NOEXCEPT
;
604 Decrements the reference count of the trace class
605 \bt_p{_trace_class}, and then sets \bt_p{_trace_class} to \c NULL.
609 Trace class of which to decrement the reference count.
614 @bt_pre_assign_expr{_trace_class}
616 #define BT_TRACE_CLASS_PUT_REF_AND_RESET(_trace_class) \
618 bt_trace_class_put_ref(_trace_class); \
619 (_trace_class) = NULL; \
624 Decrements the reference count of the trace class \bt_p{_dst}, sets
625 \bt_p{_dst} to \bt_p{_src}, and then sets \bt_p{_src} to \c NULL.
627 This macro effectively moves a trace class reference from the expression
628 \bt_p{_src} to the expression \bt_p{_dst}, putting the existing
629 \bt_p{_dst} reference.
633 Destination expression.
644 @bt_pre_assign_expr{_dst}
645 @bt_pre_assign_expr{_src}
647 #define BT_TRACE_CLASS_MOVE_REF(_dst, _src) \
649 bt_trace_class_put_ref(_dst); \
662 #endif /* BABELTRACE2_TRACE_IR_TRACE_CLASS_H */