API : trace_handle
authorJulien Desfossez <julien.desfossez@efficios.com>
Mon, 30 Jan 2012 22:25:50 +0000 (17:25 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 30 Jan 2012 22:25:50 +0000 (17:25 -0500)
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>
include/Makefile.am
include/babeltrace/context.h
include/babeltrace/trace-handle-internal.h [new file with mode: 0644]
include/babeltrace/trace-handle.h [new file with mode: 0644]
lib/Makefile.am
lib/context.c
lib/trace-handle.c [new file with mode: 0644]

index b5d26808ef76909a981b8d0b9e1dfcfec2b7c40a..1dfa218b27afd52258136b4c673707086513fef8 100644 (file)
@@ -2,7 +2,8 @@ babeltraceinclude_HEADERS = \
        babeltrace/babeltrace.h \
        babeltrace/format.h \
        babeltrace/context.h \
-       babeltrace/iterator.h
+       babeltrace/iterator.h \
+       babeltrace/trace-handle.h
 
 
 noinst_HEADERS = \
@@ -18,4 +19,5 @@ 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
index 55fe2313034db84476a1976fd7b2a3acbd084b12..445af4f39c609aaa98284e89a877476626b434ae 100644 (file)
@@ -35,6 +35,7 @@ struct trace_collection;
 struct bt_context {
        struct trace_collection *tc;
        int refcount;
+       int last_trace_handle_id;
 };
 
 /*
diff --git a/include/babeltrace/trace-handle-internal.h b/include/babeltrace/trace-handle-internal.h
new file mode 100644 (file)
index 0000000..9351367
--- /dev/null
@@ -0,0 +1,53 @@
+#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 */
diff --git a/include/babeltrace/trace-handle.h b/include/babeltrace/trace-handle.h
new file mode 100644 (file)
index 0000000..5900cc1
--- /dev/null
@@ -0,0 +1,53 @@
+#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 */
index cb3597d7622b7a99f9a1688d5a3c421b20515c82..26f024b447b4e50925389ccd99079cea4d4bd01e 100644 (file)
@@ -7,7 +7,8 @@ lib_LTLIBRARIES = libbabeltrace.la
 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 \
index 36efc9d0c9fc451bd88b598077335739aed4d336..48cf216e11780f99a20b6dea27264368c9c350c3 100644 (file)
@@ -35,6 +35,7 @@ struct bt_context *bt_context_create(struct trace_collection *tc)
 
        ctx->tc = tc;
        ctx->refcount = 1;
+       ctx->last_trace_handle_id = 0;
 
        return ctx;
 
diff --git a/lib/trace-handle.c b/lib/trace-handle.c
new file mode 100644 (file)
index 0000000..fce2397
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * 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;
+}
This page took 0.028296 seconds and 4 git commands to generate.