X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=plugins%2Ftext%2Fdmesg%2Fdmesg.c;h=b10c94252201c2a040bb22e932ce2475411fd5d9;hb=68b66a256a54d32992dfefeaad11eea88b7df234;hp=c85eb16a54a83fa2aceb0a417d560d47d5f31777;hpb=d6e69534ef08a2dd8bff9eb5af1eab63736b3d31;p=babeltrace.git diff --git a/plugins/text/dmesg/dmesg.c b/plugins/text/dmesg/dmesg.c index c85eb16a..b10c9425 100644 --- a/plugins/text/dmesg/dmesg.c +++ b/plugins/text/dmesg/dmesg.c @@ -28,12 +28,12 @@ #include #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include #define NSEC_PER_USEC 1000UL @@ -50,12 +50,15 @@ struct dmesg_msg_iter { size_t linebuf_len; FILE *fp; bt_message *tmp_event_msg; + uint64_t last_clock_value; enum { STATE_EMIT_STREAM_BEGINNING, + STATE_EMIT_STREAM_ACTIVITY_BEGINNING, STATE_EMIT_PACKET_BEGINNING, STATE_EMIT_EVENT, STATE_EMIT_PACKET_END, + STATE_EMIT_STREAM_ACTIVITY_END, STATE_EMIT_STREAM_END, STATE_DONE, } state; @@ -68,6 +71,7 @@ struct dmesg_component { bt_bool no_timestamp; } params; + bt_self_component_source *self_comp; bt_trace_class *trace_class; bt_stream_class *stream_class; bt_event_class *event_class; @@ -78,19 +82,19 @@ struct dmesg_component { }; static -bt_field_class *create_event_payload_fc(void) +bt_field_class *create_event_payload_fc(bt_trace_class *trace_class) { bt_field_class *root_fc = NULL; bt_field_class *fc = NULL; int ret; - root_fc = bt_field_class_structure_create(); + root_fc = bt_field_class_structure_create(trace_class); if (!root_fc) { BT_LOGE_STR("Cannot create an empty structure field class object."); goto error; } - fc = bt_field_class_string_create(); + fc = bt_field_class_string_create(trace_class); if (!fc) { BT_LOGE_STR("Cannot create a string field class object."); goto error; @@ -120,7 +124,9 @@ int create_meta(struct dmesg_component *dmesg_comp, bool has_ts) bt_field_class *fc = NULL; int ret = 0; - dmesg_comp->trace_class = bt_trace_class_create(); + dmesg_comp->trace_class = bt_trace_class_create( + bt_self_component_source_as_self_component( + dmesg_comp->self_comp)); if (!dmesg_comp->trace_class) { BT_LOGE_STR("Cannot create an empty trace class object."); goto error; @@ -134,18 +140,32 @@ int create_meta(struct dmesg_component *dmesg_comp, bool has_ts) } if (has_ts) { - dmesg_comp->clock_class = bt_clock_class_create(); + dmesg_comp->clock_class = bt_clock_class_create( + bt_self_component_source_as_self_component( + dmesg_comp->self_comp)); if (!dmesg_comp->clock_class) { BT_LOGE_STR("Cannot create clock class."); goto error; } + /* + * The `dmesg` timestamp's origin is not the Unix epoch, + * it's the boot time. + */ + bt_clock_class_set_origin_is_unix_epoch(dmesg_comp->clock_class, + BT_FALSE); + ret = bt_stream_class_set_default_clock_class( dmesg_comp->stream_class, dmesg_comp->clock_class); if (ret) { BT_LOGE_STR("Cannot set stream class's default clock class."); goto error; } + + bt_stream_class_set_packets_have_beginning_default_clock_snapshot( + dmesg_comp->stream_class, BT_TRUE); + bt_stream_class_set_packets_have_end_default_clock_snapshot( + dmesg_comp->stream_class, BT_TRUE); } dmesg_comp->event_class = bt_event_class_create( @@ -161,7 +181,7 @@ int create_meta(struct dmesg_component *dmesg_comp, bool has_ts) goto error; } - fc = create_event_payload_fc(); + fc = create_event_payload_fc(dmesg_comp->trace_class); if (!fc) { BT_LOGE_STR("Cannot create event payload field class."); goto error; @@ -241,7 +261,7 @@ static int create_packet_and_stream_and_trace(struct dmesg_component *dmesg_comp) { int ret = 0; - const char *trace_name; + const char *trace_name = NULL; gchar *basename = NULL; dmesg_comp->trace = bt_trace_create(dmesg_comp->trace_class); @@ -284,12 +304,6 @@ int create_packet_and_stream_and_trace(struct dmesg_component *dmesg_comp) goto error; } - ret = bt_trace_make_static(dmesg_comp->trace); - if (ret) { - BT_LOGE_STR("Cannot make trace static."); - goto error; - } - goto end; error: @@ -354,11 +368,12 @@ void destroy_dmesg_component(struct dmesg_component *dmesg_comp) bt_event_class_put_ref(dmesg_comp->event_class); bt_stream_put_ref(dmesg_comp->stream); bt_clock_class_put_ref(dmesg_comp->clock_class); + bt_trace_class_put_ref(dmesg_comp->trace_class); g_free(dmesg_comp); } static -enum bt_self_component_status create_port( +bt_self_component_status create_port( bt_self_component_source *self_comp) { return bt_self_component_source_add_output_port(self_comp, @@ -366,19 +381,20 @@ enum bt_self_component_status create_port( } BT_HIDDEN -enum bt_self_component_status dmesg_init( +bt_self_component_status dmesg_init( bt_self_component_source *self_comp, bt_value *params, void *init_method_data) { int ret = 0; struct dmesg_component *dmesg_comp = g_new0(struct dmesg_component, 1); - enum bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK; + bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK; if (!dmesg_comp) { BT_LOGE_STR("Failed to allocate one dmesg component structure."); goto error; } + dmesg_comp->self_comp = self_comp; dmesg_comp->params.path = g_string_new(NULL); if (!dmesg_comp->params.path) { BT_LOGE_STR("Failed to allocate a GString."); @@ -507,8 +523,16 @@ skip_ts: goto error; } - msg = bt_message_event_create(msg_iter->pc_msg_iter, - dmesg_comp->event_class, dmesg_comp->packet); + if (dmesg_comp->clock_class) { + msg = bt_message_event_create_with_default_clock_snapshot( + msg_iter->pc_msg_iter, + dmesg_comp->event_class, dmesg_comp->packet, ts); + msg_iter->last_clock_value = ts; + } else { + msg = bt_message_event_create(msg_iter->pc_msg_iter, + dmesg_comp->event_class, dmesg_comp->packet); + } + if (!msg) { BT_LOGE_STR("Cannot create event message."); goto error; @@ -516,11 +540,6 @@ skip_ts: event = bt_message_event_borrow_event(msg); BT_ASSERT(event); - - if (dmesg_comp->clock_class) { - bt_event_set_default_clock_value(event, ts); - } - goto end; error: @@ -628,8 +647,10 @@ void destroy_dmesg_msg_iter(struct dmesg_msg_iter *dmesg_msg_iter) g_free(dmesg_msg_iter); } + + BT_HIDDEN -enum bt_self_message_iterator_status dmesg_msg_iter_init( +bt_self_message_iterator_status dmesg_msg_iter_init( bt_self_message_iterator *self_msg_iter, bt_self_component_source *self_comp, bt_self_component_port_output *self_port) @@ -637,7 +658,7 @@ enum bt_self_message_iterator_status dmesg_msg_iter_init( struct dmesg_component *dmesg_comp; struct dmesg_msg_iter *dmesg_msg_iter = g_new0(struct dmesg_msg_iter, 1); - enum bt_self_message_iterator_status status = + bt_self_message_iterator_status status = BT_SELF_MESSAGE_ITERATOR_STATUS_OK; if (!dmesg_msg_iter) { @@ -686,13 +707,13 @@ void dmesg_msg_iter_finalize( } static -enum bt_self_message_iterator_status dmesg_msg_iter_next_one( +bt_self_message_iterator_status dmesg_msg_iter_next_one( struct dmesg_msg_iter *dmesg_msg_iter, bt_message **msg) { ssize_t len; struct dmesg_component *dmesg_comp; - enum bt_self_message_iterator_status status = + bt_self_message_iterator_status status = BT_SELF_MESSAGE_ITERATOR_STATUS_OK; BT_ASSERT(dmesg_msg_iter); @@ -706,6 +727,7 @@ enum bt_self_message_iterator_status dmesg_msg_iter_next_one( if (dmesg_msg_iter->tmp_event_msg || dmesg_msg_iter->state == STATE_EMIT_PACKET_END || + dmesg_msg_iter->state == STATE_EMIT_STREAM_ACTIVITY_END || dmesg_msg_iter->state == STATE_EMIT_STREAM_END) { goto handle_state; } @@ -770,12 +792,26 @@ handle_state: BT_ASSERT(dmesg_msg_iter->tmp_event_msg); *msg = bt_message_stream_beginning_create( dmesg_msg_iter->pc_msg_iter, dmesg_comp->stream); + dmesg_msg_iter->state = STATE_EMIT_STREAM_ACTIVITY_BEGINNING; + break; + case STATE_EMIT_STREAM_ACTIVITY_BEGINNING: + BT_ASSERT(dmesg_msg_iter->tmp_event_msg); + *msg = bt_message_stream_activity_beginning_create( + dmesg_msg_iter->pc_msg_iter, dmesg_comp->stream); dmesg_msg_iter->state = STATE_EMIT_PACKET_BEGINNING; break; case STATE_EMIT_PACKET_BEGINNING: BT_ASSERT(dmesg_msg_iter->tmp_event_msg); - *msg = bt_message_packet_beginning_create( - dmesg_msg_iter->pc_msg_iter, dmesg_comp->packet); + + if (dmesg_comp->clock_class) { + *msg = bt_message_packet_beginning_create_with_default_clock_snapshot( + dmesg_msg_iter->pc_msg_iter, dmesg_comp->packet, + dmesg_msg_iter->last_clock_value); + } else { + *msg = bt_message_packet_beginning_create( + dmesg_msg_iter->pc_msg_iter, dmesg_comp->packet); + } + dmesg_msg_iter->state = STATE_EMIT_EVENT; break; case STATE_EMIT_EVENT: @@ -784,8 +820,20 @@ handle_state: dmesg_msg_iter->tmp_event_msg = NULL; break; case STATE_EMIT_PACKET_END: - *msg = bt_message_packet_end_create( - dmesg_msg_iter->pc_msg_iter, dmesg_comp->packet); + if (dmesg_comp->clock_class) { + *msg = bt_message_packet_end_create_with_default_clock_snapshot( + dmesg_msg_iter->pc_msg_iter, dmesg_comp->packet, + dmesg_msg_iter->last_clock_value); + } else { + *msg = bt_message_packet_end_create( + dmesg_msg_iter->pc_msg_iter, dmesg_comp->packet); + } + + dmesg_msg_iter->state = STATE_EMIT_STREAM_ACTIVITY_END; + break; + case STATE_EMIT_STREAM_ACTIVITY_END: + *msg = bt_message_stream_activity_end_create( + dmesg_msg_iter->pc_msg_iter, dmesg_comp->stream); dmesg_msg_iter->state = STATE_EMIT_STREAM_END; break; case STATE_EMIT_STREAM_END: @@ -808,7 +856,7 @@ end: } BT_HIDDEN -enum bt_self_message_iterator_status dmesg_msg_iter_next( +bt_self_message_iterator_status dmesg_msg_iter_next( bt_self_message_iterator *self_msg_iter, bt_message_array_const msgs, uint64_t capacity, uint64_t *count) @@ -816,7 +864,7 @@ enum bt_self_message_iterator_status dmesg_msg_iter_next( struct dmesg_msg_iter *dmesg_msg_iter = bt_self_message_iterator_get_data( self_msg_iter); - enum bt_self_message_iterator_status status = + bt_self_message_iterator_status status = BT_SELF_MESSAGE_ITERATOR_STATUS_OK; uint64_t i = 0; @@ -851,3 +899,29 @@ enum bt_self_message_iterator_status dmesg_msg_iter_next( return status; } + +BT_HIDDEN +bt_bool dmesg_msg_iter_can_seek_beginning( + bt_self_message_iterator *self_msg_iter) +{ + struct dmesg_msg_iter *dmesg_msg_iter = + bt_self_message_iterator_get_data(self_msg_iter); + + /* Can't seek the beginning of the standard input stream */ + return !dmesg_msg_iter->dmesg_comp->params.read_from_stdin; +} + +BT_HIDDEN +bt_self_message_iterator_status dmesg_msg_iter_seek_beginning( + bt_self_message_iterator *self_msg_iter) +{ + struct dmesg_msg_iter *dmesg_msg_iter = + bt_self_message_iterator_get_data(self_msg_iter); + + BT_ASSERT(!dmesg_msg_iter->dmesg_comp->params.read_from_stdin); + + BT_MESSAGE_PUT_REF_AND_RESET(dmesg_msg_iter->tmp_event_msg); + dmesg_msg_iter->last_clock_value = 0; + dmesg_msg_iter->state = STATE_EMIT_STREAM_BEGINNING; + return BT_SELF_MESSAGE_ITERATOR_STATUS_OK; +}