From 043e202066787ef4d63c587375c1d58753245d82 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Wed, 7 Sep 2016 18:23:56 -0400 Subject: [PATCH] add end of stream notification MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- converter/babeltrace.c | 4 +- include/Makefile.am | 6 +- .../plugin/notification/notification.h | 11 +-- .../babeltrace/plugin/notification/schema.h | 1 - .../plugin/notification/stream-internal.h | 38 +++++++++++ .../babeltrace/plugin/notification/stream.h | 46 +++++++++++++ lib/plugin-system/notification/Makefile.am | 3 +- lib/plugin-system/notification/packet.c | 8 +-- lib/plugin-system/notification/stream.c | 67 +++++++++++++++++++ plugins/ctf/common/notif-iter/notif-iter.c | 22 ++++++ plugins/ctf/fs/data-stream.c | 21 +++++- plugins/ctf/fs/fs.c | 4 +- plugins/ctf/fs/fs.h | 1 + plugins/text/text.c | 36 +++++----- 14 files changed, 232 insertions(+), 36 deletions(-) create mode 100644 include/babeltrace/plugin/notification/stream-internal.h create mode 100644 include/babeltrace/plugin/notification/stream.h create mode 100644 lib/plugin-system/notification/stream.c diff --git a/converter/babeltrace.c b/converter/babeltrace.c index e563c0a4..5b381bf6 100644 --- a/converter/babeltrace.c +++ b/converter/babeltrace.c @@ -255,7 +255,7 @@ int main(int argc, char **argv) component_factory, "ctf", BT_COMPONENT_TYPE_SOURCE, "fs"); if (!source_class) { - fprintf(stderr, "Could not find ctf-fs output component class. Aborting...\n"); + fprintf(stderr, "Could not find ctf-fs source component class. Aborting...\n"); ret = -1; goto end; } @@ -263,7 +263,7 @@ int main(int argc, char **argv) sink_class = bt_component_factory_get_component_class(component_factory, "text", BT_COMPONENT_TYPE_SINK, "text"); if (!sink_class) { - fprintf(stderr, "Could not find text output component class. Aborting...\n"); + fprintf(stderr, "Could not find text sink component class. Aborting...\n"); ret = -1; goto end; } diff --git a/include/Makefile.am b/include/Makefile.am index 76e07722..5ae1cc30 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -51,7 +51,8 @@ babeltraceplugininclude_HEADERS = \ babeltrace/plugin/notification/event.h \ babeltrace/plugin/notification/iterator.h \ babeltrace/plugin/notification/packet.h \ - babeltrace/plugin/notification/schema.h + babeltrace/plugin/notification/schema.h \ + babeltrace/plugin/notification/stream.h noinst_HEADERS = \ babeltrace/align.h \ @@ -122,4 +123,5 @@ noinst_HEADERS = \ babeltrace/plugin/notification/event-internal.h \ babeltrace/plugin/notification/iterator-internal.h \ babeltrace/plugin/notification/notification-internal.h \ - babeltrace/plugin/notification/packet-internal.h + babeltrace/plugin/notification/packet-internal.h \ + babeltrace/plugin/notification/stream-internal.h diff --git a/include/babeltrace/plugin/notification/notification.h b/include/babeltrace/plugin/notification/notification.h index 5557f919..4636f229 100644 --- a/include/babeltrace/plugin/notification/notification.h +++ b/include/babeltrace/plugin/notification/notification.h @@ -54,17 +54,20 @@ enum bt_notification_type { /** End of stream packet notification, see packet.h */ BT_NOTIFICATION_TYPE_PACKET_END = 3, + /** End of stream packet notification, see stream.h */ + BT_NOTIFICATION_TYPE_STREAM_END = 4, + /** New trace notification, see model.h */ - BT_NOTIFICATION_TYPE_NEW_TRACE = 4, + BT_NOTIFICATION_TYPE_NEW_TRACE = 5, /** New stream class notification, see model.h */ - BT_NOTIFICATION_TYPE_NEW_STREAM_CLASS = 5, + BT_NOTIFICATION_TYPE_NEW_STREAM_CLASS = 6, /** New event class notification, see model.h */ - BT_NOTIFICATION_TYPE_NEW_EVENT_CLASS = 6, + BT_NOTIFICATION_TYPE_NEW_EVENT_CLASS = 7, /** End of trace notification, see eot.h */ - BT_NOTIFICATION_TYPE_END_OF_TRACE = 7, + BT_NOTIFICATION_TYPE_END_OF_TRACE = 8, BT_NOTIFICATION_TYPE_NR, /* Not part of ABI. */ }; diff --git a/include/babeltrace/plugin/notification/schema.h b/include/babeltrace/plugin/notification/schema.h index 96b161a0..5d7b6425 100644 --- a/include/babeltrace/plugin/notification/schema.h +++ b/include/babeltrace/plugin/notification/schema.h @@ -36,7 +36,6 @@ struct bt_ctf_trace; struct bt_ctf_stream_class; struct bt_ctf_event_class; - /* BT_NOTIFICATION_TYPE_NEW_TRACE */ /** * Create a new trace notification. diff --git a/include/babeltrace/plugin/notification/stream-internal.h b/include/babeltrace/plugin/notification/stream-internal.h new file mode 100644 index 00000000..73e2fd63 --- /dev/null +++ b/include/babeltrace/plugin/notification/stream-internal.h @@ -0,0 +1,38 @@ +#ifndef BABELTRACE_PLUGIN_NOTIFICATION_STREAM_INTERNAL_H +#define BABELTRACE_PLUGIN_NOTIFICATION_STREAM_INTERNAL_H + +/* + * BabelTrace - Stream-related Notifications + * + * Copyright 2016 Jérémie Galarneau + * + * Author: 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 + +struct bt_notification_stream_end { + struct bt_notification parent; + struct bt_ctf_stream *stream; +}; + +#endif /* BABELTRACE_PLUGIN_NOTIFICATION_STREAM_INTERNAL_H */ diff --git a/include/babeltrace/plugin/notification/stream.h b/include/babeltrace/plugin/notification/stream.h new file mode 100644 index 00000000..6f079256 --- /dev/null +++ b/include/babeltrace/plugin/notification/stream.h @@ -0,0 +1,46 @@ +#ifndef BABELTRACE_PLUGIN_NOTIFICATION_STREAM_H +#define BABELTRACE_PLUGIN_NOTIFICATION_STREAM_H + +/* + * BabelTrace - Plug-in Stream-related Notifications + * + * Copyright 2016 Jérémie Galarneau + * + * Author: 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 + +#ifdef __cplusplus +extern "C" { +#endif + +/*** BT_NOTIFICATION_TYPE_STREAM_END ***/ +struct bt_notification *bt_notification_stream_end_create( + struct bt_ctf_stream *stream); +struct bt_ctf_stream *bt_notification_stream_end_get_stream( + struct bt_notification *notification); + +#ifdef __cplusplus +} +#endif + +#endif /* BABELTRACE_PLUGIN_NOTIFICATION_STREAM_H */ diff --git a/lib/plugin-system/notification/Makefile.am b/lib/plugin-system/notification/Makefile.am index 1271c6eb..12cdbf12 100644 --- a/lib/plugin-system/notification/Makefile.am +++ b/lib/plugin-system/notification/Makefile.am @@ -6,4 +6,5 @@ noinst_LTLIBRARIES = libplugin-system-notification.la libplugin_system_notification_la_SOURCES = \ notification.c \ packet.c \ - event.c + event.c \ + stream.c diff --git a/lib/plugin-system/notification/packet.c b/lib/plugin-system/notification/packet.c index 0b6649a9..112f0f78 100644 --- a/lib/plugin-system/notification/packet.c +++ b/lib/plugin-system/notification/packet.c @@ -28,7 +28,7 @@ #include static -void bt_notification_start_packet_destroy(struct bt_object *obj) +void bt_notification_packet_start_destroy(struct bt_object *obj) { struct bt_notification_packet_start *notification = (struct bt_notification_packet_start *) obj; @@ -38,7 +38,7 @@ void bt_notification_start_packet_destroy(struct bt_object *obj) } static -void bt_notification_end_packet_destroy(struct bt_object *obj) +void bt_notification_packet_end_destroy(struct bt_object *obj) { struct bt_notification_packet_end *notification = (struct bt_notification_packet_end *) obj; @@ -59,7 +59,7 @@ struct bt_notification *bt_notification_packet_start_create( notification = g_new0(struct bt_notification_packet_start, 1); bt_notification_init(¬ification->parent, BT_NOTIFICATION_TYPE_PACKET_START, - bt_notification_start_packet_destroy); + bt_notification_packet_start_destroy); notification->packet = bt_get(packet); return ¬ification->parent; error: @@ -88,7 +88,7 @@ struct bt_notification *bt_notification_packet_end_create( notification = g_new0(struct bt_notification_packet_end, 1); bt_notification_init(¬ification->parent, BT_NOTIFICATION_TYPE_PACKET_END, - bt_notification_end_packet_destroy); + bt_notification_packet_end_destroy); notification->packet = bt_get(packet); return ¬ification->parent; error: diff --git a/lib/plugin-system/notification/stream.c b/lib/plugin-system/notification/stream.c new file mode 100644 index 00000000..bc0b1b7e --- /dev/null +++ b/lib/plugin-system/notification/stream.c @@ -0,0 +1,67 @@ +/* + * Babeltrace Plug-in Stream-related Notifications + * + * Copyright 2016 Jérémie Galarneau + * + * Author: 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 + +static +void bt_notification_stream_end_destroy(struct bt_object *obj) +{ + struct bt_notification_stream_end *notification = + (struct bt_notification_stream_end *) obj; + + BT_PUT(notification->stream); + g_free(notification); +} + +struct bt_notification *bt_notification_stream_end_create( + struct bt_ctf_stream *stream) +{ + struct bt_notification_stream_end *notification; + + if (!stream) { + goto error; + } + + notification = g_new0(struct bt_notification_stream_end, 1); + bt_notification_init(¬ification->parent, + BT_NOTIFICATION_TYPE_STREAM_END, + bt_notification_stream_end_destroy); + notification->stream = bt_get(stream); + return ¬ification->parent; +error: + return NULL; +} + +struct bt_ctf_packet *bt_notification_stream_end_get_stream( + struct bt_notification *notification) +{ + struct bt_notification_stream_end *stream_end; + + stream_end = container_of(notification, + struct bt_notification_stream_end, parent); + return bt_get(stream_end->stream); +} diff --git a/plugins/ctf/common/notif-iter/notif-iter.c b/plugins/ctf/common/notif-iter/notif-iter.c index ee4cd2be..5de812b0 100644 --- a/plugins/ctf/common/notif-iter/notif-iter.c +++ b/plugins/ctf/common/notif-iter/notif-iter.c @@ -1735,6 +1735,28 @@ end: BT_PUT(event); } +static +void notify_eos(struct bt_ctf_notif_iter *notit, + struct bt_notification **notification) +{ + struct bt_ctf_event *event; + struct bt_notification *ret = NULL; + + /* Create event */ + event = create_event(notit); + if (!event) { + goto end; + } + + ret = bt_notification_stream_end_create(event); + if (!ret) { + goto end; + } + *notification = ret; +end: + BT_PUT(event); +} + struct bt_ctf_notif_iter *bt_ctf_notif_iter_create(struct bt_ctf_trace *trace, size_t max_request_sz, struct bt_ctf_notif_iter_medium_ops medops, diff --git a/plugins/ctf/fs/data-stream.c b/plugins/ctf/fs/data-stream.c index 64152ed2..704e4f64 100644 --- a/plugins/ctf/fs/data-stream.c +++ b/plugins/ctf/fs/data-stream.c @@ -330,6 +330,11 @@ enum bt_notification_iterator_status ctf_fs_data_stream_get_next_notification( struct ctf_fs_stream *stream = g_ptr_array_index( ctf_fs->data_stream.streams, 0); + if (stream->end_reached) { + status = BT_CTF_NOTIF_ITER_STATUS_EOF; + goto end; + } + status = bt_ctf_notif_iter_get_next_notification(stream->notif_iter, notification); if (status != BT_CTF_NOTIF_ITER_STATUS_OK && @@ -337,12 +342,21 @@ enum bt_notification_iterator_status ctf_fs_data_stream_get_next_notification( goto end; } + /* Should be handled in bt_ctf_notif_iter_get_next_notification. */ + if (status == BT_CTF_NOTIF_ITER_STATUS_EOF) { + *notification = bt_notification_stream_end_create( + stream->stream); + if (!*notification) { + status = BT_CTF_NOTIF_ITER_STATUS_ERROR; + } + status = BT_CTF_NOTIF_ITER_STATUS_OK; + stream->end_reached = true; + } end: switch (status) { case BT_CTF_NOTIF_ITER_STATUS_EOF: - /* Not an error, send end of stream notification. */ - /* Subsequent calls to "next" should return BT_NOTIFICATION_STATUS_END */ - /* TODO */ + ret = BT_NOTIFICATION_ITERATOR_STATUS_END; + break; case BT_CTF_NOTIF_ITER_STATUS_OK: ret = BT_NOTIFICATION_ITERATOR_STATUS_OK; break; @@ -356,6 +370,7 @@ end: case BT_CTF_NOTIF_ITER_STATUS_INVAL: /* No argument provided by the user, so don't return INVAL. */ case BT_CTF_NOTIF_ITER_STATUS_ERROR: + default: ret = BT_NOTIFICATION_ITERATOR_STATUS_ERROR; break; } diff --git a/plugins/ctf/fs/fs.c b/plugins/ctf/fs/fs.c index ba550f2f..cf00fddd 100644 --- a/plugins/ctf/fs/fs.c +++ b/plugins/ctf/fs/fs.c @@ -86,7 +86,7 @@ enum bt_notification_iterator_status ctf_fs_iterator_next( bt_put(ctf_fs->current_notification); ctf_fs->current_notification = notification; end: - return BT_NOTIFICATION_ITERATOR_STATUS_OK; + return ret; } static @@ -137,7 +137,6 @@ enum bt_component_status ctf_fs_iterator_init(struct bt_component *source, if (ret) { goto error; } - end: return ret; error: @@ -240,7 +239,6 @@ enum bt_component_status ctf_fs_init(struct bt_component *source, if (ret != BT_COMPONENT_STATUS_OK) { goto error; } - end: return ret; error: diff --git a/plugins/ctf/fs/fs.h b/plugins/ctf/fs/fs.h index 31c86827..f3d442e4 100644 --- a/plugins/ctf/fs/fs.h +++ b/plugins/ctf/fs/fs.h @@ -63,6 +63,7 @@ struct ctf_fs_stream { size_t mmap_len; off_t mmap_offset; off_t request_offset; + bool end_reached; }; struct ctf_fs_data_stream { diff --git a/plugins/text/text.c b/plugins/text/text.c index 40bc1c5e..9d72e3a1 100644 --- a/plugins/text/text.c +++ b/plugins/text/text.c @@ -72,25 +72,23 @@ const char *loglevel_str [] = { }; struct text_options { - bool opt_print_all_field_names : 1; - bool opt_print_scope_field_names : 1; - bool opt_print_header_field_names : 1; - bool opt_print_context_field_names : 1; - bool opt_print_payload_field_names : 1; - bool opt_print_all_fields : 1; - bool opt_print_trace_field : 1; - bool opt_print_trace_domain_field : 1; - bool opt_print_trace_procname_field : 1; - bool opt_print_trace_vpid_field : 1; - bool opt_print_trace_hostname_field : 1; - bool opt_print_trace_default_fields : 1; - bool opt_print_loglevel_field : 1; - bool opt_print_emf_field : 1; - bool opt_print_delta_field : 1; + bool print_scope_field_names : 1; + bool print_header_field_names : 1; + bool print_context_field_names : 1; + bool print_payload_field_names : 1; + bool print_delta_field : 1; + bool print_loglevel_field : 1; + bool print_trace_field : 1; + bool print_trace_domain_field : 1; + bool print_trace_procname_field : 1; + bool print_trace_vpid_field : 1; + bool print_trace_hostname_field : 1; + bool no_size_limit : 1; }; struct text_component { struct text_options options; + FILE *out, *err; }; static @@ -124,7 +122,10 @@ enum bt_component_status handle_notification(struct bt_component *component, puts(""); break; case BT_NOTIFICATION_TYPE_EVENT: - puts(""); + puts("\t"); + break; + case BT_NOTIFICATION_TYPE_STREAM_END: + puts(""); break; default: puts("Unhandled notification type"); @@ -160,6 +161,9 @@ enum bt_component_status text_component_init( if (ret != BT_COMPONENT_STATUS_OK) { goto error; } + + text->out = stdout; + text->err = stderr; end: return ret; error: -- 2.34.1