From 5c5632787fc9cafa602c89a28966bcfd01ec0204 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Mon, 4 Jun 2018 17:00:10 -0400 Subject: [PATCH] lib: use object pool for event and packet notifications This patch adds object pooling for event, packet beginning, and packet end notifications. The object pools are located in graph objects: there is one for each notification type. All the notification creation functions (in case we want to recycle other types of notification objects in the future) take a graph object so that a notification recycling function can find the appropriate object pool. I'm adding the convenient bt_private_connection_private_notification_iterator_borrow_graph() function for a notification iterator user function to borrow its graph easily. If the notification has a reference to its "creating" graph, there's a possible reference cycle, for example: * Graph -> connection -> notification iterator -> notification -> graph * Graph -> component -> notification -> graph To avoid this, the notification's graph link is weak, and the notification creation function adds the notification to the graph's array of notifications (also weak). While the graph is alive, notification recycling functions are free to use the appropriate graph's pool. When the graph is destroyed, all the notifications which have a link to it are notified so that they "unlink" the graph. In this case, notification recycling functions destroy the notification instead of recycling it. Some `bt_X_from_private()` functions are renamed to `bt_X_borrow_from_private()` and do not return a new reference to make it clearer. Everything related to the notification heap API is removed because it is not used anywhere and not needed since the `flt.utils.muxer` component class does this. Signed-off-by: Philippe Proulx --- include/Makefile.am | 2 - include/babeltrace/babeltrace.h | 1 - include/babeltrace/graph/component-internal.h | 14 - include/babeltrace/graph/component.h | 11 +- .../babeltrace/graph/connection-internal.h | 7 - include/babeltrace/graph/graph-internal.h | 31 ++ include/babeltrace/graph/graph.h | 1 + ...notification-discarded-elements-internal.h | 1 + .../graph/notification-event-internal.h | 10 + include/babeltrace/graph/notification-event.h | 3 +- .../graph/notification-heap-internal.h | 41 --- include/babeltrace/graph/notification-heap.h | 103 ------- .../graph/notification-inactivity.h | 4 +- .../babeltrace/graph/notification-internal.h | 58 +++- .../graph/notification-iterator-internal.h | 9 +- .../graph/notification-packet-internal.h | 18 ++ .../babeltrace/graph/notification-packet.h | 11 +- .../babeltrace/graph/notification-stream.h | 8 +- include/babeltrace/graph/port-internal.h | 7 - include/babeltrace/graph/private-component.h | 2 +- ...connection-private-notification-iterator.h | 5 +- include/babeltrace/graph/private-connection.h | 2 +- include/babeltrace/graph/private-port.h | 3 +- lib/ctf-ir/stream-class.c | 2 +- lib/graph/component.c | 9 +- lib/graph/connection.c | 4 +- lib/graph/filter.c | 1 + lib/graph/graph.c | 89 ++++++ lib/graph/iterator.c | 22 +- lib/graph/notification/Makefile.am | 1 - lib/graph/notification/discarded-elements.c | 3 +- lib/graph/notification/event.c | 93 ++++-- lib/graph/notification/heap.c | 264 ------------------ lib/graph/notification/inactivity.c | 3 +- lib/graph/notification/notification.c | 18 +- lib/graph/notification/packet.c | 163 ++++++++--- lib/graph/notification/stream.c | 8 +- lib/graph/port.c | 4 +- lib/graph/sink.c | 1 + lib/graph/source.c | 1 + lib/lib-logging.c | 19 +- plugins/ctf/common/notif-iter/notif-iter.c | 33 ++- plugins/ctf/common/notif-iter/notif-iter.h | 1 + plugins/ctf/fs-src/data-stream-file.c | 6 +- plugins/ctf/fs-src/data-stream-file.h | 4 + plugins/ctf/fs-src/fs.c | 25 +- plugins/ctf/fs-src/fs.h | 8 +- plugins/ctf/fs-src/query.c | 2 +- plugins/text/dmesg/dmesg.c | 17 +- plugins/utils/muxer/muxer.c | 22 +- tests/Makefile.am | 1 - tests/lib/Makefile.am | 6 +- tests/lib/test_bt_notification_heap.c | 199 ------------- tests/lib/test_bt_notification_iterator.c | 53 ++-- tests/lib/test_graph_topo.c | 30 +- tests/plugins/test-utils-muxer.c | 36 +-- 56 files changed, 648 insertions(+), 852 deletions(-) delete mode 100644 include/babeltrace/graph/notification-heap-internal.h delete mode 100644 include/babeltrace/graph/notification-heap.h delete mode 100644 lib/graph/notification/heap.c delete mode 100644 tests/lib/test_bt_notification_heap.c diff --git a/include/Makefile.am b/include/Makefile.am index acadd59f..b25aabfe 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -143,7 +143,6 @@ babeltracegraphinclude_HEADERS = \ babeltrace/graph/notification-discarded-events.h \ babeltrace/graph/notification-discarded-packets.h \ babeltrace/graph/notification-event.h \ - babeltrace/graph/notification-heap.h \ babeltrace/graph/notification-inactivity.h \ babeltrace/graph/notification-iterator.h \ babeltrace/graph/notification-packet.h \ @@ -229,7 +228,6 @@ noinst_HEADERS = \ babeltrace/graph/graph-internal.h \ babeltrace/graph/component-class-sink-colander-internal.h \ babeltrace/graph/notification-inactivity-internal.h \ - babeltrace/graph/notification-heap-internal.h \ babeltrace/graph/component-source-internal.h \ babeltrace/graph/notification-discarded-elements-internal.h \ babeltrace/graph/notification-packet-internal.h \ diff --git a/include/babeltrace/babeltrace.h b/include/babeltrace/babeltrace.h index cd910280..181c0141 100644 --- a/include/babeltrace/babeltrace.h +++ b/include/babeltrace/babeltrace.h @@ -87,7 +87,6 @@ #include #include #include -#include #include #include #include diff --git a/include/babeltrace/graph/component-internal.h b/include/babeltrace/graph/component-internal.h index f742c7b1..65f5e4d8 100644 --- a/include/babeltrace/graph/component-internal.h +++ b/include/babeltrace/graph/component-internal.h @@ -69,13 +69,6 @@ struct bt_component { bool initialized; }; -static inline -struct bt_component *bt_component_borrow_from_private( - struct bt_private_component *private_component) -{ - return (void *) private_component; -} - static inline struct bt_private_component *bt_private_component_from_component( struct bt_component *component) @@ -83,13 +76,6 @@ struct bt_private_component *bt_private_component_from_component( return (void *) component; } -static inline -struct bt_graph *bt_component_borrow_graph(struct bt_component *comp) -{ - BT_ASSERT(comp); - return (void *) comp->base.parent; -} - BT_HIDDEN enum bt_component_status bt_component_create( struct bt_component_class *component_class, diff --git a/include/babeltrace/graph/component.h b/include/babeltrace/graph/component.h index 7423e92a..f2db9d72 100644 --- a/include/babeltrace/graph/component.h +++ b/include/babeltrace/graph/component.h @@ -33,6 +33,9 @@ /* For bt_bool */ #include +/* For bt_get */ +#include + #ifdef __cplusplus extern "C" { #endif @@ -84,7 +87,13 @@ bt_bool bt_component_is_sink(struct bt_component *component) BT_COMPONENT_CLASS_TYPE_SINK; } -extern struct bt_graph *bt_component_get_graph(struct bt_component *component); +extern struct bt_graph *bt_component_borrow_graph(struct bt_component *component); + +static inline +struct bt_graph *bt_component_get_graph(struct bt_component *component) +{ + return bt_get(bt_component_borrow_graph(component)); +} #ifdef __cplusplus } diff --git a/include/babeltrace/graph/connection-internal.h b/include/babeltrace/graph/connection-internal.h index 366dc0e4..c1eea4b1 100644 --- a/include/babeltrace/graph/connection-internal.h +++ b/include/babeltrace/graph/connection-internal.h @@ -60,13 +60,6 @@ struct bt_connection { GPtrArray *iterators; }; -static inline -struct bt_connection *bt_connection_borrow_from_private( - struct bt_private_connection *private_connection) -{ - return (void *) private_connection; -} - static inline struct bt_private_connection *bt_private_connection_from_connection( struct bt_connection *connection) diff --git a/include/babeltrace/graph/graph-internal.h b/include/babeltrace/graph/graph-internal.h index cd1b557d..9e6012ec 100644 --- a/include/babeltrace/graph/graph-internal.h +++ b/include/babeltrace/graph/graph-internal.h @@ -29,8 +29,10 @@ #include #include +#include #include #include +#include #include #include #include @@ -80,6 +82,31 @@ struct bt_graph { GArray *ports_connected; GArray *ports_disconnected; } listeners; + + /* Pool of `struct bt_notification_event *` */ + struct bt_object_pool event_notif_pool; + + /* Pool of `struct bt_notification_packet_begin *` */ + struct bt_object_pool packet_begin_notif_pool; + + /* Pool of `struct bt_notification_packet_end *` */ + struct bt_object_pool packet_end_notif_pool; + + /* + * Array of `struct bt_notification *` (weak). + * + * This is an array of all the notifications ever created from + * this graph. Some of them can be in one of the pools above, + * some of them can be at large. Because each notification has a + * weak pointer to the graph containing its pool, we need to + * notify each notification that the graph is gone on graph + * destruction. + * + * TODO: When we support a maximum size for object pools, + * add a way for a notification to remove itself from this + * array (on destruction). + */ + GPtrArray *notifications; }; static inline @@ -130,6 +157,10 @@ BT_HIDDEN int bt_graph_remove_unconnected_component(struct bt_graph *graph, struct bt_component *component); +BT_HIDDEN +void bt_graph_add_notification(struct bt_graph *graph, + struct bt_notification *notif); + static inline const char *bt_graph_status_string(enum bt_graph_status status) { diff --git a/include/babeltrace/graph/graph.h b/include/babeltrace/graph/graph.h index bb3d84cb..acff8393 100644 --- a/include/babeltrace/graph/graph.h +++ b/include/babeltrace/graph/graph.h @@ -38,6 +38,7 @@ struct bt_port; struct bt_connection; struct bt_component; struct bt_component_class; +struct bt_value; enum bt_graph_status { BT_GRAPH_STATUS_COMPONENT_REFUSES_PORT_CONNECTION = 111, diff --git a/include/babeltrace/graph/notification-discarded-elements-internal.h b/include/babeltrace/graph/notification-discarded-elements-internal.h index 489a0464..c5d1f0ea 100644 --- a/include/babeltrace/graph/notification-discarded-elements-internal.h +++ b/include/babeltrace/graph/notification-discarded-elements-internal.h @@ -43,6 +43,7 @@ struct bt_notification_discarded_elements { BT_HIDDEN struct bt_notification *bt_notification_discarded_elements_create( + struct bt_graph *graph, enum bt_notification_type type, struct bt_stream *stream, struct bt_clock_value *begin_clock_value, diff --git a/include/babeltrace/graph/notification-event-internal.h b/include/babeltrace/graph/notification-event-internal.h index a5dea56f..436477b3 100644 --- a/include/babeltrace/graph/notification-event-internal.h +++ b/include/babeltrace/graph/notification-event-internal.h @@ -28,6 +28,7 @@ */ #include +#include #include #include #include @@ -43,6 +44,15 @@ struct bt_notification_event { struct bt_clock_class_priority_map *cc_prio_map; }; +BT_HIDDEN +struct bt_notification *bt_notification_event_new(struct bt_graph *graph); + +BT_HIDDEN +void bt_notification_event_recycle(struct bt_notification *notif); + +BT_HIDDEN +void bt_notification_event_destroy(struct bt_notification *notif); + #ifdef __cplusplus } #endif diff --git a/include/babeltrace/graph/notification-event.h b/include/babeltrace/graph/notification-event.h index d6614fb6..ab8a6606 100644 --- a/include/babeltrace/graph/notification-event.h +++ b/include/babeltrace/graph/notification-event.h @@ -39,7 +39,8 @@ struct bt_event; struct bt_event_class; struct bt_clock_class_priority_map; -extern struct bt_notification *bt_notification_event_create( +extern +struct bt_notification *bt_notification_event_create(struct bt_graph *graph, struct bt_event_class *event_class, struct bt_packet *packet, struct bt_clock_class_priority_map *clock_class_priority_map); diff --git a/include/babeltrace/graph/notification-heap-internal.h b/include/babeltrace/graph/notification-heap-internal.h deleted file mode 100644 index a93c5fb2..00000000 --- a/include/babeltrace/graph/notification-heap-internal.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef BABELTRACE_GRAPH_NOTIFICATION_HEAP_INTERNAL_H -#define BABELTRACE_GRAPH_NOTIFICATION_HEAP_INTERNAL_H - -/* - * Babeltrace - CTF notification heap priority heap - * - * Copyright (c) 2016 Jérémie Galarneau - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include -#include -#include -#include - -struct bt_notification_heap { - struct bt_object base; - GPtrArray *ptrs; - size_t count; - bt_notification_time_compare_func compare; - void *compare_data; -}; - -#endif /* BABELTRACE_GRAPH_NOTIFICATION_HEAP_INTERNAL_H */ diff --git a/include/babeltrace/graph/notification-heap.h b/include/babeltrace/graph/notification-heap.h deleted file mode 100644 index 3efb541e..00000000 --- a/include/babeltrace/graph/notification-heap.h +++ /dev/null @@ -1,103 +0,0 @@ -#ifndef BABELTRACE_GRAPH_NOTIFICATION_HEAP_H -#define BABELTRACE_GRAPH_NOTIFICATION_HEAP_H - -/* - * Babeltrace - Notification Heap - * - * Copyright (c) 2011 Mathieu Desnoyers - * Copyright (c) 2016 Jérémie Galarneau - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -/* For bt_bool */ -#include - -#ifdef __cplusplus -extern "C" { -#endif - -struct bt_notification; - -/** - * bt_notification_time_compare - Compare two notifications' timestamps - * - * Compare two notifications in the time domain. Return true if 'a' happened - * prior to 'b'. In the case where both notifications are deemed to have - * happened at the same time, an implementation-defined critarion shall be - * used to order the notifications. This criterion shall ensure a consistent - * ordering over multiple runs. - */ -typedef bt_bool (*bt_notification_time_compare_func)( - struct bt_notification *a, struct bt_notification *b, - void *user_data); - -/** - * bt_notification_heap_create - create a new bt_notification heap. - * - * @comparator: Function to use for notification comparisons. - * - * Returns a new notification heap, NULL on error. - */ -extern struct bt_notification_heap *bt_notification_heap_create( - bt_notification_time_compare_func comparator, void *user_data); - -/** - * bt_notification_heap_insert - insert an element into the heap - * - * @heap: the heap to be operated on - * @notification: the notification to add - * - * Insert a notification into the heap. - * - * Returns 0 on success, a negative value on error. - */ -extern int bt_notification_heap_insert(struct bt_notification_heap *heap, - struct bt_notification *notification); - -/** - * bt_notification_heap_peek - return the element on top of the heap. - * - * @heap: the heap to be operated on - * - * Returns the top element of the heap, without performing any modification - * to the heap structure. Returns NULL if the heap is empty. The returned - * notification must be bt_put() by the caller. - */ -extern struct bt_notification *bt_notification_heap_peek( - struct bt_notification_heap *heap); - -/** - * bt_notification_heap_pop - remove the element sitting on top of the heap. - * @heap: the heap to be operated on - * - * Returns the top element of the heap. The element is removed from the - * heap. Returns NULL if the heap is empty. The returned notification must be - * bt_put() by the caller. - */ -extern struct bt_notification *bt_notification_heap_pop( - struct bt_notification_heap *heap); - -#ifdef __cplusplus -} -#endif - -#endif /* BABELTRACE_GRAPH_NOTIFICATION_HEAP_H */ diff --git a/include/babeltrace/graph/notification-inactivity.h b/include/babeltrace/graph/notification-inactivity.h index 93be8b12..c530660c 100644 --- a/include/babeltrace/graph/notification-inactivity.h +++ b/include/babeltrace/graph/notification-inactivity.h @@ -34,7 +34,9 @@ struct bt_notification; struct bt_clock_class_priority_map; struct bt_clock_class; -extern struct bt_notification *bt_notification_inactivity_create( +extern +struct bt_notification *bt_notification_inactivity_create( + struct bt_graph *graph, struct bt_clock_class_priority_map *clock_class_priority_map); extern struct bt_clock_class_priority_map * diff --git a/include/babeltrace/graph/notification-internal.h b/include/babeltrace/graph/notification-internal.h index 2fbdbb42..3cd90509 100644 --- a/include/babeltrace/graph/notification-internal.h +++ b/include/babeltrace/graph/notification-internal.h @@ -30,8 +30,10 @@ #include #include #include +#include #include #include +#include #include typedef struct bt_stream *(*get_stream_func)( @@ -40,9 +42,11 @@ typedef struct bt_stream *(*get_stream_func)( struct bt_notification { struct bt_object base; enum bt_notification_type type; - get_stream_func get_stream; uint64_t seq_num; bt_bool frozen; + + /* Owned by this; keeps the graph alive while the notif. is alive */ + struct bt_graph *graph; }; #define BT_ASSERT_PRE_NOTIF_IS_TYPE(_notif, _type) \ @@ -54,13 +58,61 @@ struct bt_notification { BT_HIDDEN void bt_notification_init(struct bt_notification *notification, enum bt_notification_type type, - bt_object_release_func release); + bt_object_release_func release, + struct bt_graph *graph); + +static inline +void bt_notification_reset(struct bt_notification *notification) +{ + BT_ASSERT(notification); + +#ifdef BT_DEV_MODE + notification->frozen = BT_FALSE; + notification->seq_num = UINT64_C(-1); +#endif +} + +static inline +struct bt_notification *bt_notification_create_from_pool( + struct bt_object_pool *pool, struct bt_graph *graph) +{ + struct bt_notification *notif = bt_object_pool_create_object(pool); + + if (!notif) { +#ifdef BT_LIB_LOGE + BT_LIB_LOGE("Cannot allocate one notification from notification pool: " + "%![pool-]+o, %![graph-]+g", pool, graph); +#endif + goto error; + } + + if (!notif->graph) { + notif->graph = graph; + } + + goto end; + +error: + BT_PUT(notif); -static inline void bt_notification_freeze(struct bt_notification *notification) +end: + return notif; +} + +static inline void _bt_notification_freeze(struct bt_notification *notification) { notification->frozen = BT_TRUE; } +BT_HIDDEN +void bt_notification_unlink_graph(struct bt_notification *notif); + +#ifdef BT_DEV_MODE +# define bt_notification_freeze _bt_notification_freeze +#else +# define bt_notification_freeze(_x) +#endif /* BT_DEV_MODE */ + static inline const char *bt_notification_type_string(enum bt_notification_type type) { diff --git a/include/babeltrace/graph/notification-iterator-internal.h b/include/babeltrace/graph/notification-iterator-internal.h index 55aa4e62..2d2ef9ca 100644 --- a/include/babeltrace/graph/notification-iterator-internal.h +++ b/include/babeltrace/graph/notification-iterator-internal.h @@ -95,6 +95,7 @@ struct bt_notification_iterator_private_connection { struct bt_component *upstream_component; /* Weak */ struct bt_port *upstream_port; /* Weak */ struct bt_connection *connection; /* Weak */ + struct bt_graph *graph; /* Weak */ /* * This hash table keeps the state of a stream as viewed by @@ -145,14 +146,6 @@ void bt_notification_iterator_replace_current_notification( iterator->current_notification = bt_get(notification); } -static inline -struct bt_notification_iterator_private_connection * -bt_private_connection_notification_iterator_borrow_from_private( - struct bt_private_connection_private_notification_iterator *private_notification_iterator) -{ - return (void *) private_notification_iterator; -} - static inline struct bt_private_connection_private_notification_iterator * bt_private_connection_private_notification_iterator_from_notification_iterator( diff --git a/include/babeltrace/graph/notification-packet-internal.h b/include/babeltrace/graph/notification-packet-internal.h index 467d0861..639925b4 100644 --- a/include/babeltrace/graph/notification-packet-internal.h +++ b/include/babeltrace/graph/notification-packet-internal.h @@ -42,4 +42,22 @@ struct bt_notification_packet_end { struct bt_packet *packet; }; +BT_HIDDEN +struct bt_notification *bt_notification_packet_begin_new( + struct bt_graph *graph); +BT_HIDDEN +void bt_notification_packet_begin_recycle(struct bt_notification *notif); + +BT_HIDDEN +void bt_notification_packet_begin_destroy(struct bt_notification *notif); + +BT_HIDDEN +struct bt_notification *bt_notification_packet_end_new(struct bt_graph *graph); + +BT_HIDDEN +void bt_notification_packet_end_recycle(struct bt_notification *notif); + +BT_HIDDEN +void bt_notification_packet_end_destroy(struct bt_notification *notif); + #endif /* BABELTRACE_GRAPH_NOTIFICATION_PACKET_INTERNAL_H */ diff --git a/include/babeltrace/graph/notification-packet.h b/include/babeltrace/graph/notification-packet.h index 6b237c3b..e3c9d55b 100644 --- a/include/babeltrace/graph/notification-packet.h +++ b/include/babeltrace/graph/notification-packet.h @@ -37,11 +37,14 @@ extern "C" { struct bt_notification; struct bt_packet; -extern struct bt_notification *bt_notification_packet_begin_create( - struct bt_packet *packet); +extern +struct bt_notification *bt_notification_packet_begin_create( + struct bt_graph *graph, struct bt_packet *packet); + +extern +struct bt_notification *bt_notification_packet_end_create( + struct bt_graph *graph, struct bt_packet *packet); -extern struct bt_notification *bt_notification_packet_end_create( - struct bt_packet *packet); extern struct bt_packet *bt_notification_packet_begin_borrow_packet( struct bt_notification *notification); diff --git a/include/babeltrace/graph/notification-stream.h b/include/babeltrace/graph/notification-stream.h index 5deff05b..e016117a 100644 --- a/include/babeltrace/graph/notification-stream.h +++ b/include/babeltrace/graph/notification-stream.h @@ -37,10 +37,14 @@ extern "C" { struct bt_notification; struct bt_stream; -extern struct bt_notification *bt_notification_stream_begin_create( +extern +struct bt_notification *bt_notification_stream_begin_create( + struct bt_graph *graph, struct bt_stream *stream); -extern struct bt_notification *bt_notification_stream_end_create( +extern +struct bt_notification *bt_notification_stream_end_create( + struct bt_graph *graph, struct bt_stream *stream); extern struct bt_stream *bt_notification_stream_begin_borrow_stream( diff --git a/include/babeltrace/graph/port-internal.h b/include/babeltrace/graph/port-internal.h index 8f2fb4b7..57f817ee 100644 --- a/include/babeltrace/graph/port-internal.h +++ b/include/babeltrace/graph/port-internal.h @@ -37,13 +37,6 @@ struct bt_port { void *user_data; }; -static inline -struct bt_port *bt_port_borrow_from_private( - struct bt_private_port *private_port) -{ - return (void *) private_port; -} - static inline struct bt_private_port *bt_private_port_from_port( struct bt_port *port) diff --git a/include/babeltrace/graph/private-component.h b/include/babeltrace/graph/private-component.h index ce0a6b06..f2663011 100644 --- a/include/babeltrace/graph/private-component.h +++ b/include/babeltrace/graph/private-component.h @@ -30,7 +30,7 @@ extern "C" { struct bt_component; struct bt_private_component; -extern struct bt_component *bt_component_from_private( +extern struct bt_component *bt_component_borrow_from_private( struct bt_private_component *private_component); extern void *bt_private_component_get_user_data( diff --git a/include/babeltrace/graph/private-connection-private-notification-iterator.h b/include/babeltrace/graph/private-connection-private-notification-iterator.h index 1a855e96..339cf80c 100644 --- a/include/babeltrace/graph/private-connection-private-notification-iterator.h +++ b/include/babeltrace/graph/private-connection-private-notification-iterator.h @@ -34,7 +34,7 @@ struct bt_private_connection; struct bt_private_connection_private_notification_iterator; extern struct bt_notification_iterator * -bt_private_connection_notification_iterator_from_private( +bt_private_connection_notification_iterator_borrow_from_private( struct bt_private_connection_private_notification_iterator *private_notification_iterator); extern struct bt_private_component * @@ -49,6 +49,9 @@ bt_private_connection_private_notification_iterator_set_user_data( extern void *bt_private_connection_private_notification_iterator_get_user_data( struct bt_private_connection_private_notification_iterator *private_notification_iterator); +extern struct bt_graph *bt_private_connection_private_notification_iterator_borrow_graph( + struct bt_private_connection_private_notification_iterator *private_notification_iterator); + #ifdef __cplusplus } #endif diff --git a/include/babeltrace/graph/private-connection.h b/include/babeltrace/graph/private-connection.h index e62c1e36..c3692361 100644 --- a/include/babeltrace/graph/private-connection.h +++ b/include/babeltrace/graph/private-connection.h @@ -36,7 +36,7 @@ struct bt_private_port; struct bt_private_connection; struct bt_notification_iterator; -extern struct bt_connection *bt_connection_from_private( +extern struct bt_connection *bt_connection_borrow_from_private( struct bt_private_connection *private_connection); extern enum bt_connection_status diff --git a/include/babeltrace/graph/private-port.h b/include/babeltrace/graph/private-port.h index e109649f..264de482 100644 --- a/include/babeltrace/graph/private-port.h +++ b/include/babeltrace/graph/private-port.h @@ -32,7 +32,8 @@ struct bt_private_port; struct bt_private_component; struct bt_private_connection; -struct bt_port *bt_port_from_private(struct bt_private_port *private_port); +struct bt_port *bt_port_borrow_from_private( + struct bt_private_port *private_port); extern struct bt_private_connection *bt_private_port_get_private_connection( struct bt_private_port *private_port); extern struct bt_private_component *bt_private_port_get_private_component( diff --git a/lib/ctf-ir/stream-class.c b/lib/ctf-ir/stream-class.c index c414f79d..45f519ad 100644 --- a/lib/ctf-ir/stream-class.c +++ b/lib/ctf-ir/stream-class.c @@ -131,7 +131,7 @@ void bt_stream_class_destroy(struct bt_object *obj) * * 4. Destroying an event makes it recycle its event header * field to its stream class's event header field pool. But - * said pool is already destroyed. + * said pool is already finalized. */ bt_stream_class_common_finalize(BT_TO_COMMON(stream_class)); bt_object_pool_finalize(&stream_class->event_header_field_pool); diff --git a/lib/graph/component.c b/lib/graph/component.c index 1c83b4b3..185b8d10 100644 --- a/lib/graph/component.c +++ b/lib/graph/component.c @@ -144,10 +144,10 @@ void bt_component_destroy(struct bt_object *obj) g_free(component); } -struct bt_component *bt_component_from_private( +struct bt_component *bt_component_borrow_from_private( struct bt_private_component *private_component) { - return bt_get(bt_component_borrow_from_private(private_component)); + return (void *) private_component; } enum bt_component_class_type bt_component_get_class_type( @@ -371,10 +371,9 @@ void bt_component_set_graph(struct bt_component *component, bt_object_set_parent(component, graph ? &graph->base : NULL); } -struct bt_graph *bt_component_get_graph( - struct bt_component *component) +struct bt_graph *bt_component_borrow_graph(struct bt_component *component) { - return (struct bt_graph *) bt_object_get_parent(&component->base); + return (struct bt_graph *) bt_object_borrow_parent(&component->base); } static diff --git a/lib/graph/connection.c b/lib/graph/connection.c index 73b5383d..91d130ed 100644 --- a/lib/graph/connection.c +++ b/lib/graph/connection.c @@ -117,10 +117,10 @@ void bt_connection_parent_is_owner(struct bt_object *obj) bt_connection_try_remove_from_graph(connection); } -struct bt_connection *bt_connection_from_private( +struct bt_connection *bt_connection_borrow_from_private( struct bt_private_connection *private_connection) { - return bt_get(bt_connection_borrow_from_private(private_connection)); + return (void *) private_connection; } BT_HIDDEN diff --git a/lib/graph/filter.c b/lib/graph/filter.c index 8914e1ef..a82270e7 100644 --- a/lib/graph/filter.c +++ b/lib/graph/filter.c @@ -31,6 +31,7 @@ #include #include +#include #include #include #include diff --git a/lib/graph/graph.c b/lib/graph/graph.c index c7c27058..d8181f0b 100644 --- a/lib/graph/graph.c +++ b/lib/graph/graph.c @@ -35,6 +35,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -129,14 +132,20 @@ void bt_graph_destroy(struct bt_object *obj) call_remove_listeners(graph->listeners.ports_connected); call_remove_listeners(graph->listeners.ports_disconnected); + if (graph->notifications) { + g_ptr_array_free(graph->notifications, TRUE); + } + if (graph->connections) { BT_LOGD_STR("Destroying connections."); g_ptr_array_free(graph->connections, TRUE); } + if (graph->components) { BT_LOGD_STR("Destroying components."); g_ptr_array_free(graph->components, TRUE); } + if (graph->sinks_to_consume) { g_queue_free(graph->sinks_to_consume); } @@ -157,9 +166,39 @@ void bt_graph_destroy(struct bt_object *obj) g_array_free(graph->listeners.ports_disconnected, TRUE); } + bt_object_pool_finalize(&graph->event_notif_pool); + bt_object_pool_finalize(&graph->packet_begin_notif_pool); + bt_object_pool_finalize(&graph->packet_end_notif_pool); g_free(graph); } +static +void destroy_notification_event(struct bt_notification *notif, + struct bt_graph *graph) +{ + bt_notification_event_destroy(notif); +} + +static +void destroy_notification_packet_begin(struct bt_notification *notif, + struct bt_graph *graph) +{ + bt_notification_packet_begin_destroy(notif); +} + +static +void destroy_notification_packet_end(struct bt_notification *notif, + struct bt_graph *graph) +{ + bt_notification_packet_end_destroy(notif); +} + +static +void notify_notification_graph_is_destroyed(struct bt_notification *notif) +{ + bt_notification_unlink_graph(notif); +} + struct bt_graph *bt_graph_create(void) { struct bt_graph *graph; @@ -215,6 +254,38 @@ struct bt_graph *bt_graph_create(void) goto error; } + ret = bt_object_pool_initialize(&graph->event_notif_pool, + (bt_object_pool_new_object_func) bt_notification_event_new, + (bt_object_pool_destroy_object_func) destroy_notification_event, + graph); + if (ret) { + BT_LOGE("Failed to initialize event notification pool: ret=%d", + ret); + goto error; + } + + ret = bt_object_pool_initialize(&graph->packet_begin_notif_pool, + (bt_object_pool_new_object_func) bt_notification_packet_begin_new, + (bt_object_pool_destroy_object_func) destroy_notification_packet_begin, + graph); + if (ret) { + BT_LOGE("Failed to initialize packet beginning notification pool: ret=%d", + ret); + goto error; + } + + ret = bt_object_pool_initialize(&graph->packet_end_notif_pool, + (bt_object_pool_new_object_func) bt_notification_packet_end_new, + (bt_object_pool_destroy_object_func) destroy_notification_packet_end, + graph); + if (ret) { + BT_LOGE("Failed to initialize packet end notification pool: ret=%d", + ret); + goto error; + } + + graph->notifications = g_ptr_array_new_with_free_func( + (GDestroyNotify) notify_notification_graph_is_destroyed); BT_LOGD("Created graph object: addr=%p", graph); end: @@ -1187,3 +1258,21 @@ end: graph->can_consume = init_can_consume; return ret; } + +BT_HIDDEN +void bt_graph_add_notification(struct bt_graph *graph, + struct bt_notification *notif) +{ + BT_ASSERT(graph); + BT_ASSERT(notif); + + /* + * It's okay not to take a reference because, when a + * notification's reference count drops to 0, either: + * + * * It is recycled back to one of this graph's pool. + * * It is destroyed because it doesn't have any link to any + * graph, which means the original graph is already destroyed. + */ + g_ptr_array_add(graph->notifications, notif); +} diff --git a/lib/graph/iterator.c b/lib/graph/iterator.c index 61b5298b..799888bc 100644 --- a/lib/graph/iterator.c +++ b/lib/graph/iterator.c @@ -347,6 +347,7 @@ enum bt_connection_status bt_private_connection_notification_iterator_create( iterator->upstream_component = upstream_comp; iterator->upstream_port = upstream_port; iterator->connection = connection; + iterator->graph = bt_component_borrow_graph(upstream_comp); iterator->state = BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_STATE_NON_INITIALIZED; BT_LOGD("Created notification iterator: " "upstream-comp-addr=%p, upstream-comp-name=\"%s\", " @@ -368,7 +369,7 @@ end: void *bt_private_connection_private_notification_iterator_get_user_data( struct bt_private_connection_private_notification_iterator *private_iterator) { - struct bt_notification_iterator_private_connection *iterator = + struct bt_notification_iterator_private_connection *iterator = (void *) bt_private_connection_notification_iterator_borrow_from_private(private_iterator); BT_ASSERT_PRE_NON_NULL(private_iterator, "Notification iterator"); @@ -380,7 +381,7 @@ bt_private_connection_private_notification_iterator_set_user_data( struct bt_private_connection_private_notification_iterator *private_iterator, void *data) { - struct bt_notification_iterator_private_connection *iterator = + struct bt_notification_iterator_private_connection *iterator = (void *) bt_private_connection_notification_iterator_borrow_from_private(private_iterator); BT_ASSERT_PRE_NON_NULL(iterator, "Notification iterator"); @@ -390,6 +391,17 @@ bt_private_connection_private_notification_iterator_set_user_data( return BT_NOTIFICATION_ITERATOR_STATUS_OK; } +struct bt_graph *bt_private_connection_private_notification_iterator_borrow_graph( + struct bt_private_connection_private_notification_iterator *private_iterator) +{ + struct bt_notification_iterator_private_connection *iterator = (void *) + bt_private_connection_notification_iterator_borrow_from_private( + private_iterator); + + BT_ASSERT_PRE_NON_NULL(iterator, "Notification iterator"); + return iterator->graph; +} + struct bt_notification *bt_notification_iterator_borrow_notification( struct bt_notification_iterator *iterator) { @@ -1004,10 +1016,8 @@ end: } struct bt_notification_iterator * -bt_private_connection_notification_iterator_from_private( +bt_private_connection_notification_iterator_borrow_from_private( struct bt_private_connection_private_notification_iterator *private_notification_iterator) { - return bt_get( - bt_private_connection_notification_iterator_borrow_from_private( - private_notification_iterator)); + return (void *) private_notification_iterator; } diff --git a/lib/graph/notification/Makefile.am b/lib/graph/notification/Makefile.am index 61bd98af..2c837b10 100644 --- a/lib/graph/notification/Makefile.am +++ b/lib/graph/notification/Makefile.am @@ -5,7 +5,6 @@ libgraph_notification_la_SOURCES = \ packet.c \ event.c \ stream.c \ - heap.c \ inactivity.c \ discarded-events.c \ discarded-packets.c \ diff --git a/lib/graph/notification/discarded-elements.c b/lib/graph/notification/discarded-elements.c index 08fa0cbf..0dfd7579 100644 --- a/lib/graph/notification/discarded-elements.c +++ b/lib/graph/notification/discarded-elements.c @@ -53,6 +53,7 @@ void bt_notification_discarded_elements_destroy(struct bt_object *obj) BT_HIDDEN struct bt_notification *bt_notification_discarded_elements_create( + struct bt_graph *graph, enum bt_notification_type type, struct bt_stream *stream, struct bt_clock_value *begin_clock_value, @@ -77,7 +78,7 @@ struct bt_notification *bt_notification_discarded_elements_create( } bt_notification_init(¬ification->parent, type, - bt_notification_discarded_elements_destroy); + bt_notification_discarded_elements_destroy, NULL); ret_notif = ¬ification->parent; notification->stream = bt_get(stream); notification->begin_clock_value = bt_get(begin_clock_value); diff --git a/lib/graph/notification/event.c b/lib/graph/notification/event.c index 486a8b10..3ed1c4cd 100644 --- a/lib/graph/notification/event.c +++ b/lib/graph/notification/event.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -42,21 +43,6 @@ #include #include -static -void bt_notification_event_destroy(struct bt_object *obj) -{ - struct bt_notification_event *notification = - (struct bt_notification_event *) obj; - - BT_LOGD("Destroying event notification: addr=%p", notification); - BT_LOGD_STR("Recycling event."); - bt_event_recycle(notification->event); - notification->event = NULL; - BT_LOGD_STR("Putting clock class priority map."); - BT_PUT(notification->cc_prio_map); - g_free(notification); -} - BT_ASSERT_PRE_FUNC static inline bool event_class_has_trace(struct bt_event_class *event_class) { @@ -67,7 +53,30 @@ static inline bool event_class_has_trace(struct bt_event_class *event_class) return bt_stream_class_borrow_trace(stream_class) != NULL; } +BT_HIDDEN +struct bt_notification *bt_notification_event_new(struct bt_graph *graph) +{ + struct bt_notification_event *notification = NULL; + + notification = g_new0(struct bt_notification_event, 1); + if (!notification) { + BT_LOGE_STR("Failed to allocate one event notification."); + goto error; + } + + bt_notification_init(¬ification->parent, BT_NOTIFICATION_TYPE_EVENT, + (bt_object_release_func) bt_notification_event_recycle, graph); + goto end; + +error: + BT_PUT(notification); + +end: + return (void *) notification; +} + struct bt_notification *bt_notification_event_create( + struct bt_graph *graph, struct bt_event_class *event_class, struct bt_packet *packet, struct bt_clock_class_priority_map *cc_prio_map) @@ -99,14 +108,13 @@ struct bt_notification *bt_notification_event_create( BT_ASSERT_PRE(event_class_has_trace(event_class), "Event class is not part of a trace: %!+E", event_class); - notification = g_new0(struct bt_notification_event, 1); + notification = (void *) bt_notification_create_from_pool( + &graph->event_notif_pool, graph); if (!notification) { - BT_LOGE_STR("Failed to allocate one event notification."); + /* bt_notification_create_from_pool() logs errors */ goto error; } - bt_notification_init(¬ification->parent, BT_NOTIFICATION_TYPE_EVENT, - bt_notification_event_destroy); notification->event = bt_event_create(event_class, packet); if (!notification->event) { BT_LIB_LOGE("Cannot create event from event class: " @@ -132,7 +140,52 @@ error: end: bt_put(cc_prio_map); - return ¬ification->parent; + return (void *) notification; +} + +BT_HIDDEN +void bt_notification_event_destroy(struct bt_notification *notif) +{ + struct bt_notification_event *event_notif = (void *) notif; + + BT_LOGD("Destroying event notification: addr=%p", notif); + + if (event_notif->event) { + BT_LOGD_STR("Recycling event."); + bt_event_recycle(event_notif->event); + } + + BT_LOGD_STR("Putting clock class priority map."); + BT_PUT(event_notif->cc_prio_map); + g_free(notif); +} + +BT_HIDDEN +void bt_notification_event_recycle(struct bt_notification *notif) +{ + struct bt_notification_event *event_notif = (void *) notif; + struct bt_graph *graph; + + BT_ASSERT(event_notif); + + if (!notif->graph) { + bt_notification_event_destroy(notif); + return; + } + + BT_LOGD("Recycling event notification: addr=%p", notif); + bt_notification_reset(notif); + + if (event_notif->event) { + BT_LOGD_STR("Recycling event."); + bt_event_recycle(event_notif->event); + event_notif->event = NULL; + } + + BT_PUT(event_notif->cc_prio_map); + graph = notif->graph; + notif->graph = NULL; + bt_object_pool_recycle_object(&graph->event_notif_pool, notif); } struct bt_event *bt_notification_event_borrow_event( diff --git a/lib/graph/notification/heap.c b/lib/graph/notification/heap.c deleted file mode 100644 index f2d87a8b..00000000 --- a/lib/graph/notification/heap.c +++ /dev/null @@ -1,264 +0,0 @@ -/* - * Babeltrace - CTF notification priority heap - * - * Static-sized priority heap containing pointers. Based on CLRS, - * chapter 6. - * - * Copyright (c) 2011 Mathieu Desnoyers - * Copyright (c) 2016 Jérémie Galarneau - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include -#include -#include -#include - -#ifdef DEBUG_HEAP -static -void check_heap(struct bt_notification_heap *heap) -{ - size_t i; - - if (!heap->count) { - return; - } - - for (i = 1; i < heap->count; i++) { - BT_ASSERT(!heap->compare(g_ptr_array_index(heap->ptrs, i), - g_ptr_array_index(heap->ptrs, 0), - heap->compare_data)); - } -} -#else -void check_heap(struct bt_notification_heap *heap) -{ -} -#endif - -static -size_t parent(size_t i) -{ - return (i - 1) >> 1; -} - -static -size_t left(size_t i) -{ - return (i << 1) + 1; -} - -static -size_t right(size_t i) -{ - return (i << 1) + 2; -} - -/* - * Copy of heap->ptrs pointer is invalid after heap_grow. - */ -static -int heap_grow(struct bt_notification_heap *heap, size_t new_len) -{ - size_t alloc_len; - - if (likely(heap->ptrs->len >= new_len)) { - goto end; - } - - alloc_len = max_t(size_t, new_len, heap->ptrs->len << 1); - g_ptr_array_set_size(heap->ptrs, alloc_len); -end: - return 0; -} - -static -int heap_set_count(struct bt_notification_heap *heap, size_t new_count) -{ - int ret = 0; - - ret = heap_grow(heap, new_count); - if (unlikely(ret)) { - goto end; - } - heap->count = new_count; -end: - return ret; -} - -static -void heapify(struct bt_notification_heap *heap, size_t i) -{ - struct bt_notification **ptrs = - (struct bt_notification **) heap->ptrs->pdata; - - for (;;) { - void *tmp; - size_t l, r, largest; - - l = left(i); - r = right(i); - if (l < heap->count && heap->compare(ptrs[l], ptrs[i], - heap->compare_data)) { - largest = l; - } else { - largest = i; - } - if (r < heap->count && heap->compare(ptrs[r], ptrs[largest], - heap->compare_data)) { - largest = r; - } - if (unlikely(largest == i)) { - break; - } - tmp = ptrs[i]; - ptrs[i] = ptrs[largest]; - ptrs[largest] = tmp; - i = largest; - } - check_heap(heap); -} - -static -struct bt_notification *heap_replace_max(struct bt_notification_heap *heap, - struct bt_notification *notification) -{ - struct bt_notification *res = NULL; - - if (unlikely(!heap->count)) { - (void) heap_set_count(heap, 1); - g_ptr_array_index(heap->ptrs, 0) = notification; - check_heap(heap); - goto end; - } - - /* Replace the current max and heapify. */ - res = g_ptr_array_index(heap->ptrs, 0); - g_ptr_array_index(heap->ptrs, 0) = notification; - heapify(heap, 0); -end: - return res; -} - -static -void bt_notification_heap_destroy(struct bt_object *obj) -{ - struct bt_notification_heap *heap = container_of(obj, - struct bt_notification_heap, base); - - if (heap->ptrs) { - size_t i; - - for (i = 0; i < heap->count; i++) { - bt_put(g_ptr_array_index(heap->ptrs, i)); - } - g_ptr_array_free(heap->ptrs, TRUE); - } - g_free(heap); -} - -struct bt_notification_heap *bt_notification_heap_create( - bt_notification_time_compare_func comparator, void *user_data) -{ - struct bt_notification_heap *heap = NULL; - - if (!comparator) { - goto end; - } - - heap = g_new0(struct bt_notification_heap, 1); - if (!heap) { - goto end; - } - - bt_object_init(&heap->base, bt_notification_heap_destroy); - heap->ptrs = g_ptr_array_new(); - if (!heap->ptrs) { - BT_PUT(heap); - goto end; - } - - heap->compare = comparator; - heap->compare_data = user_data; -end: - return heap; -} - -struct bt_notification *bt_notification_heap_peek( - struct bt_notification_heap *heap) -{ - check_heap(heap); - return bt_get(likely(heap->count) ? - g_ptr_array_index(heap->ptrs, 0) : NULL); -} - -int bt_notification_heap_insert(struct bt_notification_heap *heap, - struct bt_notification *notification) -{ - int ret; - size_t pos; - struct bt_notification **ptrs; - - ret = heap_set_count(heap, heap->count + 1); - if (unlikely(ret)) { - goto end; - } - - ptrs = (struct bt_notification **) heap->ptrs->pdata; - pos = heap->count - 1; - while (pos > 0 && heap->compare(notification, ptrs[parent(pos)], - heap->compare_data)) { - /* Move parent down until we find the right spot. */ - ptrs[pos] = ptrs[parent(pos)]; - pos = parent(pos); - } - ptrs[pos] = bt_get(notification); - check_heap(heap); -end: - return ret; -} - -struct bt_notification *bt_notification_heap_pop( - struct bt_notification_heap *heap) -{ - struct bt_notification *ret = NULL; - - switch (heap->count) { - case 0: - goto end; - case 1: - (void) heap_set_count(heap, 0); - ret = g_ptr_array_index(heap->ptrs, 0); - goto end; - } - /* - * Shrink, replace the current max by previous last entry and heapify. - */ - heap_set_count(heap, heap->count - 1); - /* count changed. previous last entry is at heap->count. */ - ret = heap_replace_max(heap, g_ptr_array_index(heap->ptrs, - heap->count)); -end: - /* - * Not taking a supplementary reference since we are relinquishing our - * own to the caller. - */ - return ret; -} diff --git a/lib/graph/notification/inactivity.c b/lib/graph/notification/inactivity.c index 2575c144..b6708d3b 100644 --- a/lib/graph/notification/inactivity.c +++ b/lib/graph/notification/inactivity.c @@ -52,6 +52,7 @@ void bt_notification_inactivity_destroy(struct bt_object *obj) } struct bt_notification *bt_notification_inactivity_create( + struct bt_graph *graph, struct bt_clock_class_priority_map *cc_prio_map) { struct bt_notification_inactivity *notification; @@ -79,7 +80,7 @@ struct bt_notification *bt_notification_inactivity_create( } bt_notification_init(¬ification->parent, BT_NOTIFICATION_TYPE_INACTIVITY, - bt_notification_inactivity_destroy); + bt_notification_inactivity_destroy, NULL); ret_notif = ¬ification->parent; notification->clock_values = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify) bt_clock_value_recycle); diff --git a/lib/graph/notification/notification.c b/lib/graph/notification/notification.c index 57da6c33..0bcfb7df 100644 --- a/lib/graph/notification/notification.c +++ b/lib/graph/notification/notification.c @@ -28,13 +28,14 @@ #include #include +#include #include #include BT_ASSERT_PRE_FUNC static inline void _init_seq_num(struct bt_notification *notification) { - notification->seq_num = -1ULL; + notification->seq_num = UINT64_C(-1); } #ifdef BT_DEV_MODE @@ -46,12 +47,18 @@ static inline void _init_seq_num(struct bt_notification *notification) BT_HIDDEN void bt_notification_init(struct bt_notification *notification, enum bt_notification_type type, - bt_object_release_func release) + bt_object_release_func release, + struct bt_graph *graph) { BT_ASSERT(type >= 0 && type < BT_NOTIFICATION_TYPE_NR); notification->type = type; init_seq_num(notification); bt_object_init(¬ification->base, release); + notification->graph = graph; + + if (graph) { + bt_graph_add_notification(graph, notification); + } } enum bt_notification_type bt_notification_get_type( @@ -60,3 +67,10 @@ enum bt_notification_type bt_notification_get_type( BT_ASSERT_PRE_NON_NULL(notification, "Notification"); return notification->type; } + +BT_HIDDEN +void bt_notification_unlink_graph(struct bt_notification *notif) +{ + BT_ASSERT(notif); + notif->graph = NULL; +} diff --git a/lib/graph/notification/packet.c b/lib/graph/notification/packet.c index fb590c3c..17b00d46 100644 --- a/lib/graph/notification/packet.c +++ b/lib/graph/notification/packet.c @@ -33,39 +33,38 @@ #include #include #include +#include #include #include #include #include -static -void bt_notification_packet_begin_destroy(struct bt_object *obj) +BT_HIDDEN +struct bt_notification *bt_notification_packet_begin_new(struct bt_graph *graph) { - struct bt_notification_packet_begin *notification = - (struct bt_notification_packet_begin *) obj; + struct bt_notification_packet_begin *notification; - BT_LOGD("Destroying packet beginning notification: addr=%p", - notification); - BT_LOGD_STR("Putting packet."); - BT_PUT(notification->packet); - g_free(notification); -} + notification = g_new0(struct bt_notification_packet_begin, 1); + if (!notification) { + BT_LOGE_STR("Failed to allocate one packet beginning notification."); + goto error; + } -static -void bt_notification_packet_end_destroy(struct bt_object *obj) -{ - struct bt_notification_packet_end *notification = - (struct bt_notification_packet_end *) obj; + bt_notification_init(¬ification->parent, + BT_NOTIFICATION_TYPE_PACKET_BEGIN, + (bt_object_release_func) bt_notification_packet_begin_recycle, + graph); + goto end; - BT_LOGD("Destroying packet end notification: addr=%p", - notification); - BT_LOGD_STR("Putting packet."); - BT_PUT(notification->packet); - g_free(notification); +error: + BT_PUT(notification); + +end: + return (void *) notification; } struct bt_notification *bt_notification_packet_begin_create( - struct bt_packet *packet) + struct bt_graph *graph, struct bt_packet *packet) { struct bt_notification_packet_begin *notification; struct bt_stream *stream; @@ -84,15 +83,13 @@ struct bt_notification *bt_notification_packet_begin_create( stream_class, bt_stream_class_get_name(stream_class), bt_stream_class_get_id(stream_class)); - notification = g_new0(struct bt_notification_packet_begin, 1); + notification = (void *) bt_notification_create_from_pool( + &graph->packet_begin_notif_pool, graph); if (!notification) { - BT_LOGE_STR("Failed to allocate one packet beginning notification."); + /* bt_notification_create_from_pool() logs errors */ goto error; } - bt_notification_init(¬ification->parent, - BT_NOTIFICATION_TYPE_PACKET_BEGIN, - bt_notification_packet_begin_destroy); notification->packet = bt_get(packet); BT_LOGD("Created packet beginning notification object: " "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", " @@ -102,9 +99,45 @@ struct bt_notification *bt_notification_packet_begin_create( stream_class, bt_stream_class_get_name(stream_class), bt_stream_class_get_id(stream_class), notification); - return ¬ification->parent; + goto end; + error: - return NULL; + BT_PUT(notification); + +end: + return (void *) notification; +} + +BT_HIDDEN +void bt_notification_packet_begin_destroy(struct bt_notification *notif) +{ + struct bt_notification_packet_begin *packet_begin_notif = (void *) notif; + + BT_LOGD("Destroying packet beginning notification: addr=%p", notif); + BT_LOGD_STR("Putting packet."); + BT_PUT(packet_begin_notif->packet); + g_free(notif); +} + +BT_HIDDEN +void bt_notification_packet_begin_recycle(struct bt_notification *notif) +{ + struct bt_notification_packet_begin *packet_begin_notif = (void *) notif; + struct bt_graph *graph; + + BT_ASSERT(packet_begin_notif); + + if (!notif->graph) { + bt_notification_packet_begin_destroy(notif); + return; + } + + BT_LOGD("Recycling packet beginning notification: addr=%p", notif); + bt_notification_reset(notif); + BT_PUT(packet_begin_notif->packet); + graph = notif->graph; + notif->graph = NULL; + bt_object_pool_recycle_object(&graph->packet_begin_notif_pool, notif); } struct bt_packet *bt_notification_packet_begin_borrow_packet( @@ -120,8 +153,32 @@ struct bt_packet *bt_notification_packet_begin_borrow_packet( return packet_begin->packet; } +BT_HIDDEN +struct bt_notification *bt_notification_packet_end_new(struct bt_graph *graph) +{ + struct bt_notification_packet_end *notification; + + notification = g_new0(struct bt_notification_packet_end, 1); + if (!notification) { + BT_LOGE_STR("Failed to allocate one packet end notification."); + goto error; + } + + bt_notification_init(¬ification->parent, + BT_NOTIFICATION_TYPE_PACKET_END, + (bt_object_release_func) bt_notification_packet_end_recycle, + graph); + goto end; + +error: + BT_PUT(notification); + +end: + return (void *) notification; +} + struct bt_notification *bt_notification_packet_end_create( - struct bt_packet *packet) + struct bt_graph *graph, struct bt_packet *packet) { struct bt_notification_packet_end *notification; struct bt_stream *stream; @@ -140,15 +197,13 @@ struct bt_notification *bt_notification_packet_end_create( stream_class, bt_stream_class_get_name(stream_class), bt_stream_class_get_id(stream_class)); - notification = g_new0(struct bt_notification_packet_end, 1); + notification = (void *) bt_notification_create_from_pool( + &graph->packet_end_notif_pool, graph); if (!notification) { - BT_LOGE_STR("Failed to allocate one packet end notification."); + /* bt_notification_create_from_pool() logs errors */ goto error; } - bt_notification_init(¬ification->parent, - BT_NOTIFICATION_TYPE_PACKET_END, - bt_notification_packet_end_destroy); notification->packet = bt_get(packet); BT_LOGD("Created packet end notification object: " "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", " @@ -158,9 +213,45 @@ struct bt_notification *bt_notification_packet_end_create( stream_class, bt_stream_class_get_name(stream_class), bt_stream_class_get_id(stream_class), notification); - return ¬ification->parent; + goto end; + error: - return NULL; + BT_PUT(notification); + +end: + return (void *) notification; +} + +BT_HIDDEN +void bt_notification_packet_end_destroy(struct bt_notification *notif) +{ + struct bt_notification_packet_end *packet_end_notif = (void *) notif; + + BT_LOGD("Destroying packet end notification: addr=%p", notif); + BT_LOGD_STR("Putting packet."); + BT_PUT(packet_end_notif->packet); + g_free(notif); +} + +BT_HIDDEN +void bt_notification_packet_end_recycle(struct bt_notification *notif) +{ + struct bt_notification_packet_end *packet_end_notif = (void *) notif; + struct bt_graph *graph; + + BT_ASSERT(packet_end_notif); + + if (!notif->graph) { + bt_notification_packet_end_destroy(notif); + return; + } + + BT_LOGD("Recycling packet end notification: addr=%p", notif); + bt_notification_reset(notif); + BT_PUT(packet_end_notif->packet); + graph = notif->graph; + notif->graph = NULL; + bt_object_pool_recycle_object(&graph->packet_end_notif_pool, notif); } struct bt_packet *bt_notification_packet_end_borrow_packet( diff --git a/lib/graph/notification/stream.c b/lib/graph/notification/stream.c index 8f35e3c6..a1ce7a5a 100644 --- a/lib/graph/notification/stream.c +++ b/lib/graph/notification/stream.c @@ -49,7 +49,7 @@ void bt_notification_stream_end_destroy(struct bt_object *obj) } struct bt_notification *bt_notification_stream_end_create( - struct bt_stream *stream) + struct bt_graph *graph, struct bt_stream *stream) { struct bt_notification_stream_end *notification; struct bt_stream_class *stream_class; @@ -73,7 +73,7 @@ struct bt_notification *bt_notification_stream_end_create( bt_notification_init(¬ification->parent, BT_NOTIFICATION_TYPE_STREAM_END, - bt_notification_stream_end_destroy); + bt_notification_stream_end_destroy, NULL); notification->stream = bt_get(stream); BT_LOGD("Created stream end notification object: " "stream-addr=%p, stream-name=\"%s\", " @@ -115,7 +115,7 @@ void bt_notification_stream_begin_destroy(struct bt_object *obj) } struct bt_notification *bt_notification_stream_begin_create( - struct bt_stream *stream) + struct bt_graph *graph, struct bt_stream *stream) { struct bt_notification_stream_begin *notification; struct bt_stream_class *stream_class; @@ -139,7 +139,7 @@ struct bt_notification *bt_notification_stream_begin_create( bt_notification_init(¬ification->parent, BT_NOTIFICATION_TYPE_STREAM_BEGIN, - bt_notification_stream_begin_destroy); + bt_notification_stream_begin_destroy, NULL); notification->stream = bt_get(stream); BT_LOGD("Created stream beginning notification object: " "stream-addr=%p, stream-name=\"%s\", " diff --git a/lib/graph/port.c b/lib/graph/port.c index 25b427d2..950a0a26 100644 --- a/lib/graph/port.c +++ b/lib/graph/port.c @@ -52,10 +52,10 @@ void bt_port_destroy(struct bt_object *obj) g_free(port); } -struct bt_port *bt_port_from_private( +struct bt_port *bt_port_borrow_from_private( struct bt_private_port *private_port) { - return bt_get(bt_port_borrow_from_private(private_port)); + return (void *) private_port; } BT_HIDDEN diff --git a/lib/graph/sink.c b/lib/graph/sink.c index 5c8bec7a..bee8403c 100644 --- a/lib/graph/sink.c +++ b/lib/graph/sink.c @@ -31,6 +31,7 @@ #include #include +#include #include #include #include diff --git a/lib/graph/source.c b/lib/graph/source.c index afdb3765..52ac8c81 100644 --- a/lib/graph/source.c +++ b/lib/graph/source.c @@ -31,6 +31,7 @@ #include #include +#include #include #include #include diff --git a/lib/lib-logging.c b/lib/lib-logging.c index 214c2e3a..d1ac59e6 100644 --- a/lib/lib-logging.c +++ b/lib/lib-logging.c @@ -66,7 +66,6 @@ #include #include #include -#include #include #include #include @@ -586,6 +585,9 @@ static inline void format_stream_class(char **buf_ch, bool extended, SET_TMP_PREFIX("ehf-pool-"); format_object_pool(buf_ch, extended, prefix, &stream_class->event_header_field_pool); + SET_TMP_PREFIX("pcf-pool-"); + format_object_pool(buf_ch, extended, prefix, + &stream_class->packet_context_field_pool); } static inline void format_writer_stream_class(char **buf_ch, bool extended, @@ -1038,7 +1040,8 @@ static inline void format_notification(char **buf_ch, bool extended, return; } - BUF_APPEND(", %sis-frozen=%d", PRFIELD(notif->frozen)); + BUF_APPEND(", %sis-frozen=%d, %sgraph-addr=%p", + PRFIELD(notif->frozen), PRFIELD(notif->graph)); switch (notif->type) { case BT_NOTIFICATION_TYPE_EVENT: @@ -1240,6 +1243,8 @@ static inline void format_connection(char **buf_ch, bool extended, static inline void format_graph(char **buf_ch, bool extended, const char *prefix, struct bt_graph *graph) { + char tmp_prefix[64]; + BUF_APPEND(", %sis-canceled=%d", PRFIELD(graph->canceled)); if (!extended) { @@ -1255,6 +1260,16 @@ static inline void format_graph(char **buf_ch, bool extended, BUF_APPEND(", %sconn-count=%u", PRFIELD(graph->connections->len)); } + + SET_TMP_PREFIX("en-pool-"); + format_object_pool(buf_ch, extended, prefix, + &graph->event_notif_pool); + SET_TMP_PREFIX("pbn-pool-"); + format_object_pool(buf_ch, extended, prefix, + &graph->packet_begin_notif_pool); + SET_TMP_PREFIX("pen-pool-"); + format_object_pool(buf_ch, extended, prefix, + &graph->packet_end_notif_pool); } static inline void format_notification_iterator(char **buf_ch, diff --git a/plugins/ctf/common/notif-iter/notif-iter.c b/plugins/ctf/common/notif-iter/notif-iter.c index 7128e184..4f295a4d 100644 --- a/plugins/ctf/common/notif-iter/notif-iter.c +++ b/plugins/ctf/common/notif-iter/notif-iter.c @@ -132,6 +132,9 @@ struct bt_notif_iter { /* Visit stack */ struct stack *stack; + /* Current graph to create notifications (weak) */ + struct bt_graph *graph; + /* * Current dynamic scope field pointer. * @@ -1582,8 +1585,10 @@ enum bt_notif_iter_status set_current_event_notification( notit, notit->meta.event_class, bt_event_class_get_name(notit->meta.event_class), notit->packet); - notif = bt_notification_event_create(notit->meta.event_class, - notit->packet, notit->meta.cc_prio_map); + BT_ASSERT(notit->graph); + notif = bt_notification_event_create(notit->graph, + notit->meta.event_class, notit->packet, + notit->meta.cc_prio_map); if (!notif) { BT_LOGE("Cannot create event notification: " "notit-addr=%p, ec-addr=%p, ec-name=\"%s\", " @@ -2759,7 +2764,8 @@ void notify_new_stream(struct bt_notif_iter *notit, } BT_ASSERT(notit->stream); - ret = bt_notification_stream_begin_create(notit->stream); + BT_ASSERT(notit->graph); + ret = bt_notification_stream_begin_create(notit->graph, notit->stream); if (!ret) { BT_LOGE("Cannot create stream beginning notification: " "notit-addr=%p, stream-addr=%p", @@ -2783,7 +2789,8 @@ void notify_end_of_stream(struct bt_notif_iter *notit, return; } - ret = bt_notification_stream_end_create(notit->stream); + BT_ASSERT(notit->graph); + ret = bt_notification_stream_end_create(notit->graph, notit->stream); if (!ret) { BT_LOGE("Cannot create stream beginning notification: " "notit-addr=%p, stream-addr=%p", @@ -2844,7 +2851,9 @@ void notify_new_packet(struct bt_notif_iter *notit, notit->dscopes.stream_packet_context); } - notif = bt_notification_packet_begin_create(notit->packet); + BT_ASSERT(notit->graph); + notif = bt_notification_packet_begin_create(notit->graph, + notit->packet); if (!notif) { BT_LOGE("Cannot create packet beginning notification: " "notit-addr=%p, packet-addr=%p", @@ -2866,7 +2875,8 @@ void notify_end_of_packet(struct bt_notif_iter *notit, return; } - notif = bt_notification_packet_end_create(notit->packet); + BT_ASSERT(notit->graph); + notif = bt_notification_packet_end_create(notit->graph, notit->packet); if (!notif) { BT_LOGE("Cannot create packet end notification: " "notit-addr=%p, packet-addr=%p", @@ -3051,6 +3061,7 @@ void bt_notif_iter_destroy(struct bt_notif_iter *notit) enum bt_notif_iter_status bt_notif_iter_get_next_notification( struct bt_notif_iter *notit, struct bt_clock_class_priority_map *cc_prio_map, + struct bt_graph *graph, struct bt_notification **notification) { int ret; @@ -3059,15 +3070,17 @@ enum bt_notif_iter_status bt_notif_iter_get_next_notification( BT_ASSERT(notit); BT_ASSERT(notification); + if (notit->state == STATE_DONE) { + status = BT_NOTIF_ITER_STATUS_EOF; + goto end; + } + if (cc_prio_map != notit->meta.cc_prio_map) { bt_put(notit->meta.cc_prio_map); notit->meta.cc_prio_map = bt_get(cc_prio_map); } - if (notit->state == STATE_DONE) { - status = BT_NOTIF_ITER_STATUS_EOF; - goto end; - } + notit->graph = graph; BT_LOGV("Getting next notification: notit-addr=%p, cc-prio-map-addr=%p", notit, cc_prio_map); diff --git a/plugins/ctf/common/notif-iter/notif-iter.h b/plugins/ctf/common/notif-iter/notif-iter.h index baaa9cd6..ae9b511a 100644 --- a/plugins/ctf/common/notif-iter/notif-iter.h +++ b/plugins/ctf/common/notif-iter/notif-iter.h @@ -314,6 +314,7 @@ BT_HIDDEN enum bt_notif_iter_status bt_notif_iter_get_next_notification( struct bt_notif_iter *notit, struct bt_clock_class_priority_map *cc_prio_map, + struct bt_graph *graph, struct bt_notification **notification); /** diff --git a/plugins/ctf/fs-src/data-stream-file.c b/plugins/ctf/fs-src/data-stream-file.c index 2b97ca3a..76f5688a 100644 --- a/plugins/ctf/fs-src/data-stream-file.c +++ b/plugins/ctf/fs-src/data-stream-file.c @@ -737,7 +737,7 @@ error: BT_HIDDEN struct ctf_fs_ds_file *ctf_fs_ds_file_create( struct ctf_fs_trace *ctf_fs_trace, - struct bt_notif_iter *notif_iter, + struct bt_graph *graph, struct bt_notif_iter *notif_iter, struct bt_stream *stream, const char *path) { int ret; @@ -748,6 +748,7 @@ struct ctf_fs_ds_file *ctf_fs_ds_file_create( goto error; } + ds_file->graph = graph; ds_file->file = ctf_fs_file_create(); if (!ds_file->file) { goto error; @@ -827,7 +828,8 @@ struct bt_notification_iterator_next_method_return ctf_fs_ds_file_next( }; notif_iter_status = bt_notif_iter_get_next_notification( - ds_file->notif_iter, ds_file->cc_prio_map, &ret.notification); + ds_file->notif_iter, ds_file->cc_prio_map, ds_file->graph, + &ret.notification); switch (notif_iter_status) { case BT_NOTIF_ITER_STATUS_EOF: diff --git a/plugins/ctf/fs-src/data-stream-file.h b/plugins/ctf/fs-src/data-stream-file.h index e1620b9f..e7d8b04a 100644 --- a/plugins/ctf/fs-src/data-stream-file.h +++ b/plugins/ctf/fs-src/data-stream-file.h @@ -85,6 +85,9 @@ struct ctf_fs_ds_file_info { }; struct ctf_fs_ds_file { + /* Weak */ + struct bt_graph *graph; + /* Owned by this */ struct ctf_fs_file *file; @@ -123,6 +126,7 @@ struct ctf_fs_ds_file { BT_HIDDEN struct ctf_fs_ds_file *ctf_fs_ds_file_create( struct ctf_fs_trace *ctf_fs_trace, + struct bt_graph *graph, struct bt_notif_iter *notif_iter, struct bt_stream *stream, const char *path); diff --git a/plugins/ctf/fs-src/fs.c b/plugins/ctf/fs-src/fs.c index 07b4c049..04421d31 100644 --- a/plugins/ctf/fs-src/fs.c +++ b/plugins/ctf/fs-src/fs.c @@ -59,6 +59,7 @@ int notif_iter_data_set_current_ds_file(struct ctf_fs_notif_iter_data *notif_ite ctf_fs_ds_file_destroy(notif_iter_data->ds_file); notif_iter_data->ds_file = ctf_fs_ds_file_create( notif_iter_data->ds_file_group->ctf_fs_trace, + notif_iter_data->graph, notif_iter_data->notif_iter, notif_iter_data->ds_file_group->stream, ds_file_info->path->str); @@ -215,6 +216,8 @@ enum bt_notification_iterator_status ctf_fs_iterator_init( goto error; } + notif_iter_data->graph = bt_component_borrow_graph( + bt_component_borrow_from_private(port_data->ctf_fs->priv_comp)); notif_iter_data->notif_iter = bt_notif_iter_create( port_data->ds_file_group->ctf_fs_trace->metadata->trace, bt_common_get_page_size() * 8, @@ -366,6 +369,7 @@ int create_one_port_for_trace(struct ctf_fs_component *ctf_fs, goto error; } + port_data->ctf_fs = ctf_fs; port_data->ds_file_group = ds_file_group; ret = bt_private_component_source_add_output_private_port( ctf_fs->priv_comp, port_name->str, port_data, NULL); @@ -642,7 +646,7 @@ end: static int add_ds_file_to_ds_file_group(struct ctf_fs_trace *ctf_fs_trace, - const char *path) + struct bt_graph *graph, const char *path) { struct bt_field *packet_header_field = NULL; struct bt_field *packet_context_field = NULL; @@ -664,7 +668,8 @@ int add_ds_file_to_ds_file_group(struct ctf_fs_trace *ctf_fs_trace, goto error; } - ds_file = ctf_fs_ds_file_create(ctf_fs_trace, notif_iter, NULL, path); + ds_file = ctf_fs_ds_file_create(ctf_fs_trace, graph, notif_iter, + NULL, path); if (!ds_file) { goto error; } @@ -784,7 +789,8 @@ end: } static -int create_ds_file_groups(struct ctf_fs_trace *ctf_fs_trace) +int create_ds_file_groups(struct ctf_fs_trace *ctf_fs_trace, + struct bt_graph *graph) { int ret = 0; const char *basename; @@ -849,7 +855,7 @@ int create_ds_file_groups(struct ctf_fs_trace *ctf_fs_trace) continue; } - ret = add_ds_file_to_ds_file_group(ctf_fs_trace, + ret = add_ds_file_to_ds_file_group(ctf_fs_trace, graph, file->path->str); if (ret) { BT_LOGE("Cannot add stream file `%s` to stream file group", @@ -956,7 +962,8 @@ end: BT_HIDDEN struct ctf_fs_trace *ctf_fs_trace_create(const char *path, const char *name, - struct ctf_fs_metadata_config *metadata_config) + struct ctf_fs_metadata_config *metadata_config, + struct bt_graph *graph) { struct ctf_fs_trace *ctf_fs_trace; int ret; @@ -992,7 +999,7 @@ struct ctf_fs_trace *ctf_fs_trace_create(const char *path, const char *name, goto error; } - ret = create_ds_file_groups(ctf_fs_trace); + ret = create_ds_file_groups(ctf_fs_trace, graph); if (ret) { goto error; } @@ -1238,9 +1245,13 @@ int create_ctf_fs_traces(struct ctf_fs_component *ctf_fs, tn_node = g_list_next(tn_node)) { GString *trace_path = tp_node->data; GString *trace_name = tn_node->data; + struct bt_graph *graph = bt_component_borrow_graph( + bt_component_borrow_from_private(ctf_fs->priv_comp)); + BT_ASSERT(graph); ctf_fs_trace = ctf_fs_trace_create(trace_path->str, - trace_name->str, &ctf_fs->metadata_config); + trace_name->str, &ctf_fs->metadata_config, + graph); if (!ctf_fs_trace) { BT_LOGE("Cannot create trace for `%s`.", trace_path->str); diff --git a/plugins/ctf/fs-src/fs.h b/plugins/ctf/fs-src/fs.h index 1124a0f3..b54e4722 100644 --- a/plugins/ctf/fs-src/fs.h +++ b/plugins/ctf/fs-src/fs.h @@ -120,9 +120,15 @@ struct ctf_fs_ds_file_group { struct ctf_fs_port_data { /* Weak, belongs to ctf_fs_trace */ struct ctf_fs_ds_file_group *ds_file_group; + + /* Weak */ + struct ctf_fs_component *ctf_fs; }; struct ctf_fs_notif_iter_data { + /* Weak */ + struct bt_graph *graph; + /* Weak, belongs to ctf_fs_trace */ struct ctf_fs_ds_file_group *ds_file_group; @@ -154,7 +160,7 @@ struct bt_component_class_query_method_return ctf_fs_query( BT_HIDDEN struct ctf_fs_trace *ctf_fs_trace_create(const char *path, const char *name, - struct ctf_fs_metadata_config *config); + struct ctf_fs_metadata_config *config, struct bt_graph *graph); BT_HIDDEN void ctf_fs_trace_destroy(struct ctf_fs_trace *trace); diff --git a/plugins/ctf/fs-src/query.c b/plugins/ctf/fs-src/query.c index a54cbb0d..96bf91ca 100644 --- a/plugins/ctf/fs-src/query.c +++ b/plugins/ctf/fs-src/query.c @@ -381,7 +381,7 @@ int populate_trace_info(const char *trace_path, const char *trace_name, goto end; } - trace = ctf_fs_trace_create(trace_path, trace_name, NULL); + trace = ctf_fs_trace_create(trace_path, trace_name, NULL, NULL); if (!trace) { BT_LOGE("Failed to create fs trace at \'%s\'", trace_path); ret = -1; diff --git a/plugins/text/dmesg/dmesg.c b/plugins/text/dmesg/dmesg.c index 7d208ed3..9f0d9e1c 100644 --- a/plugins/text/dmesg/dmesg.c +++ b/plugins/text/dmesg/dmesg.c @@ -66,6 +66,7 @@ struct dmesg_component { bt_bool no_timestamp; } params; + struct bt_graph *graph; /* Weak */ struct bt_trace *trace; struct bt_stream_class *stream_class; struct bt_event_class *event_class; @@ -546,6 +547,9 @@ enum bt_component_status dmesg_init(struct bt_private_component *priv_comp, goto error; } + dmesg_comp->graph = bt_component_borrow_graph( + bt_component_borrow_from_private(priv_comp)); + BT_ASSERT(dmesg_comp->graph); dmesg_comp->params.path = g_string_new(NULL); if (!dmesg_comp->params.path) { BT_LOGE_STR("Failed to allocate a GString."); @@ -672,8 +676,9 @@ skip_ts: goto error; } - notif = bt_notification_event_create(dmesg_comp->event_class, - dmesg_comp->packet, dmesg_comp->cc_prio_map); + notif = bt_notification_event_create(dmesg_comp->graph, + dmesg_comp->event_class, dmesg_comp->packet, + dmesg_comp->cc_prio_map); if (!notif) { BT_LOGE_STR("Cannot create event notification."); goto error; @@ -957,13 +962,13 @@ handle_state: case STATE_EMIT_STREAM_BEGINNING: BT_ASSERT(dmesg_notif_iter->tmp_event_notif); next_ret.notification = bt_notification_stream_begin_create( - dmesg_comp->stream); + dmesg_comp->graph, dmesg_comp->stream); dmesg_notif_iter->state = STATE_EMIT_PACKET_BEGINNING; break; case STATE_EMIT_PACKET_BEGINNING: BT_ASSERT(dmesg_notif_iter->tmp_event_notif); next_ret.notification = bt_notification_packet_begin_create( - dmesg_comp->packet); + dmesg_comp->graph, dmesg_comp->packet); dmesg_notif_iter->state = STATE_EMIT_EVENT; break; case STATE_EMIT_EVENT: @@ -973,12 +978,12 @@ handle_state: break; case STATE_EMIT_PACKET_END: next_ret.notification = bt_notification_packet_end_create( - dmesg_comp->packet); + dmesg_comp->graph, dmesg_comp->packet); dmesg_notif_iter->state = STATE_EMIT_STREAM_END; break; case STATE_EMIT_STREAM_END: next_ret.notification = bt_notification_stream_end_create( - dmesg_comp->stream); + dmesg_comp->graph, dmesg_comp->stream); dmesg_notif_iter->state = STATE_DONE; break; default: diff --git a/plugins/utils/muxer/muxer.c b/plugins/utils/muxer/muxer.c index b349ce1f..1f87b216 100644 --- a/plugins/utils/muxer/muxer.c +++ b/plugins/utils/muxer/muxer.c @@ -406,7 +406,7 @@ static struct bt_notification_iterator *create_notif_iter_on_input_port( struct bt_private_port *priv_port, int *ret) { - struct bt_port *port = bt_port_from_private(priv_port); + struct bt_port *port = bt_port_borrow_from_private(priv_port); struct bt_notification_iterator *notif_iter = NULL; struct bt_private_connection *priv_conn = NULL; enum bt_connection_status conn_status; @@ -439,7 +439,6 @@ struct bt_notification_iterator *create_notif_iter_on_input_port( port, bt_port_get_name(port), priv_conn, notif_iter); end: - bt_put(port); bt_put(priv_conn); return notif_iter; } @@ -530,7 +529,7 @@ int muxer_notif_iter_handle_newly_connected_ports( } priv_port = node->data; - port = bt_port_from_private(priv_port); + port = bt_port_borrow_from_private(priv_port); BT_ASSERT(port); if (!bt_port_is_connected(port)) { @@ -543,7 +542,6 @@ int muxer_notif_iter_handle_newly_connected_ports( goto remove_node; } - BT_PUT(port); upstream_notif_iter = create_notif_iter_on_input_port(priv_port, &ret); if (ret) { @@ -567,7 +565,6 @@ int muxer_notif_iter_handle_newly_connected_ports( remove_node: bt_put(upstream_notif_iter); - bt_put(port); muxer_notif_iter->newly_connected_priv_ports = g_list_delete_link( muxer_notif_iter->newly_connected_priv_ports, @@ -1159,7 +1156,7 @@ int muxer_notif_iter_init_newly_connected_ports(struct muxer_comp *muxer_comp, * iterator's list of newly connected ports. They will be * handled by muxer_notif_iter_handle_newly_connected_ports(). */ - comp = bt_component_from_private(muxer_comp->priv_comp); + comp = bt_component_borrow_from_private(muxer_comp->priv_comp); BT_ASSERT(comp); count = bt_component_filter_get_input_port_count(comp); if (count < 0) { @@ -1176,7 +1173,7 @@ int muxer_notif_iter_init_newly_connected_ports(struct muxer_comp *muxer_comp, struct bt_port *port; BT_ASSERT(priv_port); - port = bt_port_from_private(priv_port); + port = bt_port_borrow_from_private(priv_port); BT_ASSERT(port); if (!bt_port_is_connected(port)) { @@ -1184,11 +1181,9 @@ int muxer_notif_iter_init_newly_connected_ports(struct muxer_comp *muxer_comp, "muxer-comp-addr=%p, port-addr=%p, port-name\"%s\"", muxer_comp, port, bt_port_get_name(port)); bt_put(priv_port); - bt_put(port); continue; } - bt_put(port); bt_put(priv_port); muxer_notif_iter->newly_connected_priv_ports = g_list_append( @@ -1210,7 +1205,6 @@ int muxer_notif_iter_init_newly_connected_ports(struct muxer_comp *muxer_comp, } end: - bt_put(comp); return ret; } @@ -1397,7 +1391,7 @@ void muxer_port_connected( struct bt_port *other_port) { struct bt_port *self_port = - bt_port_from_private(self_private_port); + bt_port_borrow_from_private(self_private_port); struct muxer_comp *muxer_comp = bt_private_component_get_user_data(priv_comp); size_t i; @@ -1462,14 +1456,14 @@ void muxer_port_connected( } end: - bt_put(self_port); + return; } BT_HIDDEN void muxer_port_disconnected(struct bt_private_component *priv_comp, struct bt_private_port *priv_port) { - struct bt_port *port = bt_port_from_private(priv_port); + struct bt_port *port = bt_port_borrow_from_private(priv_port); struct muxer_comp *muxer_comp = bt_private_component_get_user_data(priv_comp); @@ -1500,6 +1494,4 @@ void muxer_port_disconnected(struct bt_private_component *priv_comp, priv_comp, muxer_comp, port, bt_port_get_name(port), muxer_comp->available_input_ports); } - - bt_put(port); } diff --git a/tests/Makefile.am b/tests/Makefile.am index 88dce23a..05e9439e 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -29,7 +29,6 @@ TESTS_LIB = \ lib/test_ctf_ir_ref \ lib/test_bt_ctf_field_type_validation \ lib/test_ir_visit \ - lib/test_bt_notification_heap \ lib/test_graph_topo \ lib/test_cc_prio_map \ lib/test_bt_notification_iterator diff --git a/tests/lib/Makefile.am b/tests/lib/Makefile.am index 6b7030ee..1ee9fffb 100644 --- a/tests/lib/Makefile.am +++ b/tests/lib/Makefile.am @@ -25,8 +25,6 @@ test_bt_ctf_field_type_validation_LDADD = $(COMMON_TEST_LDADD) test_ir_visit_LDADD = $(COMMON_TEST_LDADD) -test_bt_notification_heap_LDADD = $(COMMON_TEST_LDADD) - test_graph_topo_LDADD = $(COMMON_TEST_LDADD) test_cc_prio_map_LDADD = $(COMMON_TEST_LDADD) @@ -35,8 +33,7 @@ test_bt_notification_iterator_LDADD = $(COMMON_TEST_LDADD) noinst_PROGRAMS = test_bitfield test_ctf_writer test_bt_values \ test_ctf_ir_ref test_bt_ctf_field_type_validation test_ir_visit \ - test_bt_notification_heap test_graph_topo \ - test_cc_prio_map test_bt_notification_iterator + test_graph_topo test_cc_prio_map test_bt_notification_iterator test_bitfield_SOURCES = test_bitfield.c test_ctf_writer_SOURCES = test_ctf_writer.c @@ -44,7 +41,6 @@ test_bt_values_SOURCES = test_bt_values.c test_ctf_ir_ref_SOURCES = test_ctf_ir_ref.c test_bt_ctf_field_type_validation_SOURCES = test_bt_ctf_field_type_validation.c test_ir_visit_SOURCES = test_ir_visit.c -test_bt_notification_heap_SOURCES = test_bt_notification_heap.c test_graph_topo_SOURCES = test_graph_topo.c test_cc_prio_map_SOURCES = test_cc_prio_map.c test_bt_notification_iterator_SOURCES = test_bt_notification_iterator.c diff --git a/tests/lib/test_bt_notification_heap.c b/tests/lib/test_bt_notification_heap.c deleted file mode 100644 index 531ddf68..00000000 --- a/tests/lib/test_bt_notification_heap.c +++ /dev/null @@ -1,199 +0,0 @@ -/* - * test_bt_notification_heap.c - * - * bt_notification_heap tests - * - * Copyright 2016 - Jérémie Galarneau - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; under version 2 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include "tap/tap.h" -#include -#include -#include -#include -#include -#include - -#define NR_TESTS 7 - -struct dummy_notification { - struct bt_notification parent; - uint64_t value; -}; - -static -void dummy_notification_destroy(struct bt_object *obj) -{ - g_free(obj); -} - -/* Reproduced from internal notification.c code. */ -void bt_notification_init(struct bt_notification *notification, - enum bt_notification_type type, - bt_object_release_func release) -{ - assert(type > 0 && type < BT_NOTIFICATION_TYPE_NR); - notification->type = type; - bt_object_init(¬ification->base, release); -} - -static -struct bt_notification *dummy_notification_create(uint64_t value) -{ - struct dummy_notification *notification; - - notification = g_new0(struct dummy_notification, 1); - if (!notification) { - goto error; - } - bt_notification_init(¬ification->parent, - BT_NOTIFICATION_TYPE_NR - 1 /* dummy value */, - dummy_notification_destroy); - notification->value = value; - return ¬ification->parent; -error: - return NULL; -} - -static -bt_bool compare_notifications(struct bt_notification *a, struct bt_notification *b, - void *unused) -{ - uint64_t val_a = ((struct dummy_notification *) a)->value; - uint64_t val_b = ((struct dummy_notification *) b)->value; - - if (val_a == val_b) { - return a < b; - } else { - return val_a < val_b; - } -} - -int main(int argc, char **argv) -{ - int i; - uint64_t last_read_value = 0; - struct bt_notification_heap *heap = NULL; - - /* Initialize tap harness before any tests */ - plan_tests(NR_TESTS); - heap = bt_notification_heap_create(compare_notifications, NULL); - ok(heap, "Created a notification heap"); - - /* Insert 10 000 notifications with random values. */ - for (i = 0; i < 10000; i++) { - int ret; - struct bt_notification *notification = - dummy_notification_create(rand()); - - if (!notification) { - diag("Dummy notification creation failed"); - goto end; - } - - ret = bt_notification_heap_insert(heap, notification); - if (ret) { - diag("Failed to insert notification %i in heap", i); - goto end; - } - bt_put(notification); - } - pass("Inserted 10 000 random notifications in notification heap"); - - /* Pop 5000 notifications, making sure the values read are ascending */ - for (i = 0; i < 5000; i++) { - struct bt_notification *pop_notification; - struct bt_notification *peek_notification; - struct dummy_notification *dummy; - - peek_notification = bt_notification_heap_peek(heap); - if (!peek_notification) { - fail("Failed to peek a notification"); - goto end; - } - - pop_notification = bt_notification_heap_pop(heap); - if (!pop_notification) { - fail("Failed to pop a notification"); - goto end; - } - - if (peek_notification != pop_notification) { - fail("bt_notification_heap_peek and bt_notification_heap_pop do not return the same notification"); - bt_put(peek_notification); - bt_put(pop_notification); - goto end; - } - - dummy = container_of(pop_notification, - struct dummy_notification, parent); - if (dummy->value < last_read_value) { - fail("Notification heap did not provide notifications in ascending order"); - } - last_read_value = dummy->value; - bt_put(peek_notification); - bt_put(pop_notification); - } - - pass("bt_notification_heap_peek and bt_notification_heap_pop return the same notification"); - pass("Notification heap provided 5 000 notifications in ascending order"); - - /* Insert 10 000 notifications with random values. */ - for (i = 0; i < 10000; i++) { - int ret; - struct bt_notification *notification = - dummy_notification_create(rand()); - - if (!notification) { - diag("Dummy notification creation failed"); - goto end; - } - - ret = bt_notification_heap_insert(heap, notification); - if (ret) { - diag("Failed to insert notification %i in heap", i); - goto end; - } - bt_put(notification); - } - pass("Inserted 10 000 random notifications in notification heap after popping"); - - last_read_value = 0; - /* Pop remaining 15 000 notifications, making sure the values read are ascending */ - for (i = 0; i < 15000; i++) { - struct bt_notification *pop_notification; - struct dummy_notification *dummy; - - pop_notification = bt_notification_heap_pop(heap); - if (!pop_notification) { - fail("Failed to pop a notification"); - goto end; - } - dummy = container_of(pop_notification, - struct dummy_notification, parent); - if (dummy->value < last_read_value) { - fail("Notification heap did not provide notifications in ascending order"); - } - last_read_value = dummy->value; - bt_put(pop_notification); - } - pass("Popped remaining 15 000 notifications from heap in ascending order"); - - ok(!bt_notification_heap_peek(heap), "No notifications left in heap"); -end: - bt_put(heap); - return exit_status(); -} diff --git a/tests/lib/test_bt_notification_iterator.c b/tests/lib/test_bt_notification_iterator.c index 8f889fcd..be3f6dd8 100644 --- a/tests/lib/test_bt_notification_iterator.c +++ b/tests/lib/test_bt_notification_iterator.c @@ -87,6 +87,7 @@ struct test_event { static bool debug = false; static enum test current_test; static GArray *test_events; +static struct bt_graph *graph; static struct bt_clock_class_priority_map *src_empty_cc_prio_map; static struct bt_stream_class *src_stream_class; static struct bt_event_class *src_event_class; @@ -421,67 +422,76 @@ struct bt_notification_iterator_next_method_return src_iter_next_seq( break; case SEQ_INACTIVITY: next_return.notification = - bt_notification_inactivity_create(src_empty_cc_prio_map); + bt_notification_inactivity_create(graph, + src_empty_cc_prio_map); assert(next_return.notification); break; case SEQ_STREAM1_BEGIN: next_return.notification = - bt_notification_stream_begin_create(src_stream1); + bt_notification_stream_begin_create(graph, src_stream1); assert(next_return.notification); break; case SEQ_STREAM2_BEGIN: next_return.notification = - bt_notification_stream_begin_create(src_stream2); + bt_notification_stream_begin_create(graph, src_stream2); assert(next_return.notification); break; case SEQ_STREAM1_END: next_return.notification = - bt_notification_stream_end_create(src_stream1); + bt_notification_stream_end_create(graph, src_stream1); assert(next_return.notification); break; case SEQ_STREAM2_END: next_return.notification = - bt_notification_stream_end_create(src_stream2); + bt_notification_stream_end_create(graph, src_stream2); assert(next_return.notification); break; case SEQ_STREAM1_PACKET1_BEGIN: next_return.notification = - bt_notification_packet_begin_create(src_stream1_packet1); + bt_notification_packet_begin_create(graph, + src_stream1_packet1); assert(next_return.notification); break; case SEQ_STREAM1_PACKET2_BEGIN: next_return.notification = - bt_notification_packet_begin_create(src_stream1_packet2); + bt_notification_packet_begin_create(graph, + src_stream1_packet2); assert(next_return.notification); break; case SEQ_STREAM2_PACKET1_BEGIN: next_return.notification = - bt_notification_packet_begin_create(src_stream2_packet1); + bt_notification_packet_begin_create(graph, + src_stream2_packet1); assert(next_return.notification); break; case SEQ_STREAM2_PACKET2_BEGIN: next_return.notification = - bt_notification_packet_begin_create(src_stream2_packet2); + bt_notification_packet_begin_create(graph, + src_stream2_packet2); assert(next_return.notification); break; case SEQ_STREAM1_PACKET1_END: next_return.notification = - bt_notification_packet_end_create(src_stream1_packet1); + bt_notification_packet_end_create(graph, + src_stream1_packet1); assert(next_return.notification); break; case SEQ_STREAM1_PACKET2_END: next_return.notification = - bt_notification_packet_end_create(src_stream1_packet2); + bt_notification_packet_end_create(graph, + src_stream1_packet2); assert(next_return.notification); break; case SEQ_STREAM2_PACKET1_END: next_return.notification = - bt_notification_packet_end_create(src_stream2_packet1); + bt_notification_packet_end_create(graph, + src_stream2_packet1); assert(next_return.notification); break; case SEQ_STREAM2_PACKET2_END: next_return.notification = - bt_notification_packet_end_create(src_stream2_packet2); + bt_notification_packet_end_create(graph, + src_stream2_packet2); assert(next_return.notification); break; case SEQ_EVENT_STREAM1_PACKET1: @@ -502,9 +512,8 @@ struct bt_notification_iterator_next_method_return src_iter_next_seq( if (event_packet) { next_return.notification = - bt_notification_event_create(src_event_class, - event_packet, - src_empty_cc_prio_map); + bt_notification_event_create(graph, src_event_class, + event_packet, src_empty_cc_prio_map); assert(next_return.notification); } @@ -777,12 +786,12 @@ void do_std_test(enum test test, const char *name, struct bt_component *sink_comp; struct bt_port *upstream_port; struct bt_port *downstream_port; - struct bt_graph *graph; enum bt_graph_status graph_status = BT_GRAPH_STATUS_OK; clear_test_events(); current_test = test; diag("test: %s", name); + assert(!graph); graph = bt_graph_create(); assert(graph); create_source_sink(graph, &src_comp, &sink_comp); @@ -813,7 +822,7 @@ void do_std_test(enum test test, const char *name, bt_put(src_comp); bt_put(sink_comp); - bt_put(graph); + BT_PUT(graph); } static @@ -872,11 +881,11 @@ void test_output_port_notification_iterator(void) enum bt_notification_iterator_status iter_status = BT_NOTIFICATION_ITERATOR_STATUS_OK; struct bt_port *upstream_port; - struct bt_graph *graph; clear_test_events(); current_test = TEST_OUTPUT_PORT_NOTIFICATION_ITERATOR; diag("test: output port notification iterator"); + assert(!graph); graph = bt_graph_create(); assert(graph); create_source_sink(graph, &src_comp, NULL); @@ -901,7 +910,7 @@ void test_output_port_notification_iterator(void) "the produced sequence of test events is the expected one"); bt_put(src_comp); - bt_put(graph); + BT_PUT(graph); bt_put(notif_iter); } @@ -911,11 +920,11 @@ void test_output_port_notification_iterator_cannot_consume(void) struct bt_component *src_comp; struct bt_notification_iterator *notif_iter; struct bt_port *upstream_port; - struct bt_graph *graph; clear_test_events(); current_test = TEST_OUTPUT_PORT_NOTIFICATION_ITERATOR; diag("test: cannot consume graph with existing output port notification iterator"); + assert(!graph); graph = bt_graph_create(); assert(graph); create_source_sink(graph, &src_comp, NULL); @@ -935,7 +944,7 @@ void test_output_port_notification_iterator_cannot_consume(void) "bt_graph_run() returns BT_GRAPH_STATUS_CANNOT_CONSUME when there's an output port notification iterator"); bt_put(src_comp); - bt_put(graph); + BT_PUT(graph); bt_put(notif_iter); } diff --git a/tests/lib/test_graph_topo.c b/tests/lib/test_graph_topo.c index e83d6b09..185c6c22 100644 --- a/tests/lib/test_graph_topo.c +++ b/tests/lib/test_graph_topo.c @@ -304,14 +304,12 @@ enum bt_component_status accept_port_connection( struct event event = { .type = COMP_ACCEPT_PORT_CONNECTION, .data.comp_accept_port_connection = { - .comp = bt_component_from_private(private_component), - .self_port = bt_port_from_private(self_private_port), + .comp = bt_component_borrow_from_private(private_component), + .self_port = bt_port_borrow_from_private(self_private_port), .other_port = other_port, }, }; - bt_put(event.data.comp_accept_port_connection.comp); - bt_put(event.data.comp_accept_port_connection.self_port); append_event(&event); return BT_COMPONENT_STATUS_OK; } @@ -326,14 +324,12 @@ void src_port_connected(struct bt_private_component *private_component, struct event event = { .type = COMP_PORT_CONNECTED, .data.comp_port_connected = { - .comp = bt_component_from_private(private_component), - .self_port = bt_port_from_private(self_private_port), + .comp = bt_component_borrow_from_private(private_component), + .self_port = bt_port_borrow_from_private(self_private_port), .other_port = other_port, }, }; - bt_put(event.data.comp_port_connected.comp); - bt_put(event.data.comp_port_connected.self_port); append_event(&event); switch (current_test) { @@ -355,13 +351,11 @@ void src_port_disconnected(struct bt_private_component *private_component, struct event event = { .type = COMP_PORT_DISCONNECTED, .data.comp_port_disconnected = { - .comp = bt_component_from_private(private_component), - .port = bt_port_from_private(private_port), + .comp = bt_component_borrow_from_private(private_component), + .port = bt_port_borrow_from_private(private_port), }, }; - bt_put(event.data.comp_port_disconnected.comp); - bt_put(event.data.comp_port_disconnected.port); append_event(&event); switch (current_test) { @@ -417,14 +411,12 @@ void sink_port_connected(struct bt_private_component *private_component, struct event event = { .type = COMP_PORT_CONNECTED, .data.comp_port_connected = { - .comp = bt_component_from_private(private_component), - .self_port = bt_port_from_private(self_private_port), + .comp = bt_component_borrow_from_private(private_component), + .self_port = bt_port_borrow_from_private(self_private_port), .other_port = other_port, }, }; - bt_put(event.data.comp_port_connected.comp); - bt_put(event.data.comp_port_connected.self_port); append_event(&event); } @@ -435,13 +427,11 @@ void sink_port_disconnected(struct bt_private_component *private_component, struct event event = { .type = COMP_PORT_DISCONNECTED, .data.comp_port_disconnected = { - .comp = bt_component_from_private(private_component), - .port = bt_port_from_private(private_port), + .comp = bt_component_borrow_from_private(private_component), + .port = bt_port_borrow_from_private(private_port), }, }; - bt_put(event.data.comp_port_disconnected.comp); - bt_put(event.data.comp_port_disconnected.port); append_event(&event); } diff --git a/tests/plugins/test-utils-muxer.c b/tests/plugins/test-utils-muxer.c index 27c905c5..c02bbbef 100644 --- a/tests/plugins/test-utils-muxer.c +++ b/tests/plugins/test-utils-muxer.c @@ -72,6 +72,7 @@ struct graph_listener_data { static bool debug = false; static enum test current_test; static GArray *test_events; +static struct bt_graph *graph; static struct bt_clock_class_priority_map *src_cc_prio_map; static struct bt_clock_class_priority_map *src_empty_cc_prio_map; static struct bt_clock_class *src_clock_class; @@ -429,7 +430,7 @@ enum bt_notification_iterator_status src_iter_init( { struct src_iter_user_data *user_data = g_new0(struct src_iter_user_data, 1); - struct bt_port *port = bt_port_from_private(private_port); + struct bt_port *port = bt_port_borrow_from_private(private_port); const char *port_name; int ret; @@ -441,7 +442,6 @@ enum bt_notification_iterator_status src_iter_init( port_name = bt_port_get_name(port); assert(port_name); user_data->iter_index = port_name[3] - '0'; - bt_put(port); switch (user_data->iter_index) { case 0: @@ -515,7 +515,7 @@ struct bt_notification *src_create_event_notif(struct bt_packet *packet, struct bt_clock_value *clock_value; struct bt_field *field; - notif = bt_notification_event_create(src_event_class, + notif = bt_notification_event_create(graph, src_event_class, packet, cc_prio_map); assert(notif); event = bt_notification_event_borrow_event(notif); @@ -557,25 +557,27 @@ struct bt_notification_iterator_next_method_return src_iter_next_seq( break; case SEQ_PACKET_BEGIN: next_return.notification = - bt_notification_packet_begin_create(user_data->packet); + bt_notification_packet_begin_create(graph, + user_data->packet); assert(next_return.notification); break; case SEQ_PACKET_END: next_return.notification = - bt_notification_packet_end_create(user_data->packet); + bt_notification_packet_end_create(graph, + user_data->packet); assert(next_return.notification); break; case SEQ_STREAM_BEGIN: stream = bt_packet_get_stream(user_data->packet); next_return.notification = - bt_notification_stream_begin_create(stream); + bt_notification_stream_begin_create(graph, stream); assert(next_return.notification); bt_put(stream); break; case SEQ_STREAM_END: stream = bt_packet_get_stream(user_data->packet); next_return.notification = - bt_notification_stream_end_create(stream); + bt_notification_stream_end_create(graph, stream); assert(next_return.notification); bt_put(stream); break; @@ -620,13 +622,13 @@ struct bt_notification_iterator_next_method_return src_iter_next( stream = bt_packet_get_stream(user_data->packet); next_return.notification = bt_notification_stream_begin_create( - stream); + graph, stream); bt_put(stream); assert(next_return.notification); } else if (user_data->at == 1) { next_return.notification = bt_notification_packet_begin_create( - user_data->packet); + graph, user_data->packet); assert(next_return.notification); } else if (user_data->at < 7) { next_return.notification = @@ -637,13 +639,13 @@ struct bt_notification_iterator_next_method_return src_iter_next( } else if (user_data->at == 7) { next_return.notification = bt_notification_packet_end_create( - user_data->packet); + graph, user_data->packet); assert(next_return.notification); } else if (user_data->at == 8) { stream = bt_packet_get_stream(user_data->packet); next_return.notification = bt_notification_stream_end_create( - stream); + graph, stream); bt_put(stream); assert(next_return.notification); } else { @@ -991,7 +993,6 @@ void do_std_test(enum test test, const char *name, struct bt_component *sink_comp; struct bt_port *upstream_port; struct bt_port *downstream_port; - struct bt_graph *graph; int64_t i; int64_t count; enum bt_graph_status graph_status = BT_GRAPH_STATUS_OK; @@ -999,6 +1000,7 @@ void do_std_test(enum test test, const char *name, clear_test_events(); current_test = test; diag("test: %s", name); + assert(!graph); graph = bt_graph_create(); assert(graph); create_source_muxer_sink(graph, &src_comp, &muxer_comp, &sink_comp); @@ -1047,7 +1049,7 @@ void do_std_test(enum test test, const char *name, bt_put(src_comp); bt_put(muxer_comp); bt_put(sink_comp); - bt_put(graph); + BT_PUT(graph); } static @@ -1406,7 +1408,6 @@ void test_single_end_then_multiple_full(void) struct bt_component *sink_comp; struct bt_port *upstream_port; struct bt_port *downstream_port; - struct bt_graph *graph; int64_t i; int64_t count; int ret; @@ -1473,6 +1474,7 @@ void test_single_end_then_multiple_full(void) clear_test_events(); current_test = TEST_SINGLE_END_THEN_MULTIPLE_FULL; diag("test: single end then multiple full"); + assert(!graph); graph = bt_graph_create(); assert(graph); create_source_muxer_sink(graph, &src_comp, &muxer_comp, &sink_comp); @@ -1522,7 +1524,7 @@ void test_single_end_then_multiple_full(void) bt_put(src_comp); bt_put(muxer_comp); bt_put(sink_comp); - bt_put(graph); + BT_PUT(graph); } static @@ -1533,7 +1535,6 @@ void test_single_again_end_then_multiple_full(void) struct bt_component *sink_comp; struct bt_port *upstream_port; struct bt_port *downstream_port; - struct bt_graph *graph; int64_t i; int64_t count; int ret; @@ -1601,6 +1602,7 @@ void test_single_again_end_then_multiple_full(void) clear_test_events(); current_test = TEST_SINGLE_AGAIN_END_THEN_MULTIPLE_FULL; diag("test: single again then end then multiple full"); + assert(!graph); graph = bt_graph_create(); assert(graph); create_source_muxer_sink(graph, &src_comp, &muxer_comp, &sink_comp); @@ -1650,7 +1652,7 @@ void test_single_again_end_then_multiple_full(void) bt_put(src_comp); bt_put(muxer_comp); bt_put(sink_comp); - bt_put(graph); + BT_PUT(graph); } #define DEBUG_ENV_VAR "TEST_UTILS_MUXER_DEBUG" -- 2.34.1