From: Jérémie Galarneau Date: Fri, 27 Jun 2014 17:55:34 +0000 (-0400) Subject: Move CTF-Writer stream to CTF-IR X-Git-Tag: v2.0.0-pre1~1519 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=3f043b0587e8c2bc1f8921438c112e41fa54db8f Move CTF-Writer stream to CTF-IR Signed-off-by: Jérémie Galarneau --- diff --git a/formats/ctf/ir/Makefile.am b/formats/ctf/ir/Makefile.am index 0247445c..295cc809 100644 --- a/formats/ctf/ir/Makefile.am +++ b/formats/ctf/ir/Makefile.am @@ -7,6 +7,7 @@ libctf_ir_la_SOURCES = \ event.c \ event-fields.c \ event-types.c \ + stream.c \ stream-class.c libctf_ir_la_LIBADD = \ diff --git a/formats/ctf/ir/stream-class.c b/formats/ctf/ir/stream-class.c index 67015978..a1115c22 100644 --- a/formats/ctf/ir/stream-class.c +++ b/formats/ctf/ir/stream-class.c @@ -1,5 +1,5 @@ /* - * stream.c + * stream-class.c * * Babeltrace CTF Writer * diff --git a/formats/ctf/ir/stream.c b/formats/ctf/ir/stream.c new file mode 100644 index 00000000..4b4e3106 --- /dev/null +++ b/formats/ctf/ir/stream.c @@ -0,0 +1,328 @@ +/* + * stream.c + * + * Babeltrace CTF Writer + * + * Copyright 2013, 2014 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static +void bt_ctf_stream_destroy(struct bt_ctf_ref *ref); +static +int set_structure_field_integer(struct bt_ctf_field *, char *, uint64_t); + +BT_HIDDEN +struct bt_ctf_stream *bt_ctf_stream_create( + struct bt_ctf_stream_class *stream_class) +{ + struct bt_ctf_stream *stream = NULL; + + if (!stream_class) { + goto end; + } + + stream = g_new0(struct bt_ctf_stream, 1); + if (!stream) { + goto end; + } + + bt_ctf_ref_init(&stream->ref_count); + stream->pos.fd = -1; + stream->id = stream_class->next_stream_id++; + stream->stream_class = stream_class; + bt_ctf_stream_class_get(stream_class); + bt_ctf_stream_class_freeze(stream_class); + stream->events = g_ptr_array_new_with_free_func( + (GDestroyNotify)bt_ctf_event_put); +end: + return stream; +} + +BT_HIDDEN +int bt_ctf_stream_set_flush_callback(struct bt_ctf_stream *stream, + flush_func callback, void *data) +{ + int ret = stream ? 0 : -1; + + if (!stream) { + goto end; + } + + stream->flush.func = callback; + stream->flush.data = data; +end: + return ret; +} + +BT_HIDDEN +int bt_ctf_stream_set_fd(struct bt_ctf_stream *stream, int fd) +{ + int ret = 0; + + if (stream->pos.fd != -1) { + ret = -1; + goto end; + } + + ctf_init_pos(&stream->pos, NULL, fd, O_RDWR); + stream->pos.fd = fd; +end: + return ret; +} + +void bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream, + uint64_t event_count) +{ + if (!stream) { + return; + } + + stream->events_discarded += event_count; +} + +int bt_ctf_stream_append_event(struct bt_ctf_stream *stream, + struct bt_ctf_event *event) +{ + int ret = 0; + uint64_t timestamp; + + if (!stream || !event) { + ret = -1; + goto end; + } + + ret = bt_ctf_event_validate(event); + if (ret) { + goto end; + } + + timestamp = bt_ctf_clock_get_time(stream->stream_class->clock); + ret = bt_ctf_event_set_timestamp(event, timestamp); + if (ret) { + goto end; + } + + bt_ctf_event_get(event); + g_ptr_array_add(stream->events, event); +end: + return ret; +} + +int bt_ctf_stream_flush(struct bt_ctf_stream *stream) +{ + int ret = 0; + size_t i; + uint64_t timestamp_begin, timestamp_end; + struct bt_ctf_stream_class *stream_class; + struct bt_ctf_field *integer = NULL; + struct ctf_stream_pos packet_context_pos; + + if (!stream) { + ret = -1; + goto end; + } + + if (!stream->events->len) { + goto end; + } + + if (stream->flush.func) { + stream->flush.func(stream, stream->flush.data); + } + + stream_class = stream->stream_class; + timestamp_begin = ((struct bt_ctf_event *) g_ptr_array_index( + stream->events, 0))->timestamp; + timestamp_end = ((struct bt_ctf_event *) g_ptr_array_index( + stream->events, stream->events->len - 1))->timestamp; + ret = set_structure_field_integer(stream_class->packet_context, + "timestamp_begin", timestamp_begin); + if (ret) { + goto end; + } + + ret = set_structure_field_integer(stream_class->packet_context, + "timestamp_end", timestamp_end); + if (ret) { + goto end; + } + + ret = set_structure_field_integer(stream_class->packet_context, + "events_discarded", stream->events_discarded); + if (ret) { + goto end; + } + + ret = set_structure_field_integer(stream_class->packet_context, + "content_size", UINT64_MAX); + if (ret) { + goto end; + } + + ret = set_structure_field_integer(stream_class->packet_context, + "packet_size", UINT64_MAX); + if (ret) { + goto end; + } + + /* Write packet context */ + memcpy(&packet_context_pos, &stream->pos, + sizeof(struct ctf_stream_pos)); + ret = bt_ctf_field_serialize(stream_class->packet_context, + &stream->pos); + if (ret) { + goto end; + } + + for (i = 0; i < stream->events->len; i++) { + struct bt_ctf_event *event = g_ptr_array_index( + stream->events, i); + uint32_t event_id = bt_ctf_event_class_get_id( + event->event_class); + uint64_t timestamp = bt_ctf_event_get_timestamp(event); + + ret = set_structure_field_integer(stream_class->event_header, + "id", event_id); + if (ret) { + goto end; + } + ret = set_structure_field_integer(stream_class->event_header, + "timestamp", timestamp); + if (ret) { + goto end; + } + + /* Write event header */ + ret = bt_ctf_field_serialize(stream_class->event_header, + &stream->pos); + if (ret) { + goto end; + } + + /* Write event content */ + ret = bt_ctf_event_serialize(event, &stream->pos); + if (ret) { + goto end; + } + } + + /* + * Update the packet total size and content size and overwrite the + * packet context. + * Copy base_mma as the packet may have been remapped (e.g. when a + * packet is resized). + */ + packet_context_pos.base_mma = stream->pos.base_mma; + ret = set_structure_field_integer(stream_class->packet_context, + "content_size", stream->pos.offset); + if (ret) { + goto end; + } + + ret = set_structure_field_integer(stream_class->packet_context, + "packet_size", stream->pos.packet_size); + if (ret) { + goto end; + } + + ret = bt_ctf_field_serialize(stream_class->packet_context, + &packet_context_pos); + if (ret) { + goto end; + } + + g_ptr_array_set_size(stream->events, 0); + stream->flushed_packet_count++; +end: + bt_ctf_field_put(integer); + return ret; +} + +void bt_ctf_stream_get(struct bt_ctf_stream *stream) +{ + if (!stream) { + return; + } + + bt_ctf_ref_get(&stream->ref_count); +} + +void bt_ctf_stream_put(struct bt_ctf_stream *stream) +{ + if (!stream) { + return; + } + + bt_ctf_ref_put(&stream->ref_count, bt_ctf_stream_destroy); +} + +static +void bt_ctf_stream_destroy(struct bt_ctf_ref *ref) +{ + struct bt_ctf_stream *stream; + + if (!ref) { + return; + } + + stream = container_of(ref, struct bt_ctf_stream, ref_count); + ctf_fini_pos(&stream->pos); + if (close(stream->pos.fd)) { + perror("close"); + } + bt_ctf_stream_class_put(stream->stream_class); + g_ptr_array_free(stream->events, TRUE); + g_free(stream); +} + +static +int set_structure_field_integer(struct bt_ctf_field *structure, char *name, + uint64_t value) +{ + int ret = 0; + + struct bt_ctf_field *integer = + bt_ctf_field_structure_get_field(structure, name); + if (!integer) { + ret = -1; + goto end; + } + + ret = bt_ctf_field_unsigned_integer_set_value(integer, value); +end: + bt_ctf_field_put(integer); + return ret; +} diff --git a/formats/ctf/writer/Makefile.am b/formats/ctf/writer/Makefile.am index 6f791f55..1f06c1af 100644 --- a/formats/ctf/writer/Makefile.am +++ b/formats/ctf/writer/Makefile.am @@ -4,7 +4,6 @@ noinst_LTLIBRARIES = libctf-writer.la libctf_writer_la_SOURCES = \ writer.c \ - stream.c \ functor.c libctf_writer_la_LIBADD = \ diff --git a/formats/ctf/writer/stream.c b/formats/ctf/writer/stream.c deleted file mode 100644 index 7a2af5ac..00000000 --- a/formats/ctf/writer/stream.c +++ /dev/null @@ -1,328 +0,0 @@ -/* - * stream.c - * - * Babeltrace CTF Writer - * - * Copyright 2013, 2014 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static -void bt_ctf_stream_destroy(struct bt_ctf_ref *ref); -static -int set_structure_field_integer(struct bt_ctf_field *, char *, uint64_t); - -BT_HIDDEN -struct bt_ctf_stream *bt_ctf_stream_create( - struct bt_ctf_stream_class *stream_class) -{ - struct bt_ctf_stream *stream = NULL; - - if (!stream_class) { - goto end; - } - - stream = g_new0(struct bt_ctf_stream, 1); - if (!stream) { - goto end; - } - - bt_ctf_ref_init(&stream->ref_count); - stream->pos.fd = -1; - stream->id = stream_class->next_stream_id++; - stream->stream_class = stream_class; - bt_ctf_stream_class_get(stream_class); - bt_ctf_stream_class_freeze(stream_class); - stream->events = g_ptr_array_new_with_free_func( - (GDestroyNotify)bt_ctf_event_put); -end: - return stream; -} - -BT_HIDDEN -int bt_ctf_stream_set_flush_callback(struct bt_ctf_stream *stream, - flush_func callback, void *data) -{ - int ret = stream ? 0 : -1; - - if (!stream) { - goto end; - } - - stream->flush.func = callback; - stream->flush.data = data; -end: - return ret; -} - -BT_HIDDEN -int bt_ctf_stream_set_fd(struct bt_ctf_stream *stream, int fd) -{ - int ret = 0; - - if (stream->pos.fd != -1) { - ret = -1; - goto end; - } - - ctf_init_pos(&stream->pos, NULL, fd, O_RDWR); - stream->pos.fd = fd; -end: - return ret; -} - -void bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream, - uint64_t event_count) -{ - if (!stream) { - return; - } - - stream->events_discarded += event_count; -} - -int bt_ctf_stream_append_event(struct bt_ctf_stream *stream, - struct bt_ctf_event *event) -{ - int ret = 0; - uint64_t timestamp; - - if (!stream || !event) { - ret = -1; - goto end; - } - - ret = bt_ctf_event_validate(event); - if (ret) { - goto end; - } - - timestamp = bt_ctf_clock_get_time(stream->stream_class->clock); - ret = bt_ctf_event_set_timestamp(event, timestamp); - if (ret) { - goto end; - } - - bt_ctf_event_get(event); - g_ptr_array_add(stream->events, event); -end: - return ret; -} - -int bt_ctf_stream_flush(struct bt_ctf_stream *stream) -{ - int ret = 0; - size_t i; - uint64_t timestamp_begin, timestamp_end; - struct bt_ctf_stream_class *stream_class; - struct bt_ctf_field *integer = NULL; - struct ctf_stream_pos packet_context_pos; - - if (!stream) { - ret = -1; - goto end; - } - - if (!stream->events->len) { - goto end; - } - - if (stream->flush.func) { - stream->flush.func(stream, stream->flush.data); - } - - stream_class = stream->stream_class; - timestamp_begin = ((struct bt_ctf_event *) g_ptr_array_index( - stream->events, 0))->timestamp; - timestamp_end = ((struct bt_ctf_event *) g_ptr_array_index( - stream->events, stream->events->len - 1))->timestamp; - ret = set_structure_field_integer(stream_class->packet_context, - "timestamp_begin", timestamp_begin); - if (ret) { - goto end; - } - - ret = set_structure_field_integer(stream_class->packet_context, - "timestamp_end", timestamp_end); - if (ret) { - goto end; - } - - ret = set_structure_field_integer(stream_class->packet_context, - "events_discarded", stream->events_discarded); - if (ret) { - goto end; - } - - ret = set_structure_field_integer(stream_class->packet_context, - "content_size", UINT64_MAX); - if (ret) { - goto end; - } - - ret = set_structure_field_integer(stream_class->packet_context, - "packet_size", UINT64_MAX); - if (ret) { - goto end; - } - - /* Write packet context */ - memcpy(&packet_context_pos, &stream->pos, - sizeof(struct ctf_stream_pos)); - ret = bt_ctf_field_serialize(stream_class->packet_context, - &stream->pos); - if (ret) { - goto end; - } - - for (i = 0; i < stream->events->len; i++) { - struct bt_ctf_event *event = g_ptr_array_index( - stream->events, i); - uint32_t event_id = bt_ctf_event_class_get_id( - event->event_class); - uint64_t timestamp = bt_ctf_event_get_timestamp(event); - - ret = set_structure_field_integer(stream_class->event_header, - "id", event_id); - if (ret) { - goto end; - } - ret = set_structure_field_integer(stream_class->event_header, - "timestamp", timestamp); - if (ret) { - goto end; - } - - /* Write event header */ - ret = bt_ctf_field_serialize(stream_class->event_header, - &stream->pos); - if (ret) { - goto end; - } - - /* Write event content */ - ret = bt_ctf_event_serialize(event, &stream->pos); - if (ret) { - goto end; - } - } - - /* - * Update the packet total size and content size and overwrite the - * packet context. - * Copy base_mma as the packet may have been remapped (e.g. when a - * packet is resized). - */ - packet_context_pos.base_mma = stream->pos.base_mma; - ret = set_structure_field_integer(stream_class->packet_context, - "content_size", stream->pos.offset); - if (ret) { - goto end; - } - - ret = set_structure_field_integer(stream_class->packet_context, - "packet_size", stream->pos.packet_size); - if (ret) { - goto end; - } - - ret = bt_ctf_field_serialize(stream_class->packet_context, - &packet_context_pos); - if (ret) { - goto end; - } - - g_ptr_array_set_size(stream->events, 0); - stream->flushed_packet_count++; -end: - bt_ctf_field_put(integer); - return ret; -} - -void bt_ctf_stream_get(struct bt_ctf_stream *stream) -{ - if (!stream) { - return; - } - - bt_ctf_ref_get(&stream->ref_count); -} - -void bt_ctf_stream_put(struct bt_ctf_stream *stream) -{ - if (!stream) { - return; - } - - bt_ctf_ref_put(&stream->ref_count, bt_ctf_stream_destroy); -} - -static -void bt_ctf_stream_destroy(struct bt_ctf_ref *ref) -{ - struct bt_ctf_stream *stream; - - if (!ref) { - return; - } - - stream = container_of(ref, struct bt_ctf_stream, ref_count); - ctf_fini_pos(&stream->pos); - if (close(stream->pos.fd)) { - perror("close"); - } - bt_ctf_stream_class_put(stream->stream_class); - g_ptr_array_free(stream->events, TRUE); - g_free(stream); -} - -static -int set_structure_field_integer(struct bt_ctf_field *structure, char *name, - uint64_t value) -{ - int ret = 0; - - struct bt_ctf_field *integer = - bt_ctf_field_structure_get_field(structure, name); - if (!integer) { - ret = -1; - goto end; - } - - ret = bt_ctf_field_unsigned_integer_set_value(integer, value); -end: - bt_ctf_field_put(integer); - return ret; -} diff --git a/formats/ctf/writer/writer.c b/formats/ctf/writer/writer.c index 57236bd9..a1605fce 100644 --- a/formats/ctf/writer/writer.c +++ b/formats/ctf/writer/writer.c @@ -34,8 +34,8 @@ #include #include #include -#include -#include +#include +#include #include #include #include diff --git a/include/Makefile.am b/include/Makefile.am index 3e322666..00364dc8 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -26,6 +26,7 @@ babeltracectfirinclude_HEADERS = \ babeltrace/ctf-ir/event-fields.h \ babeltrace/ctf-ir/event-types.h \ babeltrace/ctf-ir/event.h \ + babeltrace/ctf-ir/stream.h \ babeltrace/ctf-ir/stream-class.h noinst_HEADERS = \ @@ -54,7 +55,7 @@ noinst_HEADERS = \ babeltrace/ctf-ir/event-internal.h \ babeltrace/ctf-ir/clock-internal.h \ babeltrace/ctf-ir/stream-class-internal.h \ - babeltrace/ctf-writer/stream-internal.h \ + babeltrace/ctf-ir/stream-internal.h \ babeltrace/ctf-writer/functor-internal.h \ babeltrace/trace-handle-internal.h \ babeltrace/compat/uuid.h \ diff --git a/include/babeltrace/ctf-ir/stream-internal.h b/include/babeltrace/ctf-ir/stream-internal.h new file mode 100644 index 00000000..daaa430b --- /dev/null +++ b/include/babeltrace/ctf-ir/stream-internal.h @@ -0,0 +1,68 @@ +#ifndef BABELTRACE_CTF_WRITER_STREAM_INTERNAL_H +#define BABELTRACE_CTF_WRITER_STREAM_INTERNAL_H + +/* + * BabelTrace - CTF Writer: Stream internal + * + * Copyright 2013, 2014 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 +#include +#include +#include +#include +#include + +typedef void(*flush_func)(struct bt_ctf_stream *, void *); + +struct flush_callback { + flush_func func; + void *data; +}; + +struct bt_ctf_stream { + struct bt_ctf_ref ref_count; + uint32_t id; + struct bt_ctf_stream_class *stream_class; + struct flush_callback flush; + /* Array of pointers to bt_ctf_event for the current packet */ + GPtrArray *events; + struct ctf_stream_pos pos; + unsigned int flushed_packet_count; + uint64_t events_discarded; +}; + +BT_HIDDEN +struct bt_ctf_stream *bt_ctf_stream_create( + struct bt_ctf_stream_class *stream_class); + +BT_HIDDEN +int bt_ctf_stream_set_flush_callback(struct bt_ctf_stream *stream, + flush_func callback, void *data); + +BT_HIDDEN +int bt_ctf_stream_set_fd(struct bt_ctf_stream *stream, int fd); + +#endif /* BABELTRACE_CTF_WRITER_STREAM_INTERNAL_H */ diff --git a/include/babeltrace/ctf-ir/stream.h b/include/babeltrace/ctf-ir/stream.h new file mode 100644 index 00000000..0341e78e --- /dev/null +++ b/include/babeltrace/ctf-ir/stream.h @@ -0,0 +1,104 @@ +#ifndef BABELTRACE_CTF_IR_STREAM_H +#define BABELTRACE_CTF_IR_STREAM_H + +/* + * BabelTrace - CTF IR: Stream + * + * Copyright 2013, 2014 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. + * + * The Common Trace Format (CTF) Specification is available at + * http://www.efficios.com/ctf + */ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct bt_ctf_event; +struct bt_ctf_stream; + +/* + * bt_ctf_stream_append_discarded_events: increment discarded events count. + * + * Increase the current packet's discarded event count. + * + * @param stream Stream instance. + * @param event_count Number of discarded events to add to the stream's current + * packet. + */ +extern void bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream, + uint64_t event_count); + +/* + * bt_ctf_stream_append_event: append an event to the stream. + * + * Append "event" to the stream's current packet. The stream's associated clock + * will be sampled during this call. The event shall not be modified after + * being appended to a stream. The stream will share the event's ownership by + * incrementing its reference count. The current packet is not flushed to disk + * until the next call to bt_ctf_stream_flush. + * + * @param stream Stream instance. + * @param event Event instance to append to the stream's current packet. + * + * Returns 0 on success, a negative value on error. + */ +extern int bt_ctf_stream_append_event(struct bt_ctf_stream *stream, + struct bt_ctf_event *event); + +/* + * bt_ctf_stream_flush: flush a stream. + * + * The stream's current packet's events will be flushed to disk. Events + * subsequently appended to the stream will be added to a new packet. + * + * @param stream Stream instance. + * + * Returns 0 on success, a negative value on error. + */ +extern int bt_ctf_stream_flush(struct bt_ctf_stream *stream); + +/* + * bt_ctf_stream_get and bt_ctf_stream_put: increment and decrement the + * stream's reference count. + * + * These functions ensure that the stream won't be destroyed while it + * is in use. The same number of get and put (plus one extra put to + * release the initial reference done at creation) have to be done to + * destroy a stream. + * + * When the stream's reference count is decremented to 0 by a + * bt_ctf_stream_put, the stream is freed. + * + * @param stream Stream instance. + */ +extern void bt_ctf_stream_get(struct bt_ctf_stream *stream); +extern void bt_ctf_stream_put(struct bt_ctf_stream *stream); + +#ifdef __cplusplus +} +#endif + +#endif /* BABELTRACE_CTF_IR_STREAM_H */ diff --git a/include/babeltrace/ctf-writer/stream-internal.h b/include/babeltrace/ctf-writer/stream-internal.h deleted file mode 100644 index daaa430b..00000000 --- a/include/babeltrace/ctf-writer/stream-internal.h +++ /dev/null @@ -1,68 +0,0 @@ -#ifndef BABELTRACE_CTF_WRITER_STREAM_INTERNAL_H -#define BABELTRACE_CTF_WRITER_STREAM_INTERNAL_H - -/* - * BabelTrace - CTF Writer: Stream internal - * - * Copyright 2013, 2014 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 -#include -#include -#include -#include -#include - -typedef void(*flush_func)(struct bt_ctf_stream *, void *); - -struct flush_callback { - flush_func func; - void *data; -}; - -struct bt_ctf_stream { - struct bt_ctf_ref ref_count; - uint32_t id; - struct bt_ctf_stream_class *stream_class; - struct flush_callback flush; - /* Array of pointers to bt_ctf_event for the current packet */ - GPtrArray *events; - struct ctf_stream_pos pos; - unsigned int flushed_packet_count; - uint64_t events_discarded; -}; - -BT_HIDDEN -struct bt_ctf_stream *bt_ctf_stream_create( - struct bt_ctf_stream_class *stream_class); - -BT_HIDDEN -int bt_ctf_stream_set_flush_callback(struct bt_ctf_stream *stream, - flush_func callback, void *data); - -BT_HIDDEN -int bt_ctf_stream_set_fd(struct bt_ctf_stream *stream, int fd); - -#endif /* BABELTRACE_CTF_WRITER_STREAM_INTERNAL_H */ diff --git a/include/babeltrace/ctf-writer/stream.h b/include/babeltrace/ctf-writer/stream.h index df251fcc..a878cae6 100644 --- a/include/babeltrace/ctf-writer/stream.h +++ b/include/babeltrace/ctf-writer/stream.h @@ -1,6 +1,3 @@ -#ifndef BABELTRACE_CTF_WRITER_STREAM_H -#define BABELTRACE_CTF_WRITER_STREAM_H - /* * BabelTrace - CTF Writer: Stream * @@ -30,75 +27,4 @@ * http://www.efficios.com/ctf */ -#include - -#ifdef __cplusplus -extern "C" { -#endif - -struct bt_ctf_event; -struct bt_ctf_stream; - -/* - * bt_ctf_stream_append_discarded_events: increment discarded events count. - * - * Increase the current packet's discarded event count. - * - * @param stream Stream instance. - * @param event_count Number of discarded events to add to the stream's current - * packet. - */ -extern void bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream, - uint64_t event_count); - -/* - * bt_ctf_stream_append_event: append an event to the stream. - * - * Append "event" to the stream's current packet. The stream's associated clock - * will be sampled during this call. The event shall not be modified after - * being appended to a stream. The stream will share the event's ownership by - * incrementing its reference count. The current packet is not flushed to disk - * until the next call to bt_ctf_stream_flush. - * - * @param stream Stream instance. - * @param event Event instance to append to the stream's current packet. - * - * Returns 0 on success, a negative value on error. - */ -extern int bt_ctf_stream_append_event(struct bt_ctf_stream *stream, - struct bt_ctf_event *event); - -/* - * bt_ctf_stream_flush: flush a stream. - * - * The stream's current packet's events will be flushed to disk. Events - * subsequently appended to the stream will be added to a new packet. - * - * @param stream Stream instance. - * - * Returns 0 on success, a negative value on error. - */ -extern int bt_ctf_stream_flush(struct bt_ctf_stream *stream); - -/* - * bt_ctf_stream_get and bt_ctf_stream_put: increment and decrement the - * stream's reference count. - * - * These functions ensure that the stream won't be destroyed while it - * is in use. The same number of get and put (plus one extra put to - * release the initial reference done at creation) have to be done to - * destroy a stream. - * - * When the stream's reference count is decremented to 0 by a - * bt_ctf_stream_put, the stream is freed. - * - * @param stream Stream instance. - */ -extern void bt_ctf_stream_get(struct bt_ctf_stream *stream); -extern void bt_ctf_stream_put(struct bt_ctf_stream *stream); - -#ifdef __cplusplus -} -#endif - -#endif /* BABELTRACE_CTF_WRITER_STREAM_H */ +#include