X-Git-Url: https://git.efficios.com/?a=blobdiff_plain;f=src%2Fplugins%2Fctf%2Ffs-sink%2Ffs-sink.c;h=a0c0e5bbe930768ff9879f8d5e70beff59d88bb1;hb=4175c1d52f91f7e5d66a12135ad8ec6ec736a539;hp=7fabc65c1e3b84f5a2b6256612f9986f7a657af8;hpb=fb25b9e364c8eab9fe5e37947831e233086c7218;p=babeltrace.git diff --git a/src/plugins/ctf/fs-sink/fs-sink.c b/src/plugins/ctf/fs-sink/fs-sink.c index 7fabc65c..a0c0e5bb 100644 --- a/src/plugins/ctf/fs-sink/fs-sink.c +++ b/src/plugins/ctf/fs-sink/fs-sink.c @@ -23,7 +23,7 @@ #define BT_COMP_LOG_SELF_COMP (fs_sink->self_comp) #define BT_LOG_OUTPUT_LEVEL (fs_sink->log_level) #define BT_LOG_TAG "PLUGIN/SINK.CTF.FS" -#include "plugins/comp-logging.h" +#include "logging/comp-logging.h" #include #include @@ -43,11 +43,11 @@ static const char * const in_port_name = "in"; static -bt_component_class_init_method_status ensure_output_dir_exists( +bt_component_class_initialize_method_status ensure_output_dir_exists( struct fs_sink_comp *fs_sink) { - bt_component_class_init_method_status status = - BT_COMPONENT_CLASS_INIT_METHOD_STATUS_OK; + bt_component_class_initialize_method_status status = + BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK; int ret; ret = g_mkdir_with_parents(fs_sink->output_dir_path->str, 0755); @@ -56,7 +56,7 @@ bt_component_class_init_method_status ensure_output_dir_exists( "Cannot create directories for output directory", ": output-dir-path=\"%s\"", fs_sink->output_dir_path->str); - status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_ERROR; + status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR; goto end; } @@ -65,24 +65,24 @@ end: } static -bt_component_class_init_method_status +bt_component_class_initialize_method_status configure_component(struct fs_sink_comp *fs_sink, const bt_value *params) { - bt_component_class_init_method_status status = - BT_COMPONENT_CLASS_INIT_METHOD_STATUS_OK; + bt_component_class_initialize_method_status status = + BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK; const bt_value *value; value = bt_value_map_borrow_entry_value_const(params, "path"); if (!value) { BT_COMP_LOGE_STR("Missing mandatory `path` parameter."); - status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_ERROR; + status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR; goto end; } if (!bt_value_is_string(value)) { BT_COMP_LOGE_STR("`path` parameter: expecting a string."); - status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_ERROR; + status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR; goto end; } @@ -93,7 +93,7 @@ configure_component(struct fs_sink_comp *fs_sink, if (value) { if (!bt_value_is_bool(value)) { BT_COMP_LOGE_STR("`assume-single-trace` parameter: expecting a boolean."); - status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_ERROR; + status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR; goto end; } @@ -105,7 +105,7 @@ configure_component(struct fs_sink_comp *fs_sink, if (value) { if (!bt_value_is_bool(value)) { BT_COMP_LOGE_STR("`ignore-discarded-events` parameter: expecting a boolean."); - status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_ERROR; + status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR; goto end; } @@ -118,7 +118,7 @@ configure_component(struct fs_sink_comp *fs_sink, if (value) { if (!bt_value_is_bool(value)) { BT_COMP_LOGE_STR("`ignore-discarded-packets` parameter: expecting a boolean."); - status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_ERROR; + status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR; goto end; } @@ -131,7 +131,7 @@ configure_component(struct fs_sink_comp *fs_sink, if (value) { if (!bt_value_is_bool(value)) { BT_COMP_LOGE_STR("`quiet` parameter: expecting a boolean."); - status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_ERROR; + status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR; goto end; } @@ -168,12 +168,14 @@ end: } BT_HIDDEN -bt_component_class_init_method_status ctf_fs_sink_init( - bt_self_component_sink *self_comp_sink, const bt_value *params, +bt_component_class_initialize_method_status ctf_fs_sink_init( + bt_self_component_sink *self_comp_sink, + bt_self_component_sink_configuration *config, + const bt_value *params, void *init_method_data) { - bt_component_class_init_method_status status = - BT_COMPONENT_CLASS_INIT_METHOD_STATUS_OK; + bt_component_class_initialize_method_status status = + BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK; bt_self_component_add_port_status add_port_status; struct fs_sink_comp *fs_sink = NULL; bt_self_component *self_comp = @@ -185,7 +187,7 @@ bt_component_class_init_method_status ctf_fs_sink_init( if (!fs_sink) { BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR, log_level, self_comp, "Failed to allocate one CTF FS sink structure."); - status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_MEMORY_ERROR; + status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR; goto end; } @@ -193,7 +195,7 @@ bt_component_class_init_method_status ctf_fs_sink_init( fs_sink->self_comp = self_comp; fs_sink->output_dir_path = g_string_new(NULL); status = configure_component(fs_sink, params); - if (status != BT_COMPONENT_CLASS_INIT_METHOD_STATUS_OK) { + if (status != BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK) { /* configure_component() logs errors */ goto end; } @@ -203,12 +205,12 @@ bt_component_class_init_method_status ctf_fs_sink_init( G_FILE_TEST_EXISTS)) { BT_COMP_LOGE("Single trace mode, but output path exists: " "output-path=\"%s\"", fs_sink->output_dir_path->str); - status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_ERROR; + status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR; goto end; } status = ensure_output_dir_exists(fs_sink); - if (status != BT_COMPONENT_CLASS_INIT_METHOD_STATUS_OK) { + if (status != BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK) { /* ensure_output_dir_exists() logs errors */ goto end; } @@ -217,7 +219,7 @@ bt_component_class_init_method_status ctf_fs_sink_init( NULL, (GDestroyNotify) fs_sink_trace_destroy); if (!fs_sink->traces) { BT_COMP_LOGE_STR("Failed to allocate one GHashTable."); - status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_MEMORY_ERROR; + status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR; goto end; } @@ -225,10 +227,10 @@ bt_component_class_init_method_status ctf_fs_sink_init( self_comp_sink, in_port_name, NULL, NULL); switch (add_port_status) { case BT_SELF_COMPONENT_ADD_PORT_STATUS_ERROR: - status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_ERROR; + status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR; goto end; case BT_SELF_COMPONENT_ADD_PORT_STATUS_MEMORY_ERROR: - status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_MEMORY_ERROR; + status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR; goto end; default: break; @@ -237,7 +239,7 @@ bt_component_class_init_method_status ctf_fs_sink_init( bt_self_component_set_data(self_comp, fs_sink); end: - if (status != BT_COMPONENT_CLASS_INIT_METHOD_STATUS_OK) { + if (status != BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK) { destroy_fs_sink_comp(fs_sink); } @@ -313,6 +315,42 @@ bt_component_class_sink_consume_method_status handle_event_msg( msg); } + /* + * If this event's stream does not support packets, then we + * lazily create artificial packets. + * + * The size of an artificial packet is arbitrarily at least + * 4 MiB (it usually is greater because we close it when + * comes the time to write a new event and the packet's content + * size is >= 4 MiB), except the last one which can be smaller. + */ + if (G_UNLIKELY(!stream->sc->has_packets)) { + if (stream->packet_state.is_open && + bt_ctfser_get_offset_in_current_packet_bits(&stream->ctfser) / 8 >= + 4 * 1024 * 1024) { + /* + * Stream's current packet is larger than 4 MiB: + * close it. A new packet will be opened just + * below. + */ + ret = fs_sink_stream_close_packet(stream, NULL); + if (ret) { + status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR; + goto end; + } + } + + if (!stream->packet_state.is_open) { + /* Stream's packet is not currently opened: open it */ + ret = fs_sink_stream_open_packet(stream, NULL, NULL); + if (ret) { + status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR; + goto end; + } + } + } + + BT_ASSERT(stream->packet_state.is_open); ret = fs_sink_stream_write_event(stream, cs, ir_event, ec); if (G_UNLIKELY(ret)) { status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR; @@ -616,6 +654,29 @@ bt_component_class_sink_consume_method_status handle_stream_beginning_msg( bt_stream_class_packets_have_beginning_default_clock_snapshot(ir_sc) && bt_stream_class_packets_have_end_default_clock_snapshot(ir_sc); + /* + * Not supported: discarded events or discarded packets support + * without packets support. Packets are the way to know where + * discarded events/packets occured in CTF 1.8. + */ + if (!bt_stream_class_supports_packets(ir_sc)) { + BT_ASSERT(!bt_stream_class_supports_discarded_packets(ir_sc)); + + if (!fs_sink->ignore_discarded_events && + bt_stream_class_supports_discarded_events(ir_sc)) { + BT_COMP_LOGE("Unsupported stream: " + "stream does not support packets, " + "but supports discarded events: " + "stream-addr=%p, " + "stream-id=%" PRIu64 ", " + "stream-name=\"%s\"", + ir_stream, bt_stream_get_id(ir_stream), + bt_stream_get_name(ir_stream)); + status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR; + goto end; + } + } + /* * Not supported: discarded events with default clock snapshots, * but packet beginning/end without default clock snapshot. @@ -688,6 +749,17 @@ bt_component_class_sink_consume_method_status handle_stream_end_msg( goto end; } + if (G_UNLIKELY(!stream->sc->has_packets && + stream->packet_state.is_open)) { + /* Close stream's current artificial packet */ + int ret = fs_sink_stream_close_packet(stream, NULL); + + if (ret) { + status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR; + goto end; + } + } + BT_COMP_LOGI("Closing stream file: " "stream-id=%" PRIu64 ", stream-name=\"%s\", " "trace-name=\"%s\", path=\"%s/%s\"", @@ -972,11 +1044,6 @@ bt_component_class_sink_consume_method_status ctf_fs_sink_consume( status = handle_stream_end_msg( fs_sink, msg); break; - case BT_MESSAGE_TYPE_STREAM_ACTIVITY_BEGINNING: - case BT_MESSAGE_TYPE_STREAM_ACTIVITY_END: - /* Not supported by CTF 1.8 */ - BT_COMP_LOGD_STR("Ignoring stream activity message."); - break; case BT_MESSAGE_TYPE_DISCARDED_EVENTS: status = handle_discarded_events_msg( fs_sink, msg); @@ -1030,23 +1097,27 @@ end: } BT_HIDDEN -bt_component_class_sink_graph_is_configured_method_status ctf_fs_sink_graph_is_configured( +bt_component_class_sink_graph_is_configured_method_status +ctf_fs_sink_graph_is_configured( bt_self_component_sink *self_comp) { - bt_component_class_sink_graph_is_configured_method_status status = - BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_OK; + bt_component_class_sink_graph_is_configured_method_status status; + bt_self_component_port_input_message_iterator_create_from_sink_component_status + msg_iter_status; struct fs_sink_comp *fs_sink = bt_self_component_get_data( bt_self_component_sink_as_self_component(self_comp)); - fs_sink->upstream_iter = - bt_self_component_port_input_message_iterator_create( + msg_iter_status = + bt_self_component_port_input_message_iterator_create_from_sink_component( + self_comp, bt_self_component_sink_borrow_input_port_by_name( - self_comp, in_port_name)); - if (!fs_sink->upstream_iter) { - status = BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_ERROR; + self_comp, in_port_name), &fs_sink->upstream_iter); + if (msg_iter_status != BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_CREATE_FROM_SINK_COMPONENT_STATUS_OK) { + status = (int) msg_iter_status; goto end; } + status = BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_OK; end: return status; }