This is intended to provide a generic way to access the bt_stream_pos API without having to make assumptions about the output format's descriptor layout.
Renamed format-internal.h to trace-descriptor-internal.h to make it more representative of the interface it really contains. Signed-off-by: Jérémie Galarneau <[email protected]> --- formats/bt-dummy/bt-dummy.c | 3 ++ formats/ctf-metadata/ctf-metadata.c | 3 ++ formats/ctf-text/ctf-text.c | 3 ++ formats/ctf/ctf.c | 11 ++++-- include/Makefile.am | 5 ++- include/babeltrace/ctf-ir/metadata.h | 2 +- include/babeltrace/ctf-text/types.h | 2 +- include/babeltrace/format-internal.h | 54 ------------------------- include/babeltrace/trace-descriptor-internal.h | 55 ++++++++++++++++++++++++++ include/babeltrace/trace-descriptor.h | 53 +++++++++++++++++++++++++ lib/Makefile.am | 3 +- lib/trace-descriptor.c | 42 ++++++++++++++++++++ 12 files changed, 174 insertions(+), 62 deletions(-) delete mode 100644 include/babeltrace/format-internal.h create mode 100644 include/babeltrace/trace-descriptor-internal.h create mode 100644 include/babeltrace/trace-descriptor.h create mode 100644 lib/trace-descriptor.c diff --git a/formats/bt-dummy/bt-dummy.c b/formats/bt-dummy/bt-dummy.c index 6192e88..d9767fc 100644 --- a/formats/bt-dummy/bt-dummy.c +++ b/formats/bt-dummy/bt-dummy.c @@ -55,6 +55,8 @@ struct bt_trace_descriptor *bt_dummy_open_trace(const char *path, int flags, pos->parent.rw_table = NULL; pos->parent.event_cb = bt_dummy_write_event; pos->parent.trace = &pos->trace_descriptor; + pos->trace_descriptor.stream_pos = g_ptr_array_sized_new(1); + g_ptr_array_add(pos->trace_descriptor.stream_pos, pos); return &pos->trace_descriptor; } @@ -64,6 +66,7 @@ int bt_dummy_close_trace(struct bt_trace_descriptor *td) struct ctf_text_stream_pos *pos = container_of(td, struct ctf_text_stream_pos, trace_descriptor); + g_ptr_array_free(td->stream_pos, TRUE); free(pos); return 0; } diff --git a/formats/ctf-metadata/ctf-metadata.c b/formats/ctf-metadata/ctf-metadata.c index a5a74c3..e8774eb 100644 --- a/formats/ctf-metadata/ctf-metadata.c +++ b/formats/ctf-metadata/ctf-metadata.c @@ -96,6 +96,8 @@ struct bt_trace_descriptor *ctf_metadata_open_trace(const char *path, int flags, pos->fp = fp; pos->parent.pre_trace_cb = ctf_metadata_trace_pre_handler; pos->parent.trace = &pos->trace_descriptor; + pos->trace_descriptor.stream_pos = g_ptr_array_sized_new(1); + g_ptr_array_add(pos->trace_descriptor.stream_pos, pos); pos->print_names = 0; break; case O_RDONLY: @@ -116,6 +118,7 @@ int ctf_metadata_close_trace(struct bt_trace_descriptor *td) int ret; struct ctf_text_stream_pos *pos = container_of(td, struct ctf_text_stream_pos, trace_descriptor); + g_ptr_array_free(td->stream_pos, TRUE); if (pos->fp != stdout) { ret = fclose(pos->fp); if (ret) { diff --git a/formats/ctf-text/ctf-text.c b/formats/ctf-text/ctf-text.c index 48ce31b..c3b55ed 100644 --- a/formats/ctf-text/ctf-text.c +++ b/formats/ctf-text/ctf-text.c @@ -562,6 +562,8 @@ struct bt_trace_descriptor *ctf_text_open_trace(const char *path, int flags, pos->parent.rw_table = write_dispatch_table; pos->parent.event_cb = ctf_text_write_event; pos->parent.trace = &pos->trace_descriptor; + pos->trace_descriptor.stream_pos = g_ptr_array_sized_new(1); + g_ptr_array_add(pos->trace_descriptor.stream_pos, pos); pos->print_names = 0; break; case O_RDONLY: @@ -582,6 +584,7 @@ int ctf_text_close_trace(struct bt_trace_descriptor *td) int ret; struct ctf_text_stream_pos *pos = container_of(td, struct ctf_text_stream_pos, trace_descriptor); + g_ptr_array_free(td->stream_pos, TRUE); if (pos->fp != stdout) { ret = fclose(pos->fp); if (ret) { diff --git a/formats/ctf/ctf.c b/formats/ctf/ctf.c index bb94e52..aee80b1 100644 --- a/formats/ctf/ctf.c +++ b/formats/ctf/ctf.c @@ -1728,9 +1728,10 @@ int ctf_open_file_stream_read(struct ctf_trace *td, const char *path, int flags, fprintf(stderr, "[error] Stream index creation error.\n"); goto error_index; } - /* Add stream file to stream class */ + /* Add stream file to stream class and trace descriptor */ g_ptr_array_add(file_stream->parent.stream_class->streams, &file_stream->parent); + g_ptr_array_add(td->parent.stream_pos, &file_stream->pos.parent); return 0; error_index: @@ -1864,6 +1865,7 @@ struct bt_trace_descriptor *ctf_open_trace(const char *path, int flags, packet_seek = ctf_packet_seek; td = g_new0(struct ctf_trace, 1); + td->parent.stream_pos = g_ptr_array_new(); switch (flags & O_ACCMODE) { case O_RDONLY: @@ -1871,7 +1873,8 @@ struct bt_trace_descriptor *ctf_open_trace(const char *path, int flags, fprintf(stderr, "[error] Path missing for input CTF trace.\n"); goto error; } - ret = ctf_open_trace_read(td, path, flags, packet_seek, metadata_fp); + ret = ctf_open_trace_read(td, path, flags, packet_seek, + metadata_fp); if (ret) goto error; break; @@ -1885,6 +1888,7 @@ struct bt_trace_descriptor *ctf_open_trace(const char *path, int flags, return &td->parent; error: + g_ptr_array_free(td->parent.stream_pos, TRUE); g_free(td); return NULL; } @@ -1967,9 +1971,10 @@ int ctf_open_mmap_stream_read(struct ctf_trace *td, */ file_stream->parent.current_clock = td->parent.single_clock; - /* Add stream file to stream class */ + /* Add stream file to stream class and trace descriptor */ g_ptr_array_add(file_stream->parent.stream_class->streams, &file_stream->parent); + g_ptr_array_add(td->parent.stream_pos, &file_stream->pos.parent); return 0; error_index: diff --git a/include/Makefile.am b/include/Makefile.am index eee2ac1..c953fac 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -5,7 +5,8 @@ babeltraceinclude_HEADERS = \ babeltrace/iterator.h \ babeltrace/trace-handle.h \ babeltrace/list.h \ - babeltrace/clock-types.h + babeltrace/clock-types.h \ + babeltrace/trace-descriptor.h babeltracectfinclude_HEADERS = \ babeltrace/ctf/events.h \ @@ -19,7 +20,7 @@ noinst_HEADERS = \ babeltrace/clock-internal.h \ babeltrace/compiler.h \ babeltrace/context-internal.h \ - babeltrace/format-internal.h \ + babeltrace/trace-descriptor-internal.h \ babeltrace/iterator-internal.h \ babeltrace/trace-collection.h \ babeltrace/prio_heap.h \ diff --git a/include/babeltrace/ctf-ir/metadata.h b/include/babeltrace/ctf-ir/metadata.h index 5e92984..458d4d9 100644 --- a/include/babeltrace/ctf-ir/metadata.h +++ b/include/babeltrace/ctf-ir/metadata.h @@ -29,7 +29,7 @@ #include <babeltrace/types.h> #include <babeltrace/format.h> -#include <babeltrace/format-internal.h> +#include <babeltrace/trace-descriptor-internal.h> #include <babeltrace/ctf/types.h> #include <sys/types.h> #include <dirent.h> diff --git a/include/babeltrace/ctf-text/types.h b/include/babeltrace/ctf-text/types.h index 7b4b717..89b99f8 100644 --- a/include/babeltrace/ctf-text/types.h +++ b/include/babeltrace/ctf-text/types.h @@ -35,7 +35,7 @@ #include <babeltrace/babeltrace-internal.h> #include <babeltrace/types.h> #include <babeltrace/format.h> -#include <babeltrace/format-internal.h> +#include <babeltrace/trace-descriptor-internal.h> /* * Inherit from both struct bt_stream_pos and struct bt_trace_descriptor. diff --git a/include/babeltrace/format-internal.h b/include/babeltrace/format-internal.h deleted file mode 100644 index 7f3eb5e..0000000 --- a/include/babeltrace/format-internal.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef _BABELTRACE_FORMAT_INTERNAL_H -#define _BABELTRACE_FORMAT_INTERNAL_H - -/* - * BabelTrace - * - * Trace Format Internal Header - * - * Copyright 2010-2013 EfficiOS Inc. and Linux Foundation - * - * Author: Mathieu Desnoyers <[email protected]> - * - * 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 <limits.h> -#include <babeltrace/context-internal.h> -#include <babeltrace/babeltrace-internal.h> - -#ifdef __cplusplus -extern "C" { -#endif - -/* Parent trace descriptor */ -struct bt_trace_descriptor { - char path[PATH_MAX]; /* trace path */ - struct bt_context *ctx; - struct bt_trace_handle *handle; - struct trace_collection *collection; /* Container of this trace */ - GHashTable *clocks; - struct ctf_clock *single_clock; /* currently supports only one clock */ -}; - -#ifdef __cplusplus -} -#endif - -#endif /* _BABELTRACE_FORMAT_INTERNAL_H */ diff --git a/include/babeltrace/trace-descriptor-internal.h b/include/babeltrace/trace-descriptor-internal.h new file mode 100644 index 0000000..8ec23bb --- /dev/null +++ b/include/babeltrace/trace-descriptor-internal.h @@ -0,0 +1,55 @@ +#ifndef _BABELTRACE_TRACE_DESCRIPTOR_INTERNAL_H +#define _BABELTRACE_TRACE_DESCRIPTOR_INTERNAL_H + +/* + * BabelTrace + * + * Trace Descriptor Internal Header + * + * Copyright 2010-2013 EfficiOS Inc. and Linux Foundation + * + * Author: Mathieu Desnoyers <[email protected]> + * + * 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 <limits.h> +#include <babeltrace/context-internal.h> +#include <babeltrace/babeltrace-internal.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/* Parent trace descriptor */ +struct bt_trace_descriptor { + char path[PATH_MAX]; /* trace path */ + struct bt_context *ctx; + struct bt_trace_handle *handle; + struct trace_collection *collection; /* Container of this trace */ + GHashTable *clocks; + struct ctf_clock *single_clock; /* currently supports only one clock */ + GPtrArray *stream_pos; /* Pointers to bt_stream_pos */ +}; + +#ifdef __cplusplus +} +#endif + +#endif /* _BABELTRACE_TRACE_DESCRIPTOR_INTERNAL_H */ diff --git a/include/babeltrace/trace-descriptor.h b/include/babeltrace/trace-descriptor.h new file mode 100644 index 0000000..0ae4b8b --- /dev/null +++ b/include/babeltrace/trace-descriptor.h @@ -0,0 +1,53 @@ +#ifndef _BABELTRACE_TRACE_DESCRIPTOR_H +#define _BABELTRACE_TRACE_DESCRIPTOR_H + +/* + * BabelTrace + * + * Trace Descriptor Header + * + * Copyright 2013 EfficiOS Inc. and Linux Foundation + * + * Author: Jérémie Galarneau <[email protected]> + * + * 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 <glib.h> + +struct bt_trace_descriptor; + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * bt_trace_descriptor_get_stream_pos: Get the stream_pos array associated + * with descriptor's trace + * + * Return: Array of pointers to struct bt_stream_pos + */ +extern const GPtrArray *bt_trace_descriptor_get_stream_pos( + const struct bt_trace_descriptor *descriptor); + +#ifdef __cplusplus +} +#endif + +#endif /* _BABELTRACE_TRACE_DESCRIPTOR_H */ diff --git a/lib/Makefile.am b/lib/Makefile.am index 7ffb164..379688d 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -9,7 +9,8 @@ libbabeltrace_la_SOURCES = babeltrace.c \ context.c \ trace-handle.c \ trace-collection.c \ - registry.c + registry.c \ + trace-descriptor.c libbabeltrace_la_LDFLAGS = \ -Wl,--no-as-needed \ diff --git a/lib/trace-descriptor.c b/lib/trace-descriptor.c new file mode 100644 index 0000000..4001679 --- /dev/null +++ b/lib/trace-descriptor.c @@ -0,0 +1,42 @@ +/* + * trace-descriptor.c + * + * Babeltrace Library + * + * Copyright 2013 EfficiOS Inc. and Linux Foundation + * + * Author: Jérémie Galarneau <[email protected]> + * + * 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 <babeltrace/trace-descriptor-internal.h> + +const GPtrArray *bt_trace_descriptor_get_stream_pos( + const struct bt_trace_descriptor *descriptor) +{ + const GPtrArray *ret; + if (!descriptor) { + ret = NULL; + goto end; + } + ret = descriptor->stream_pos; +end: + return ret; +} -- 1.8.2.3 _______________________________________________ lttng-dev mailing list [email protected] http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
