X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=lib%2Fgraph%2Fnotification%2Fevent.c;h=3ed1c4cd0f6b6d351619bbdcd2497755c72d4c8b;hb=5c5632787fc9cafa602c89a28966bcfd01ec0204;hp=8e5d672493d8482f41a34d6ba96d90483d7a2e8e;hpb=c55a9f585da53ea54ac458155fac3cdec1779d47;p=babeltrace.git diff --git a/lib/graph/notification/event.c b/lib/graph/notification/event.c index 8e5d6724..3ed1c4cd 100644 --- a/lib/graph/notification/event.c +++ b/lib/graph/notification/event.c @@ -24,168 +24,191 @@ * SOFTWARE. */ +#define BT_LOG_TAG "NOTIF-EVENT" +#include + #include #include #include #include #include #include +#include #include #include #include #include +#include +#include +#include +#include -static -void bt_notification_event_destroy(struct bt_object *obj) +BT_ASSERT_PRE_FUNC +static inline bool event_class_has_trace(struct bt_event_class *event_class) { - struct bt_notification_event *notification = - (struct bt_notification_event *) obj; + struct bt_stream_class *stream_class; - BT_PUT(notification->event); - BT_PUT(notification->cc_prio_map); - g_free(notification); + stream_class = bt_event_class_borrow_stream_class(event_class); + BT_ASSERT(stream_class); + return bt_stream_class_borrow_trace(stream_class) != NULL; } -static -bt_bool validate_clock_classes(struct bt_notification_event *notif) +BT_HIDDEN +struct bt_notification *bt_notification_event_new(struct bt_graph *graph) { - /* - * For each clock class found in the notification's clock class - * priority map, make sure the event has a clock value set for - * this clock class. Also make sure that those clock classes - * are part of the trace to which the event belongs. - */ - bt_bool is_valid = BT_TRUE; - int trace_cc_count; - int cc_prio_map_cc_count; - size_t cc_prio_map_cc_i, trace_cc_i; - struct bt_ctf_event_class *event_class = NULL; - struct bt_ctf_stream_class *stream_class = NULL; - struct bt_ctf_trace *trace = NULL; - - event_class = bt_ctf_event_borrow_event_class(notif->event); - assert(event_class); - stream_class = bt_ctf_event_class_borrow_stream_class(event_class); - assert(stream_class); - trace = bt_ctf_stream_class_borrow_trace(stream_class); - assert(trace); - trace_cc_count = bt_ctf_trace_get_clock_class_count(trace); - assert(trace_cc_count >= 0); - cc_prio_map_cc_count = - bt_clock_class_priority_map_get_clock_class_count( - notif->cc_prio_map); - assert(cc_prio_map_cc_count >= 0); - - for (cc_prio_map_cc_i = 0; cc_prio_map_cc_i < cc_prio_map_cc_count; - cc_prio_map_cc_i++) { - struct bt_ctf_clock_class *clock_class = - bt_clock_class_priority_map_get_clock_class_by_index( - notif->cc_prio_map, cc_prio_map_cc_i); - struct bt_ctf_clock_value *clock_value; - bt_bool found_in_trace = BT_FALSE; - - assert(clock_class); - clock_value = bt_ctf_event_get_clock_value(notif->event, - clock_class); - if (!clock_value) { - is_valid = BT_FALSE; - goto end; - } - - bt_put(clock_value); - - for (trace_cc_i = 0; trace_cc_i < trace_cc_count; - trace_cc_i++) { - struct bt_ctf_clock_class *trace_clock_class = - bt_ctf_trace_get_clock_class_by_index(trace, - trace_cc_i); - - assert(trace_clock_class); + struct bt_notification_event *notification = NULL; - if (trace_clock_class == clock_class) { - found_in_trace = BT_TRUE; - break; - } - } + notification = g_new0(struct bt_notification_event, 1); + if (!notification) { + BT_LOGE_STR("Failed to allocate one event notification."); + goto error; + } - bt_put(clock_class); + bt_notification_init(¬ification->parent, BT_NOTIFICATION_TYPE_EVENT, + (bt_object_release_func) bt_notification_event_recycle, graph); + goto end; - if (!found_in_trace) { - is_valid = BT_FALSE; - goto end; - } - } +error: + BT_PUT(notification); end: - return is_valid; + return (void *) notification; } -struct bt_notification *bt_notification_event_create(struct bt_ctf_event *event, +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) { struct bt_notification_event *notification = NULL; - if (!event || !cc_prio_map) { - goto error; - } - - if (!bt_ctf_event_borrow_packet(event)) { - goto error; + BT_ASSERT_PRE_NON_NULL(event_class, "Event class"); + BT_ASSERT_PRE_NON_NULL(packet, "Packet"); + + if (cc_prio_map) { + /* Function's reference, released at the end */ + bt_get(cc_prio_map); + } else { + cc_prio_map = bt_clock_class_priority_map_create(); + if (!cc_prio_map) { + BT_LOGE_STR("Cannot create empty clock class priority map."); + goto error; + } } - notification = g_new0(struct bt_notification_event, 1); + BT_ASSERT(cc_prio_map); + BT_LOGD("Creating event notification object: " + "event-class-addr=%p, " + "event-class-name=\"%s\", event-class-id=%" PRId64 ", " + "cc-prio-map-addr=%p", + event_class, + bt_event_class_get_name(event_class), + bt_event_class_get_id(event_class), cc_prio_map); + + BT_ASSERT_PRE(event_class_has_trace(event_class), + "Event class is not part of a trace: %!+E", event_class); + notification = (void *) bt_notification_create_from_pool( + &graph->event_notif_pool, graph); if (!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_get(event); - notification->cc_prio_map = bt_get(cc_prio_map); - if (!validate_clock_classes(notification)) { + + notification->event = bt_event_create(event_class, packet); + if (!notification->event) { + BT_LIB_LOGE("Cannot create event from event class: " + "%![event-class-]+E", event_class); goto error; } - bt_ctf_event_freeze(notification->event); + notification->cc_prio_map = bt_get(cc_prio_map); + BT_LOGD_STR("Freezing event notification's clock class priority map."); bt_clock_class_priority_map_freeze(notification->cc_prio_map); - return ¬ification->parent; + BT_LOGD("Created event notification object: " + "event-addr=%p, event-class-addr=%p, " + "event-class-name=\"%s\", event-class-id=%" PRId64 ", " + "cc-prio-map-addr=%p, notif-addr=%p", + notification->event, event_class, + bt_event_class_get_name(event_class), + bt_event_class_get_id(event_class), cc_prio_map, + notification); + goto end; + error: - bt_put(notification); - return NULL; + BT_PUT(notification); + +end: + bt_put(cc_prio_map); + 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_ctf_event *bt_notification_event_get_event( +struct bt_event *bt_notification_event_borrow_event( struct bt_notification *notification) { - struct bt_ctf_event *event = NULL; struct bt_notification_event *event_notification; - if (bt_notification_get_type(notification) != - BT_NOTIFICATION_TYPE_EVENT) { - goto end; - } + BT_ASSERT_PRE_NON_NULL(notification, "Notification"); + BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, BT_NOTIFICATION_TYPE_EVENT); event_notification = container_of(notification, struct bt_notification_event, parent); - event = bt_get(event_notification->event); -end: - return event; + return event_notification->event; } extern struct bt_clock_class_priority_map * -bt_notification_event_get_clock_class_priority_map( +bt_notification_event_borrow_clock_class_priority_map( struct bt_notification *notification) { - struct bt_clock_class_priority_map *cc_prio_map = NULL; struct bt_notification_event *event_notification; - if (bt_notification_get_type(notification) != - BT_NOTIFICATION_TYPE_EVENT) { - goto end; - } - + BT_ASSERT_PRE_NON_NULL(notification, "Notification"); + BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, BT_NOTIFICATION_TYPE_EVENT); event_notification = container_of(notification, struct bt_notification_event, parent); - cc_prio_map = bt_get(event_notification->cc_prio_map); -end: - return cc_prio_map; + return event_notification->cc_prio_map; }