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 <mathieu.desnoyers@efficios.com>
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
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 \
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
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;
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;
}
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
bt-dummy.c
libbt_dummy_la_LIBADD = \
- ../libbabeltrace_registry.la
+ $(top_builddir)/lib/libbabeltrace.la
#include <stdlib.h>
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;
}
libctf_text_la_LIBADD = \
types/libctf-text-types.la \
- ../libbabeltrace_registry.la
+ $(top_builddir)/lib/libbabeltrace.la
#include <babeltrace/ctf-text/types.h>
#include <babeltrace/ctf/metadata.h>
#include <babeltrace/babeltrace-internal.h>
+#include <babeltrace/ctf/events-internal.h>
#include <inttypes.h>
#include <uuid/uuid.h>
#include <sys/mman.h>
}
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);
types/libctf-types.la \
metadata/libctf-parser.la \
metadata/libctf-ast.la \
- ../libbabeltrace_registry.la
+ $(top_builddir)/lib/libbabeltrace.la
#include <babeltrace/ctf/types.h>
#include <babeltrace/ctf/metadata.h>
#include <babeltrace/babeltrace-internal.h>
+#include <babeltrace/ctf/events-internal.h>
#include <inttypes.h>
#include <stdio.h>
#include <uuid/uuid.h>
#include <babeltrace/format.h>
#include <babeltrace/ctf/events.h>
#include <babeltrace/ctf-ir/metadata.h>
+#include <babeltrace/prio_heap.h>
+#include <babeltrace/iterator-internal.h>
+#include <babeltrace/ctf/events-internal.h>
+#include <babeltrace/ctf/metadata.h>
#include <glib.h>
/*
*/
__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)
{
+++ /dev/null
-/*
- * BabelTrace
- *
- * Format Registry
- *
- * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation
- *
- * Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- *
- * 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 <babeltrace/format.h>
-#include <glib.h>
-#include <errno.h>
-#include <stdio.h>
-#include <assert.h>
-
-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, "<none>");
- 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);
-}
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 \
--- /dev/null
+#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 <mathieu.desnoyers@efficios.com>
+ * Julien Desfossez <julien.desfossez@efficios.com>
+ *
+ * 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 <babeltrace/iterator-internal.h>
+
+struct bt_ctf_iter {
+ struct bt_iter parent;
+ struct bt_ctf_event current_ctf_event; /* last read event */
+};
+
+#endif /*_BABELTRACE_CTF_EVENTS_INTERNAL_H */
*/
#include <stdint.h>
+#include <babeltrace/iterator.h>
struct ctf_stream;
struct ctf_stream_event;
struct definition;
+struct bt_ctf_iter;
/*
* the top-level scopes in CTF
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
*
* all copies or substantial portions of the Software.
*/
+#include <babeltrace/callbacks-internal.h>
#include <babeltrace/ctf/events.h>
/*
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 */
/*
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 */
#include <babeltrace/format.h>
#include <babeltrace/context.h>
-#include <babeltrace/ctf/events.h>
/* Forward declarations */
struct bt_iter;
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 */
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
#include <babeltrace/callbacks-internal.h>
#include <babeltrace/context.h>
#include <babeltrace/context-internal.h>
-#include <babeltrace/ctf/metadata.h>
#include <babeltrace/iterator-internal.h>
#include <babeltrace/iterator.h>
#include <babeltrace/prio_heap.h>
+#include <babeltrace/ctf/metadata.h>
#include <babeltrace/ctf/events.h>
#include <inttypes.h>
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));
}
}
- 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;
}
bt_context_put(iter->ctx);
+}
+void bt_iter_destroy(struct bt_iter *iter)
+{
+ bt_iter_fini(iter);
g_free(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;
-}
--- /dev/null
+/*
+ * BabelTrace
+ *
+ * Format Registry
+ *
+ * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation
+ *
+ * Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * 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 <babeltrace/format.h>
+#include <glib.h>
+#include <errno.h>
+#include <stdio.h>
+#include <assert.h>
+
+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, "<none>");
+ 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);
+}