1 #ifndef BABELTRACE2_TRACE_IR_TRACE_CLASS_H
2 #define BABELTRACE2_TRACE_IR_TRACE_CLASS_H
5 * Copyright (c) 2010-2019 EfficiOS Inc. and Linux Foundation
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 #ifndef __BT_IN_BABELTRACE_H
27 # error "Please include <babeltrace2/babeltrace.h> instead."
32 #include <babeltrace2/types.h>
39 @defgroup api-tir-trace-cls Trace class
45 A <strong><em>trace class</em></strong> is the class of \bt_p_trace:
47 @image html trace-structure.png
49 In the illustration above, notice that a trace is an instance of a
52 A trace class is a \ref api-tir "trace IR" metadata object.
54 A trace class is a \ref api-fund-shared-object "shared object": get a
55 new reference with bt_trace_class_get_ref() and put an existing
56 reference with bt_trace_class_put_ref().
58 Some library functions \ref api-fund-freezing "freeze" trace classes on
59 success. The documentation of those functions indicate this
60 postcondition. With a frozen trace class, you can still:
62 - Create and add a \bt_p_stream_cls to it with
63 bt_stream_class_create() or bt_stream_class_create_with_id().
64 - Add a destruction listener to it with
65 bt_trace_class_add_destruction_listener().
67 The type of a trace class is #bt_trace_class.
69 A trace class contains \bt_p_stream_cls. All the stream classes of a
70 given trace class have unique
71 \ref api-tir-stream-cls-prop-id "numeric IDs". Get the number of stream
72 classes in a trace class with bt_trace_class_get_stream_class_count().
73 Borrow a specific stream class from a trace class with
74 bt_trace_class_borrow_stream_class_by_index(),
75 bt_trace_class_borrow_stream_class_by_index_const(),
76 bt_trace_class_borrow_stream_class_by_id(), or
77 bt_trace_class_borrow_stream_class_by_id_const().
79 Set whether or not the \bt_p_stream_cls you create for a trace class get
80 automatic numeric IDs with
81 bt_trace_class_set_assigns_automatic_stream_class_id().
83 Create a default trace class from a \bt_self_comp with
84 bt_trace_class_create().
86 Add to and remove a destruction listener from a trace class with
87 bt_trace_class_add_destruction_listener() and
88 bt_trace_class_remove_destruction_listener().
92 A trace class has the following properties:
96 \anchor api-tir-trace-cls-prop-auto-sc-id
97 Assigns automatic stream class IDs?
100 Whether or not the stream classes you create and add to the trace
101 class get \ref api-tir-stream-cls-prop-id "numeric IDs"
104 Depending on the value of this property, to create a stream class
105 and add it to the trace class:
110 Use bt_stream_class_create().
115 Use bt_stream_class_create_with_id().
119 Use bt_trace_class_set_assigns_automatic_stream_class_id()
120 and bt_trace_class_assigns_automatic_stream_class_id().
124 \anchor api-tir-trace-cls-prop-user-attrs
125 \bt_dt_opt User attributes
128 User attributes of the trace class.
130 User attributes are custom attributes attached to a trace class.
132 Use bt_trace_class_set_user_attributes(),
133 bt_trace_class_borrow_user_attributes(), and
134 bt_trace_class_borrow_user_attributes_const().
145 @typedef struct bt_trace_class bt_trace_class;
160 Creates a default trace class from the \bt_self_comp
161 \bt_p{self_component}.
163 On success, the returned trace class has the following property values:
170 <td>\ref api-tir-trace-cls-prop-auto-sc-id "Assigns automatic stream class IDs?"
173 <td>\ref api-tir-trace-cls-prop-user-attrs "User attributes"
174 <td>Empty \bt_map_val
177 @param[in] self_component
178 Self component from which to create the default trace class.
181 New trace class reference, or \c NULL on memory error.
183 extern bt_trace_class
*bt_trace_class_create(bt_self_component
*self_component
);
188 @name Stream class access
194 Returns the number of \bt_p_stream_cls contained in the trace
195 class \bt_p{trace_class}.
197 @param[in] trace_class
198 Trace class of which to get the number of contained stream classes.
201 Number of contained stream classes in \bt_p{trace_class}.
203 @bt_pre_not_null{trace_class}
205 extern uint64_t bt_trace_class_get_stream_class_count(
206 const bt_trace_class
*trace_class
);
210 Borrows the \bt_stream_cls at index \bt_p{index} from the
211 trace class \bt_p{trace_class}.
213 @param[in] trace_class
214 Trace class from which to borrow the stream class at index
217 Index of the stream class to borrow from \bt_p{trace_class}.
221 \em Borrowed reference of the stream class of
222 \bt_p{trace_class} at index \bt_p{index}.
224 The returned pointer remains valid as long as \bt_p{trace_class}
228 @bt_pre_not_null{trace_class}
230 \bt_p{index} is less than the number of stream classes in
231 \bt_p{trace_class} (as returned by
232 bt_trace_class_get_stream_class_count()).
234 @sa bt_trace_class_get_stream_class_count() —
235 Returns the number of stream classes contained in a trace class.
236 @sa bt_trace_class_borrow_stream_class_by_index_const() —
237 \c const version of this function.
239 extern bt_stream_class
*bt_trace_class_borrow_stream_class_by_index(
240 bt_trace_class
*trace_class
, uint64_t index
);
244 Borrows the \bt_stream_cls at index \bt_p{index} from the
245 trace class \bt_p{trace_class} (\c const version).
247 See bt_trace_class_borrow_stream_class_by_index().
249 extern const bt_stream_class
*
250 bt_trace_class_borrow_stream_class_by_index_const(
251 const bt_trace_class
*trace_class
, uint64_t index
);
255 Borrows the \bt_stream_cls having the numeric ID \bt_p{id} from the
256 trace class \bt_p{trace_class}.
258 If there's no stream class having the numeric ID \bt_p{id} in
259 \bt_p{trace_class}, this function returns \c NULL.
261 @param[in] trace_class
262 Trace class from which to borrow the stream class having the
263 numeric ID \bt_p{id}.
265 ID of the stream class to borrow from \bt_p{trace_class}.
269 \em Borrowed reference of the stream class of
270 \bt_p{trace_class} having the numeric ID \bt_p{id}, or \c NULL
273 The returned pointer remains valid as long as \bt_p{trace_class}
277 @bt_pre_not_null{trace_class}
279 @sa bt_trace_class_borrow_stream_class_by_id_const() —
280 \c const version of this function.
282 extern bt_stream_class
*bt_trace_class_borrow_stream_class_by_id(
283 bt_trace_class
*trace_class
, uint64_t id
);
287 Borrows the \bt_stream_cls having the numeric ID \bt_p{id} from the
288 trace class \bt_p{trace_class} (\c const version).
290 See bt_trace_class_borrow_stream_class_by_id().
292 extern const bt_stream_class
*bt_trace_class_borrow_stream_class_by_id_const(
293 const bt_trace_class
*trace_class
, uint64_t id
);
304 Sets whether or not the trace class \bt_p{trace_class} automatically
305 assigns a numeric ID to a \bt_stream_cls you create and add to it.
307 See the \ref api-tir-trace-cls-prop-auto-sc-id "assigns automatic stream class IDs?"
310 @param[in] trace_class
311 Trace class of which to set whether or not it assigns automatic
313 @param[in] assigns_automatic_stream_class_id
314 #BT_TRUE to make \bt_p{trace_class} assign automatic stream class
317 @bt_pre_not_null{trace_class}
318 @bt_pre_hot{trace_class}
320 @sa bt_trace_class_assigns_automatic_stream_class_id() —
321 Returns whether or not a trace class automatically assigns
324 extern void bt_trace_class_set_assigns_automatic_stream_class_id(
325 bt_trace_class
*trace_class
,
326 bt_bool assigns_automatic_stream_class_id
);
330 Returns whether or not the trace class \bt_p{trace_class}
331 automatically assigns a numeric ID to a \bt_stream_cls you create
334 See the \ref api-tir-trace-cls-prop-auto-sc-id "assigns automatic stream class IDs?"
337 @param[in] trace_class
338 Trace class of which to get whether or not it assigns automatic
342 #BT_TRUE if \bt_p{trace_class} automatically
343 assigns stream class IDs.
345 @bt_pre_not_null{trace_class}
347 @sa bt_trace_class_set_assigns_automatic_stream_class_id() —
348 Sets whether or not a trace class automatically assigns
351 extern bt_bool
bt_trace_class_assigns_automatic_stream_class_id(
352 const bt_trace_class
*trace_class
);
356 Sets the user attributes of the trace class \bt_p{trace_class} to
357 \bt_p{user_attributes}.
359 See the \ref api-tir-trace-cls-prop-user-attrs "user attributes"
363 When you create a default trace class with bt_trace_class_create()
364 or bt_trace_class_create_with_id(), the trace class's initial user
365 attributes is an empty \bt_map_val. Therefore you can borrow it with
366 bt_trace_class_borrow_user_attributes() and fill it directly
367 instead of setting a new one with this function.
369 @param[in] trace_class
370 Trace class of which to set the user attributes to
371 \bt_p{user_attributes}.
372 @param[in] user_attributes
373 New user attributes of \bt_p{trace_class}.
375 @bt_pre_not_null{trace_class}
376 @bt_pre_hot{trace_class}
377 @bt_pre_not_null{user_attributes}
378 @bt_pre_is_map_val{user_attributes}
380 @sa bt_trace_class_borrow_user_attributes() —
381 Borrows the user attributes of a trace class.
383 extern void bt_trace_class_set_user_attributes(
384 bt_trace_class
*trace_class
, const bt_value
*user_attributes
);
388 Borrows the user attributes of the trace class \bt_p{trace_class}.
390 See the \ref api-tir-trace-cls-prop-user-attrs "user attributes"
394 When you create a default trace class with bt_trace_class_create()
395 or bt_trace_class_create_with_id(), the trace class's initial user
396 attributes is an empty \bt_map_val.
398 @param[in] trace_class
399 Trace class from which to borrow the user attributes.
402 User attributes of \bt_p{trace_class} (a \bt_map_val).
404 @bt_pre_not_null{trace_class}
406 @sa bt_trace_class_set_user_attributes() —
407 Sets the user attributes of a trace class.
408 @sa bt_trace_class_borrow_user_attributes_const() —
409 \c const version of this function.
411 extern bt_value
*bt_trace_class_borrow_user_attributes(
412 bt_trace_class
*trace_class
);
416 Borrows the user attributes of the trace class \bt_p{trace_class}
419 See bt_trace_class_borrow_user_attributes().
421 extern const bt_value
*bt_trace_class_borrow_user_attributes_const(
422 const bt_trace_class
*trace_class
);
433 User function for bt_trace_class_add_destruction_listener().
435 This is the user function type for a trace class destruction listener.
437 @param[in] trace_class
438 Trace class being destroyed (\ref api-fund-freezing "frozen").
440 User data, as passed as the \bt_p{user_data} parameter of
441 bt_trace_class_add_destruction_listener().
443 @bt_pre_not_null{trace_class}
446 The reference count of \bt_p{trace_class} is not changed.
449 @sa bt_trace_class_add_destruction_listener() —
450 Adds a destruction listener to a trace class.
452 typedef void (* bt_trace_class_destruction_listener_func
)(
453 const bt_trace_class
*trace_class
, void *user_data
);
457 Status codes for bt_trace_class_add_destruction_listener().
459 typedef enum bt_trace_class_add_listener_status
{
464 BT_TRACE_CLASS_ADD_LISTENER_STATUS_OK
= __BT_FUNC_STATUS_OK
,
470 BT_TRACE_CLASS_ADD_LISTENER_STATUS_MEMORY_ERROR
= __BT_FUNC_STATUS_MEMORY_ERROR
,
471 } bt_trace_class_add_listener_status
;
475 Adds a destruction listener having the function \bt_p{user_func}
476 to the trace class \bt_p{trace_class}.
478 All the destruction listener user functions of a trace class are called
479 when it's being destroyed.
481 If \bt_p{listener_id} is not \c NULL, then this function, on success,
482 sets \bt_p{*listener_id} to the ID of the added destruction listener
483 within \bt_p{trace_class}. You can then use this ID to remove the
484 added destruction listener with
485 bt_trace_class_remove_destruction_listener().
487 @param[in] trace_class
488 Trace class to add the destruction listener to.
490 User function of the destruction listener to add to
493 User data to pass as the \bt_p{user_data} parameter of
495 @param[out] listener_id
496 <strong>On success and if not \c NULL</strong>, \bt_p{*listener_id}
497 is the ID of the added destruction listener within
500 @retval #BT_TRACE_CLASS_ADD_LISTENER_STATUS_OK
502 @retval #BT_TRACE_CLASS_ADD_LISTENER_STATUS_MEMORY_ERROR
505 @bt_pre_not_null{trace_class}
506 @bt_pre_not_null{user_func}
508 @sa bt_trace_class_remove_destruction_listener() —
509 Removes a destruction listener from a trace class.
511 extern bt_trace_class_add_listener_status
512 bt_trace_class_add_destruction_listener(
513 const bt_trace_class
*trace_class
,
514 bt_trace_class_destruction_listener_func user_func
,
515 void *user_data
, bt_listener_id
*listener_id
);
519 Status codes for bt_trace_class_remove_destruction_listener().
521 typedef enum bt_trace_class_remove_listener_status
{
526 BT_TRACE_CLASS_REMOVE_LISTENER_STATUS_OK
= __BT_FUNC_STATUS_OK
,
532 BT_TRACE_CLASS_REMOVE_LISTENER_STATUS_MEMORY_ERROR
= __BT_FUNC_STATUS_MEMORY_ERROR
,
533 } bt_trace_class_remove_listener_status
;
537 Removes the destruction listener having the ID \bt_p{listener_id}
538 from the trace class \bt_p{trace_class}.
540 The destruction listener to remove from \bt_p{trace_class} was
541 previously added with bt_trace_class_add_destruction_listener().
543 You can call this function when \bt_p{trace_class} is
544 \ref api-fund-freezing "frozen".
546 @param[in] trace_class
547 Trace class from which to remove the destruction listener having
548 the ID \bt_p{listener_id}.
549 @param[in] listener_id
550 ID of the destruction listener to remove from \bt_p{trace_class}.
552 @retval #BT_TRACE_CLASS_REMOVE_LISTENER_STATUS_OK
554 @retval #BT_TRACE_CLASS_REMOVE_LISTENER_STATUS_MEMORY_ERROR
557 @bt_pre_not_null{trace_class}
559 \bt_p{listener_id} is the ID of an existing destruction listener
560 in \bt_p{trace_class}.
562 @sa bt_trace_class_add_destruction_listener() —
563 Adds a destruction listener to a trace class.
565 extern bt_trace_class_remove_listener_status
566 bt_trace_class_remove_destruction_listener(
567 const bt_trace_class
*trace_class
, bt_listener_id listener_id
);
572 @name Reference count
578 Increments the \ref api-fund-shared-object "reference count" of
579 the trace class \bt_p{trace_class}.
581 @param[in] trace_class
583 Trace class of which to increment the reference count.
588 @sa bt_trace_class_put_ref() —
589 Decrements the reference count of a trace class.
591 extern void bt_trace_class_get_ref(const bt_trace_class
*trace_class
);
595 Decrements the \ref api-fund-shared-object "reference count" of
596 the trace class \bt_p{trace_class}.
598 @param[in] trace_class
600 Trace class of which to decrement the reference count.
605 @sa bt_trace_class_get_ref() —
606 Increments the reference count of a trace class.
608 extern void bt_trace_class_put_ref(const bt_trace_class
*trace_class
);
612 Decrements the reference count of the trace class
613 \bt_p{_trace_class}, and then sets \bt_p{_trace_class} to \c NULL.
617 Trace class of which to decrement the reference count.
622 @bt_pre_assign_expr{_trace_class}
624 #define BT_TRACE_CLASS_PUT_REF_AND_RESET(_trace_class) \
626 bt_trace_class_put_ref(_trace_class); \
627 (_trace_class) = NULL; \
632 Decrements the reference count of the trace class \bt_p{_dst}, sets
633 \bt_p{_dst} to \bt_p{_src}, and then sets \bt_p{_src} to \c NULL.
635 This macro effectively moves a trace class reference from the expression
636 \bt_p{_src} to the expression \bt_p{_dst}, putting the existing
637 \bt_p{_dst} reference.
641 Destination expression.
652 @bt_pre_assign_expr{_dst}
653 @bt_pre_assign_expr{_src}
655 #define BT_TRACE_CLASS_MOVE_REF(_dst, _src) \
657 bt_trace_class_put_ref(_dst); \
670 #endif /* BABELTRACE2_TRACE_IR_TRACE_CLASS_H */