API Fix : give access to trace_handle and context
authorJulien Desfossez <julien.desfossez@efficios.com>
Tue, 27 Mar 2012 13:12:46 +0000 (09:12 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 27 Mar 2012 13:12:46 +0000 (09:12 -0400)
When reading multiple traces, we need to know to which context or
trace_handle an event belongs to. Setting the context and trace_handle
is format agnostic, but reading it is not, so the reading part is only
implemented for CTF.

Signed-off-by: Julien Desfossez <julien.desfossez@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
formats/ctf/ctf.c
formats/ctf/events.c
include/babeltrace/context.h
include/babeltrace/ctf-ir/metadata.h
include/babeltrace/ctf/metadata.h
include/babeltrace/format.h
include/babeltrace/trace-handle.h
lib/context.c

index 8608b5a1b68c95115b4d499215baed1076ea441e..2965f496f2fc7a0ae51d55519975cf5257e00f7a 100644 (file)
@@ -23,6 +23,8 @@
 #include <babeltrace/ctf/metadata.h>
 #include <babeltrace/babeltrace-internal.h>
 #include <babeltrace/ctf/events-internal.h>
+#include <babeltrace/trace-handle-internal.h>
+#include <babeltrace/context-internal.h>
 #include <babeltrace/uuid.h>
 #include <babeltrace/endian.h>
 #include <inttypes.h>
@@ -76,6 +78,12 @@ struct trace_descriptor *ctf_open_mmap_trace(
                void (*packet_seek)(struct stream_pos *pos, size_t index,
                        int whence),
                FILE *metadata_fp);
+static
+void ctf_set_context(struct trace_descriptor *descriptor,
+               struct bt_context *ctx);
+static
+void ctf_set_handle(struct trace_descriptor *descriptor,
+               struct bt_trace_handle *handle);
 
 static
 void ctf_close_trace(struct trace_descriptor *descriptor);
@@ -109,6 +117,8 @@ struct format ctf_format = {
        .open_trace = ctf_open_trace,
        .open_mmap_trace = ctf_open_mmap_trace,
        .close_trace = ctf_close_trace,
+       .set_context = ctf_set_context,
+       .set_handle = ctf_set_handle,
 };
 
 /*
@@ -1610,6 +1620,26 @@ void ctf_close_trace(struct trace_descriptor *tdp)
        g_free(td);
 }
 
+static
+void ctf_set_context(struct trace_descriptor *descriptor,
+               struct bt_context *ctx)
+{
+       struct ctf_trace *td = container_of(descriptor, struct ctf_trace,
+                       parent);
+
+       td->ctx = ctx;
+}
+
+static
+void ctf_set_handle(struct trace_descriptor *descriptor,
+               struct bt_trace_handle *handle)
+{
+       struct ctf_trace *td = container_of(descriptor, struct ctf_trace,
+                       parent);
+
+       td->handle = handle;
+}
+
 void __attribute__((constructor)) ctf_init(void)
 {
        int ret;
index ebc4f1b057143d046ccee603b11e5da2eafabdd7..be90d841acbcc5bc05fbc6a6bf1dda2423a15008 100644 (file)
@@ -251,6 +251,46 @@ error:
        return -1;
 }
 
+struct bt_context *bt_ctf_event_get_context(const struct bt_ctf_event *event)
+{
+       struct bt_context *ret = NULL;
+       struct ctf_file_stream *cfs;
+       struct ctf_stream *stream;
+       struct ctf_stream_class *stream_class;
+       struct ctf_trace *trace;
+
+       cfs = container_of(event->stream, struct ctf_file_stream,
+                       parent);
+       stream = &cfs->parent;
+       stream_class = stream->stream_class;
+       trace = stream_class->trace;
+
+       if (trace->ctx)
+               ret = trace->ctx;
+
+       return ret;
+}
+
+int bt_ctf_event_get_handle_id(const struct bt_ctf_event *event)
+{
+       int ret = -1;
+       struct ctf_file_stream *cfs;
+       struct ctf_stream *stream;
+       struct ctf_stream_class *stream_class;
+       struct ctf_trace *trace;
+
+       cfs = container_of(event->stream, struct ctf_file_stream,
+                       parent);
+       stream = &cfs->parent;
+       stream_class = stream->stream_class;
+       trace = stream_class->trace;
+
+       if (trace->handle)
+               ret = trace->handle->id;
+
+       return ret;
+}
+
 uint64_t bt_ctf_get_timestamp_raw(const struct bt_ctf_event *event)
 {
        if (event && event->stream->has_timestamp)
index 591c9cad029757951dc642d1631d9914fd8ef22a..4a85ff9966162aefa6c61b757ff510a62a659dec 100644 (file)
@@ -29,6 +29,7 @@
 /* struct bt_context is opaque to the user */
 struct bt_context;
 struct stream_pos;
+struct bt_ctf_event;
 
 /*
  * bt_context_create : create a Babeltrace context
@@ -96,4 +97,11 @@ void bt_context_remove_trace(struct bt_context *ctx, int trace_id);
 void bt_context_get(struct bt_context *ctx);
 void bt_context_put(struct bt_context *ctx);
 
+/*
+ * bt_ctf_get_context : get the context associated with an event
+ *
+ * Returns NULL on error
+ */
+struct bt_context *bt_ctf_event_get_context(const struct bt_ctf_event *event);
+
 #endif /* _BABELTRACE_CONTEXT_H */
index a36dc89af8d4096f73421ce5ad266f4e14c124ab..024b50f1c4daed84e7d0cfe3c06822488dd365c3 100644 (file)
@@ -166,6 +166,9 @@ struct ctf_trace {
        /* Heap of streams, ordered to always get the lowest timestam */
        struct ptr_heap *stream_heap;
        char path[PATH_MAX];
+
+       struct bt_context *ctx;
+       struct bt_trace_handle *handle;
 };
 
 #define CTF_STREAM_SET_FIELD(ctf_stream, field)                                \
index de8a1a8e62f5798d943be2749de42189b617f432..82b017086f9a0056e2a5d4c229db0aaab1941012 100644 (file)
@@ -23,6 +23,8 @@
 #include <babeltrace/format.h>
 #include <babeltrace/ctf/types.h>
 #include <babeltrace/ctf-ir/metadata.h>
+#include <babeltrace/trace-handle-internal.h>
+#include <babeltrace/context-internal.h>
 #include <sys/types.h>
 #include <dirent.h>
 #include <assert.h>
index 8eae42c0e2aa7f3405969f785987216986d485d5..b67dd5dc77298d434557f3fe3afe00a1bbd8e8cd 100644 (file)
@@ -29,6 +29,8 @@ typedef int bt_intern_str;
 
 /* forward declaration */
 struct stream_pos;
+struct bt_context;
+struct bt_trace_handle;
 
 /* Parent trace descriptor */
 struct trace_descriptor {
@@ -56,6 +58,10 @@ struct format {
                                size_t index, int whence),
                        FILE *metadata_fp);
        void (*close_trace)(struct trace_descriptor *descriptor);
+       void (*set_context)(struct trace_descriptor *descriptor,
+                       struct bt_context *ctx);
+       void (*set_handle)(struct trace_descriptor *descriptor,
+                       struct bt_trace_handle *handle);
 };
 
 extern struct format *bt_lookup_format(bt_intern_str qname);
index d188cb70f8367eefa6dab74be5842dc9c4e5d6f4..31877ee1886a681165d25fdd9d2b2b94e9252af9 100644 (file)
@@ -31,6 +31,7 @@
  * It is a unique identifier representing a trace file.
  */
 struct bt_trace_handle;
+struct bt_ctf_event;
 
 /*
  * bt_trace_handle_get_path : returns the path of a trace_handle.
@@ -49,4 +50,11 @@ uint64_t bt_trace_handle_get_timestamp_begin(struct bt_context *ctx, int handle_
  */
 uint64_t bt_trace_handle_get_timestamp_end(struct bt_context *ctx, int handle_id);
 
+/*
+ * bt_ctf_event_get_handle_id : get the handle id associated with an event
+ *
+ * Returns -1 on error
+ */
+int bt_ctf_event_get_handle_id(const struct bt_ctf_event *event);
+
 #endif /* _BABELTRACE_TRACE_HANDLE_H */
index e9a35c1d5844f7be8c0983eb86b240901b58efd8..dbab33754cab346ba6c8a2054d72398338ffde23 100644 (file)
@@ -107,6 +107,11 @@ int bt_context_add_trace(struct bt_context *ctx, const char *path,
        strncpy(handle->path, path, PATH_MAX);
        handle->path[PATH_MAX - 1] = '\0';
 
+       if (fmt->set_handle)
+               fmt->set_handle(td, handle);
+       if (fmt->set_context)
+               fmt->set_context(td, ctx);
+
        /* Add new handle to container */
        g_hash_table_insert(ctx->trace_handles,
                (gpointer) (unsigned long) handle->id,
This page took 0.0293 seconds and 4 git commands to generate.