Add the trace_handle structure to allow the user to manipulate a trace.
Will be useful for getting information on specific trace files and
remove traces from a trace_collection without rebuilding the
trace_collection entirely.
Signed-off-by: Julien Desfossez <julien.desfossez@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
babeltrace/babeltrace.h \
babeltrace/format.h \
babeltrace/context.h \
- babeltrace/iterator.h
+ babeltrace/iterator.h \
+ babeltrace/trace-handle.h
noinst_HEADERS = \
babeltrace/ctf-ir/metadata.h \
babeltrace/ctf/metadata.h \
babeltrace/ctf-text/types.h \
- babeltrace/ctf/types.h
+ babeltrace/ctf/types.h \
+ babeltrace/trace-handle-internal.h
struct bt_context {
struct trace_collection *tc;
int refcount;
+ int last_trace_handle_id;
};
/*
--- /dev/null
+#ifndef _BABELTRACE_TRACE_HANDLE_INTERNAL_H
+#define _BABELTRACE_TRACE_HANDLE_INTERNAL_H
+
+/*
+ * BabelTrace
+ *
+ * Internal trace handle header
+ *
+ * Copyright 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 <stdint.h>
+#include <babeltrace/context.h>
+
+/*
+ * trace_handle : unique identifier of a trace
+ *
+ * The trace_handle allows the user to manipulate a trace file directly.
+ * It is a unique identifier representing a trace file.
+ */
+struct bt_trace_handle {
+ int id;
+ char *path;
+ uint64_t timestamp_begin;
+ uint64_t timestamp_end;
+};
+
+/*
+ * bt_trace_handle_create : allocates a trace_handle
+ *
+ * Returns a newly allocated trace_handle or NULL on error
+ */
+struct bt_trace_handle *bt_trace_create_handle(struct bt_context *ctx);
+
+/*
+ * bt_trace_handle_destroy : free a trace_handle
+ */
+void bt_trace_handle_destroy(struct bt_trace_handle *bt);
+
+#endif /* _BABELTRACE_TRACE_HANDLE_INTERNAL_H */
--- /dev/null
+#ifndef _BABELTRACE_TRACE_HANDLE_H
+#define _BABELTRACE_TRACE_HANDLE_H
+
+/*
+ * BabelTrace
+ *
+ * trace_handle header
+ *
+ * Copyright 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 <stdint.h>
+
+/*
+ * trace_handle : unique identifier of a trace
+ *
+ * The trace_handle allows the user to manipulate a trace file directly.
+ * It is a unique identifier representing a trace file.
+ */
+struct bt_trace_handle;
+
+/*
+ * bt_trace_handle_get_path : returns the path of a trace_handle or
+ * NULL on error
+ */
+char *bt_trace_handle_get_path(struct bt_trace_handle *th);
+
+/*
+ * bt_trace_handle_get_timestamp_begin : returns the beginning timestamp
+ * of a trace or -1ULL on error
+ */
+uint64_t bt_trace_handle_get_timestamp_begin(struct bt_trace_handle *th);
+
+/*
+ * bt_trace_handle_get_timestamp_end : returns the end timestamp of a trace
+ * or -1ULL on error
+ */
+uint64_t bt_trace_handle_get_timestamp_end(struct bt_trace_handle *th);
+
+#endif /* _BABELTRACE_TRACE_HANDLE_H */
libbabeltrace_la_SOURCES = babeltrace.c \
callbacks.c \
iterator.c \
- context.c
+ context.c \
+ trace-handle.c
libbabeltrace_la_LIBADD = \
$(top_builddir)/types/libbabeltrace_types.la \
ctx->tc = tc;
ctx->refcount = 1;
+ ctx->last_trace_handle_id = 0;
return ctx;
--- /dev/null
+/*
+ * trace_handle.c
+ *
+ * Babeltrace Library
+ *
+ * Copyright 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 <stdint.h>
+#include <stdlib.h>
+#include <babeltrace/babeltrace.h>
+#include <babeltrace/context.h>
+#include <babeltrace/trace-handle.h>
+#include <babeltrace/trace-handle-internal.h>
+
+struct bt_trace_handle *bt_trace_handle_create(struct bt_context *ctx)
+{
+ struct bt_trace_handle *th;
+
+ th = calloc(1, sizeof(struct bt_trace_handle));
+ if (!th) {
+ perror("allocating trace_handle");
+ return NULL;
+ }
+ if (!ctx)
+ return NULL;
+
+ th->id = ctx->last_trace_handle_id++;
+ return th;
+}
+
+void bt_trace_handle_destroy(struct bt_trace_handle *bt)
+{
+ if (bt)
+ free(bt);
+}
+
+char *bt_trace_handle_get_path(struct bt_trace_handle *th)
+{
+ if (th && th->path)
+ return th->path;
+ return NULL;
+}
+
+uint64_t bt_trace_handle_get_timestamp_begin(struct bt_trace_handle *th)
+{
+ if (th)
+ return th->timestamp_begin;
+ return -1ULL;
+}
+
+uint64_t bt_trace_handle_get_timestamp_end(struct bt_trace_handle *th)
+{
+ if (th)
+ return th->timestamp_end;
+ return -1ULL;
+}