From: Mathieu Desnoyers Date: Fri, 17 Feb 2012 19:21:41 +0000 (-0500) Subject: fix: move read event from iterator to event.h X-Git-Tag: v1.0.0-pre1~10 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=e419579102094d83539d79ce6af83d9786d387ee;hp=5c5facc70af60670ec8f53b9d90d13722a8477f4 fix: move read event from iterator to event.h because it is CTF-specific. Need to move the format registry to libbabeltrace due to cross-dependencies between libbabeltrace and formats. Now, the format libs depend on libbabeltrace, never the opposite. Signed-off-by: Mathieu Desnoyers --- diff --git a/Makefile.am b/Makefile.am index 0a9bb9ab..074e17d1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,7 +2,7 @@ AM_CFLAGS = $(PACKAGE_CFLAGS) -I$(top_srcdir)/include ACLOCAL_AMFLAGS = -I m4 -SUBDIRS = include types formats lib converter tests doc +SUBDIRS = include types lib formats converter tests doc dist_doc_DATA = ChangeLog LICENSE mit-license.txt gpl-2.0.txt \ std-ext-lib.txt diff --git a/converter/Makefile.am b/converter/Makefile.am index 2b16f1e4..9443c214 100644 --- a/converter/Makefile.am +++ b/converter/Makefile.am @@ -13,7 +13,6 @@ babeltrace_SOURCES = \ babeltrace_LDFLAGS = -Wl,--no-as-needed babeltrace_LDADD = \ $(top_builddir)/lib/libbabeltrace.la \ - $(top_builddir)/formats/libbabeltrace_registry.la \ $(top_builddir)/formats/ctf/libctf.la \ $(top_builddir)/formats/ctf/metadata/libctf-ast.la \ $(top_builddir)/formats/ctf-text/libctf-text.la \ @@ -22,5 +21,5 @@ babeltrace_LDADD = \ babeltrace_log_SOURCES = babeltrace-log.c babeltrace_log_LDADD = \ - $(top_builddir)/formats/libbabeltrace_registry.la \ + $(top_builddir)/lib/libbabeltrace.la \ $(top_builddir)/formats/ctf/libctf.la diff --git a/converter/babeltrace.c b/converter/babeltrace.c index 5bcfc2a7..baffb195 100644 --- a/converter/babeltrace.c +++ b/converter/babeltrace.c @@ -401,7 +401,7 @@ error: int convert_trace(struct trace_descriptor *td_write, struct bt_context *ctx) { - struct bt_iter *iter; + struct bt_ctf_iter *iter; struct ctf_text_stream_pos *sout; struct bt_iter_pos begin_pos; struct bt_ctf_event *ctf_event; @@ -411,25 +411,25 @@ int convert_trace(struct trace_descriptor *td_write, trace_descriptor); begin_pos.type = BT_SEEK_BEGIN; - iter = bt_iter_create(ctx, &begin_pos, NULL); + iter = bt_ctf_iter_create(ctx, &begin_pos, NULL); if (!iter) { ret = -1; goto error_iter; } - while ((ctf_event = bt_iter_read_ctf_event(iter))) { + while ((ctf_event = bt_ctf_iter_read_event(iter))) { ret = sout->parent.event_cb(&sout->parent, ctf_event->stream); if (ret) { fprintf(stderr, "[error] Writing event failed.\n"); goto end; } - ret = bt_iter_next(iter); + ret = bt_iter_next(bt_ctf_get_iter(iter)); if (ret < 0) goto end; } ret = 0; end: - bt_iter_destroy(iter); + bt_ctf_iter_destroy(iter); error_iter: return ret; } diff --git a/formats/Makefile.am b/formats/Makefile.am index 7f95fcc5..ee3a6eda 100644 --- a/formats/Makefile.am +++ b/formats/Makefile.am @@ -1,7 +1,3 @@ AM_CFLAGS = $(PACKAGE_CFLAGS) -I$(top_srcdir)/include SUBDIRS = . ctf ctf-text bt-dummy - -lib_LTLIBRARIES = libbabeltrace_registry.la - -libbabeltrace_registry_la_SOURCES = registry.c diff --git a/formats/bt-dummy/Makefile.am b/formats/bt-dummy/Makefile.am index 50ef9098..016ffad9 100644 --- a/formats/bt-dummy/Makefile.am +++ b/formats/bt-dummy/Makefile.am @@ -6,4 +6,4 @@ libbt_dummy_la_SOURCES = \ bt-dummy.c libbt_dummy_la_LIBADD = \ - ../libbabeltrace_registry.la + $(top_builddir)/lib/libbabeltrace.la diff --git a/formats/bt-dummy/bt-dummy.c b/formats/bt-dummy/bt-dummy.c index e251ee7b..e0a10c90 100644 --- a/formats/bt-dummy/bt-dummy.c +++ b/formats/bt-dummy/bt-dummy.c @@ -32,8 +32,7 @@ #include static -int bt_dummy_write_event(struct stream_pos *ppos, - struct ctf_stream *stream) +int bt_dummy_write_event(struct stream_pos *ppos, struct ctf_stream *stream) { return 0; } diff --git a/formats/ctf-text/Makefile.am b/formats/ctf-text/Makefile.am index 8db9f39a..ca033e05 100644 --- a/formats/ctf-text/Makefile.am +++ b/formats/ctf-text/Makefile.am @@ -9,4 +9,4 @@ libctf_text_la_SOURCES = \ libctf_text_la_LIBADD = \ types/libctf-text-types.la \ - ../libbabeltrace_registry.la + $(top_builddir)/lib/libbabeltrace.la diff --git a/formats/ctf-text/ctf-text.c b/formats/ctf-text/ctf-text.c index 20e18e86..bf028615 100644 --- a/formats/ctf-text/ctf-text.c +++ b/formats/ctf-text/ctf-text.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -211,8 +212,8 @@ const char *print_loglevel(int value) } static -int ctf_text_write_event(struct stream_pos *ppos, - struct ctf_stream *stream) +int ctf_text_write_event(struct stream_pos *ppos, struct ctf_stream *stream) + { struct ctf_text_stream_pos *pos = container_of(ppos, struct ctf_text_stream_pos, parent); diff --git a/formats/ctf/Makefile.am b/formats/ctf/Makefile.am index c9faac8b..cf01be4b 100644 --- a/formats/ctf/Makefile.am +++ b/formats/ctf/Makefile.am @@ -12,4 +12,4 @@ libctf_la_LIBADD = \ types/libctf-types.la \ metadata/libctf-parser.la \ metadata/libctf-ast.la \ - ../libbabeltrace_registry.la + $(top_builddir)/lib/libbabeltrace.la diff --git a/formats/ctf/ctf.c b/formats/ctf/ctf.c index 17f299c3..83680cd6 100644 --- a/formats/ctf/ctf.c +++ b/formats/ctf/ctf.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include diff --git a/formats/ctf/events.c b/formats/ctf/events.c index 5ac74e6e..27643fcb 100644 --- a/formats/ctf/events.c +++ b/formats/ctf/events.c @@ -23,6 +23,10 @@ #include #include #include +#include +#include +#include +#include #include /* @@ -32,6 +36,58 @@ */ __thread int bt_ctf_last_field_error = 0; +struct bt_ctf_iter *bt_ctf_iter_create(struct bt_context *ctx, + struct bt_iter_pos *begin_pos, + struct bt_iter_pos *end_pos) +{ + struct bt_ctf_iter *iter; + int ret; + + iter = g_new0(struct bt_ctf_iter, 1); + ret = bt_iter_init(&iter->parent, ctx, begin_pos, end_pos); + if (ret) { + g_free(iter); + return NULL; + } + return iter; +} + +void bt_ctf_iter_destroy(struct bt_ctf_iter *iter) +{ + bt_iter_fini(&iter->parent); + g_free(iter); +} + +struct bt_iter *bt_ctf_get_iter(struct bt_ctf_iter *iter) +{ + return &iter->parent; +} + +struct bt_ctf_event *bt_ctf_iter_read_event(struct bt_ctf_iter *iter) +{ + struct ctf_file_stream *file_stream; + struct bt_ctf_event *ret = &iter->current_ctf_event; + + file_stream = heap_maximum(iter->parent.stream_heap); + if (!file_stream) { + /* end of file for all streams */ + goto stop; + } + ret->stream = &file_stream->parent; + ret->event = g_ptr_array_index(ret->stream->events_by_id, + ret->stream->event_id); + + if (ret->stream->stream_id > iter->parent.callbacks->len) + goto end; + + process_callbacks(&iter->parent, ret->stream); + +end: + return ret; +stop: + return NULL; +} + struct definition *bt_ctf_get_top_level_scope(struct bt_ctf_event *event, enum bt_ctf_scope scope) { diff --git a/formats/registry.c b/formats/registry.c deleted file mode 100644 index 829ede9d..00000000 --- a/formats/registry.c +++ /dev/null @@ -1,102 +0,0 @@ -/* - * BabelTrace - * - * Format Registry - * - * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation - * - * Author: Mathieu Desnoyers - * - * 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. - */ - -#include -#include -#include -#include -#include - -struct walk_data { - FILE *fp; - int iter; -}; - -static int init_done; -void __attribute__((constructor)) format_init(void); -void __attribute__((destructor)) format_finalize(void); - -/* - * Format registry hash table contains the registered formats. Format - * registration is typically performed by a format plugin. - * TODO: support plugin unload (unregistration of formats). - */ -GHashTable *format_registry; - -struct format *bt_lookup_format(bt_intern_str name) -{ - if (!init_done) - return NULL; - return g_hash_table_lookup(format_registry, - (gconstpointer) (unsigned long) name); -} - -static void show_format(gpointer key, gpointer value, gpointer user_data) -{ - struct walk_data *data = user_data; - - fprintf(data->fp, "%s%s", data->iter ? ", " : "", - g_quark_to_string((GQuark) (unsigned long) key)); - data->iter++; -} - -void bt_fprintf_format_list(FILE *fp) -{ - struct walk_data data; - - data.fp = fp; - data.iter = 0; - - fprintf(fp, "Formats available: "); - if (!init_done) - return; - g_hash_table_foreach(format_registry, show_format, &data); - if (data.iter == 0) - fprintf(fp, ""); - fprintf(fp, ".\n"); -} - -int bt_register_format(struct format *format) -{ - if (!init_done) - format_init(); - - if (bt_lookup_format(format->name)) - return -EEXIST; - - g_hash_table_insert(format_registry, - (gpointer) (unsigned long) format->name, - format); - return 0; -} - -void format_init(void) -{ - if (init_done) - return; - format_registry = g_hash_table_new(g_direct_hash, g_direct_equal); - assert(format_registry); - init_done = 1; -} - -void format_finalize(void) -{ - g_hash_table_destroy(format_registry); -} diff --git a/include/Makefile.am b/include/Makefile.am index fea3c259..f4e410d5 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -21,6 +21,7 @@ noinst_HEADERS = \ babeltrace/prio_heap.h \ babeltrace/types.h \ babeltrace/ctf-ir/metadata.h \ + babeltrace/ctf/events-internal.h \ babeltrace/ctf/metadata.h \ babeltrace/ctf-text/types.h \ babeltrace/ctf/types.h \ diff --git a/include/babeltrace/ctf/events-internal.h b/include/babeltrace/ctf/events-internal.h new file mode 100644 index 00000000..deff1058 --- /dev/null +++ b/include/babeltrace/ctf/events-internal.h @@ -0,0 +1,33 @@ +#ifndef _BABELTRACE_CTF_EVENTS_INTERNAL_H +#define _BABELTRACE_CTF_EVENTS_INTERNAL_H + +/* + * BabelTrace + * + * CTF events API (internal) + * + * Copyright 2011-2012 EfficiOS Inc. and Linux Foundation + * + * Author: Mathieu Desnoyers + * Julien Desfossez + * + * 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. + */ + +#include + +struct bt_ctf_iter { + struct bt_iter parent; + struct bt_ctf_event current_ctf_event; /* last read event */ +}; + +#endif /*_BABELTRACE_CTF_EVENTS_INTERNAL_H */ diff --git a/include/babeltrace/ctf/events.h b/include/babeltrace/ctf/events.h index f2ef22df..61e3f6a3 100644 --- a/include/babeltrace/ctf/events.h +++ b/include/babeltrace/ctf/events.h @@ -24,10 +24,12 @@ */ #include +#include struct ctf_stream; struct ctf_stream_event; struct definition; +struct bt_ctf_iter; /* * the top-level scopes in CTF @@ -66,6 +68,42 @@ struct bt_ctf_event { struct ctf_stream_event *event; }; +/* + * bt_ctf_iter_read_event: Read the iterator's current event data. + * + * @iter: trace collection iterator (input) + * @stream: stream containing event at current position (output) + * @event: current event (output) + * Return 0 on success, negative error value on error. + */ +struct bt_ctf_event *bt_ctf_iter_read_event(struct bt_ctf_iter *iter); + +/* + * bt_ctf_iter_create - Allocate a CTF trace collection iterator. + * + * begin_pos and end_pos are optional parameters to specify the position + * at which the trace collection should be seeked upon iterator + * creation, and the position at which iteration will start returning + * "EOF". + * + * By default, if begin_pos is NULL, a BT_SEEK_CUR is performed at + * creation. By default, if end_pos is NULL, a BT_SEEK_END (end of + * trace) is the EOF criterion. + */ +struct bt_ctf_iter *bt_ctf_iter_create(struct bt_context *ctx, + struct bt_iter_pos *begin_pos, + struct bt_iter_pos *end_pos); + +/* + * bt_ctf_get_iter - get iterator from ctf iterator. + */ +struct bt_iter *bt_ctf_get_iter(struct bt_ctf_iter *iter); + +/* + * bt_ctf_iter_destroy - Free a CTF trace collection iterator. + */ +void bt_ctf_iter_destroy(struct bt_ctf_iter *iter); + /* * bt_ctf_get_top_level_scope: return a definition of the top-level scope * diff --git a/include/babeltrace/iterator-internal.h b/include/babeltrace/iterator-internal.h index 121d0dcc..c9b5d607 100644 --- a/include/babeltrace/iterator-internal.h +++ b/include/babeltrace/iterator-internal.h @@ -21,6 +21,7 @@ * all copies or substantial portions of the Software. */ +#include #include /* @@ -31,7 +32,6 @@ struct bt_iter { struct ptr_heap *stream_heap; struct bt_context *ctx; struct bt_iter_pos *end_pos; - struct bt_ctf_event current_ctf_event; /* last read event */ GArray *callbacks; /* Array of struct bt_stream_callbacks */ struct bt_callback_chain main_callbacks; /* For all events */ /* @@ -51,4 +51,10 @@ struct bt_iter { GPtrArray *dep_gc; }; +int bt_iter_init(struct bt_iter *iter, + struct bt_context *ctx, + struct bt_iter_pos *begin_pos, + struct bt_iter_pos *end_pos); +void bt_iter_fini(struct bt_iter *iter); + #endif /* _BABELTRACE_ITERATOR_INTERNAL_H */ diff --git a/include/babeltrace/iterator.h b/include/babeltrace/iterator.h index 3dcf0825..e9719fc8 100644 --- a/include/babeltrace/iterator.h +++ b/include/babeltrace/iterator.h @@ -19,7 +19,6 @@ #include #include -#include /* Forward declarations */ struct bt_iter; @@ -107,14 +106,4 @@ int bt_iter_set_pos(struct bt_iter *iter, const struct bt_iter_pos *pos); struct bt_iter_pos *bt_iter_create_time_pos(struct bt_iter *iter, uint64_t timestamp); -/* - * bt_iter_read_ctf_event: Read the iterator's current event data. - * - * @iter: trace collection iterator (input) - * @stream: stream containing event at current position (output) - * @event: current event (output) - * Return 0 on success, negative error value on error. - */ -struct bt_ctf_event *bt_iter_read_ctf_event(struct bt_iter *iter); - #endif /* _BABELTRACE_ITERATOR_H */ diff --git a/lib/Makefile.am b/lib/Makefile.am index fa591aef..5d069a96 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -9,10 +9,9 @@ libbabeltrace_la_SOURCES = babeltrace.c \ iterator.c \ context.c \ trace-handle.c \ - trace-collection.c + trace-collection.c \ + registry.c libbabeltrace_la_LIBADD = \ $(top_builddir)/types/libbabeltrace_types.la \ - $(top_builddir)/formats/libbabeltrace_registry.la \ - $(top_builddir)/formats/ctf/libctf.la \ prio_heap/libprio_heap.la diff --git a/lib/iterator.c b/lib/iterator.c index 398b097b..bf87193a 100644 --- a/lib/iterator.c +++ b/lib/iterator.c @@ -23,10 +23,10 @@ #include #include #include -#include #include #include #include +#include #include #include @@ -435,15 +435,14 @@ end: return ret; } -struct bt_iter *bt_iter_create(struct bt_context *ctx, +int bt_iter_init(struct bt_iter *iter, + struct bt_context *ctx, struct bt_iter_pos *begin_pos, struct bt_iter_pos *end_pos) { int i, stream_id; int ret = 0; - struct bt_iter *iter; - iter = g_new0(struct bt_iter, 1); iter->stream_heap = g_new(struct ptr_heap, 1); iter->end_pos = end_pos; iter->callbacks = g_array_new(0, 1, sizeof(struct bt_stream_callbacks)); @@ -498,17 +497,32 @@ struct bt_iter *bt_iter_create(struct bt_context *ctx, } } - return iter; + return 0; error: heap_free(iter->stream_heap); error_heap_init: g_free(iter->stream_heap); - g_free(iter); - return NULL; + return ret; } -void bt_iter_destroy(struct bt_iter *iter) +struct bt_iter *bt_iter_create(struct bt_context *ctx, + struct bt_iter_pos *begin_pos, + struct bt_iter_pos *end_pos) +{ + struct bt_iter *iter; + int ret; + + iter = g_new0(struct bt_iter, 1); + ret = bt_iter_init(iter, ctx, begin_pos, end_pos); + if (ret) { + g_free(iter); + return NULL; + } + return iter; +} + +void bt_iter_fini(struct bt_iter *iter) { struct bt_stream_callbacks *bt_stream_cb; struct bt_callback_chain *bt_chain; @@ -540,7 +554,11 @@ void bt_iter_destroy(struct bt_iter *iter) } bt_context_put(iter->ctx); +} +void bt_iter_destroy(struct bt_iter *iter) +{ + bt_iter_fini(iter); g_free(iter); } @@ -572,28 +590,3 @@ int bt_iter_next(struct bt_iter *iter) end: return ret; } - -struct bt_ctf_event *bt_iter_read_ctf_event(struct bt_iter *iter) -{ - struct ctf_file_stream *file_stream; - struct bt_ctf_event *ret = &iter->current_ctf_event; - - file_stream = heap_maximum(iter->stream_heap); - if (!file_stream) { - /* end of file for all streams */ - goto stop; - } - ret->stream = &file_stream->parent; - ret->event = g_ptr_array_index(ret->stream->events_by_id, - ret->stream->event_id); - - if (ret->stream->stream_id > iter->callbacks->len) - goto end; - - process_callbacks(iter, ret->stream); - -end: - return ret; -stop: - return NULL; -} diff --git a/lib/registry.c b/lib/registry.c new file mode 100644 index 00000000..829ede9d --- /dev/null +++ b/lib/registry.c @@ -0,0 +1,102 @@ +/* + * BabelTrace + * + * Format Registry + * + * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation + * + * Author: Mathieu Desnoyers + * + * 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. + */ + +#include +#include +#include +#include +#include + +struct walk_data { + FILE *fp; + int iter; +}; + +static int init_done; +void __attribute__((constructor)) format_init(void); +void __attribute__((destructor)) format_finalize(void); + +/* + * Format registry hash table contains the registered formats. Format + * registration is typically performed by a format plugin. + * TODO: support plugin unload (unregistration of formats). + */ +GHashTable *format_registry; + +struct format *bt_lookup_format(bt_intern_str name) +{ + if (!init_done) + return NULL; + return g_hash_table_lookup(format_registry, + (gconstpointer) (unsigned long) name); +} + +static void show_format(gpointer key, gpointer value, gpointer user_data) +{ + struct walk_data *data = user_data; + + fprintf(data->fp, "%s%s", data->iter ? ", " : "", + g_quark_to_string((GQuark) (unsigned long) key)); + data->iter++; +} + +void bt_fprintf_format_list(FILE *fp) +{ + struct walk_data data; + + data.fp = fp; + data.iter = 0; + + fprintf(fp, "Formats available: "); + if (!init_done) + return; + g_hash_table_foreach(format_registry, show_format, &data); + if (data.iter == 0) + fprintf(fp, ""); + fprintf(fp, ".\n"); +} + +int bt_register_format(struct format *format) +{ + if (!init_done) + format_init(); + + if (bt_lookup_format(format->name)) + return -EEXIST; + + g_hash_table_insert(format_registry, + (gpointer) (unsigned long) format->name, + format); + return 0; +} + +void format_init(void) +{ + if (init_done) + return; + format_registry = g_hash_table_new(g_direct_hash, g_direct_equal); + assert(format_registry); + init_done = 1; +} + +void format_finalize(void) +{ + g_hash_table_destroy(format_registry); +}