API : list of events in the trace
authorJulien Desfossez <julien.desfossez@efficios.com>
Wed, 4 Apr 2012 00:14:56 +0000 (20:14 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 4 Apr 2012 00:14:56 +0000 (20:14 -0400)
This function exports the list of events enabled in a trace.

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
formats/ctf/metadata/ctf-visitor-generate-io-struct.c
include/babeltrace/ctf-ir/metadata.h
include/babeltrace/ctf/events-internal.h
include/babeltrace/ctf/events.h

index 65b4cf7643518b3b4362c8c314a0c43803bec837..91fc20c3972626a59075b13dcf72df981b30f2a3 100644 (file)
@@ -1617,6 +1617,16 @@ void ctf_close_trace(struct trace_descriptor *tdp)
                }
                g_ptr_array_free(td->streams, TRUE);
        }
+
+       if (td->event_declarations) {
+               for (i = 0; i < td->event_declarations->len; i++) {
+                       struct bt_ctf_event_decl *event;
+
+                       event = g_ptr_array_index(td->event_declarations, i);
+                       g_free(event);
+               }
+               g_ptr_array_free(td->event_declarations, TRUE);
+       }
        closedir(td->dir);
        g_free(td);
 }
index b33796bc2dfbc9580e46b57d88848de266445862..13c7411a1fe2c89e462cc0a686236be8dd0989fa 100644 (file)
@@ -441,3 +441,37 @@ char *bt_ctf_get_string(const struct definition *field)
 
        return ret;
 }
+
+int bt_ctf_get_event_decl_list(int handle_id, struct bt_context *ctx,
+               struct bt_ctf_event_decl const * const **list,
+               unsigned int *count)
+{
+       struct bt_trace_handle *handle;
+       struct trace_descriptor *td;
+       struct ctf_trace *tin;
+
+       if (!ctx)
+               goto error;
+
+       handle = g_hash_table_lookup(ctx->trace_handles,
+                       (gpointer) (unsigned long) handle_id);
+       if (!handle)
+               goto error;
+
+       td = handle->td;
+       tin = container_of(td, struct ctf_trace, parent);
+
+       *list = (struct bt_ctf_event_decl const* const*) tin->event_declarations->pdata;
+       *count = tin->event_declarations->len;
+       return 0;
+
+error:
+       return -1;
+}
+
+const char *bt_ctf_get_decl_event_name(const struct bt_ctf_event_decl *event)
+{
+       if (!event)
+               return NULL;
+       return g_quark_to_string(event->parent.name);
+}
index 4b399613585ebb81b9aa49d25c23583690483003..9ded71627a65af988bc23eb0ddce68c5f0024356 100644 (file)
@@ -30,6 +30,7 @@
 #include <babeltrace/ctf/metadata.h>
 #include <babeltrace/uuid.h>
 #include <babeltrace/endian.h>
+#include <babeltrace/ctf/events-internal.h>
 #include "ctf-scanner.h"
 #include "ctf-parser.h"
 #include "ctf-ast.h"
@@ -1742,8 +1743,10 @@ int ctf_event_visit(FILE *fd, int depth, struct ctf_node *node,
        int ret = 0;
        struct ctf_node *iter;
        struct ctf_event_declaration *event;
+       struct bt_ctf_event_decl *event_decl;
 
-       event = g_new0(struct ctf_event_declaration, 1);
+       event_decl = g_new0(struct bt_ctf_event_decl, 1);
+       event = &event_decl->parent;
        event->declaration_scope = new_declaration_scope(parent_declaration_scope);
        event->loglevel = -1;
        bt_list_for_each_entry(iter, &node->u.event.declaration_list, siblings) {
@@ -1787,6 +1790,7 @@ int ctf_event_visit(FILE *fd, int depth, struct ctf_node *node,
        g_hash_table_insert(event->stream->event_quark_to_id,
                            (gpointer) (unsigned long) event->name,
                            &event->id);
+       g_ptr_array_add(trace->event_declarations, event_decl);
        return 0;
 
 error:
@@ -1795,7 +1799,7 @@ error:
        if (event->context_decl)
                declaration_unref(&event->context_decl->p);
        free_declaration_scope(event->declaration_scope);
-       g_free(event);
+       g_free(event_decl);
        return ret;
 }
 
@@ -2128,6 +2132,7 @@ int ctf_trace_visit(FILE *fd, int depth, struct ctf_node *node, struct ctf_trace
                return -EEXIST;
        trace->declaration_scope = new_declaration_scope(trace->root_declaration_scope);
        trace->streams = g_ptr_array_new();
+       trace->event_declarations = g_ptr_array_new();
        bt_list_for_each_entry(iter, &node->u.trace.declaration_list, siblings) {
                ret = ctf_trace_declaration_visit(fd, depth + 1, iter, trace);
                if (ret)
@@ -2166,6 +2171,7 @@ error:
                trace->packet_header_decl = NULL;
        }
        g_ptr_array_free(trace->streams, TRUE);
+       g_ptr_array_free(trace->event_declarations, TRUE);
        free_declaration_scope(trace->declaration_scope);
        trace->declaration_scope = NULL;
        return ret;
index 7f2b06d6f75ebee5af0cad2f65ff7467174b4367..c18749f708906b84f6b01dde9f193d38322edec5 100644 (file)
@@ -140,6 +140,7 @@ struct ctf_trace {
        GHashTable *clocks;
        struct ctf_clock *single_clock;         /* currently supports only one clock */
        struct trace_collection *collection;    /* Container of this trace */
+       GPtrArray *event_declarations;          /* Array of all the struct bt_ctf_event_decl */
 
        struct declaration_struct *packet_header_decl;
 
index b01fda4bc199a483621aa9f6c428bc0c504eeb5a..56b7e6b9dbcbe42b79c5bdc214c43e8d4b31dbc6 100644 (file)
@@ -39,7 +39,7 @@ struct bt_ctf_event {
 };
 
 struct bt_ctf_event_decl {
-       struct ctf_event_declaration *parent;
+       struct ctf_event_declaration parent;
 };
 
 struct bt_ctf_iter {
index 80fbdcf2f5b634b9a720bec49c3aa8f69edd384e..73e6bc1aa9dc35cb23a14286f04d8e80773413c3 100644 (file)
  */
 
 #include <stdint.h>
+#include <babeltrace/context.h>
 
 struct definition;
 struct bt_ctf_event;
+struct bt_ctf_event_decl;
 
 /*
  * the top-level scopes in CTF
@@ -186,4 +188,19 @@ char *bt_ctf_get_string(const struct definition *field);
  */
 int bt_ctf_field_get_error(void);
 
+/*
+ * bt_ctf_get_event_decl_list: set list pointer to an array of bt_ctf_event_decl
+ * pointers and set count to the number of elements in the array.
+ *
+ * Return 0 on success and a negative value on error.
+ */
+int bt_ctf_get_event_decl_list(int handle_id, struct bt_context *ctx,
+               struct bt_ctf_event_decl const * const **list,
+               unsigned int *count);
+
+/*
+ * bt_ctf_get_decl_event_name: return the name of the event or NULL on error
+ */
+const char *bt_ctf_get_decl_event_name(const struct bt_ctf_event_decl *event);
+
 #endif /* _BABELTRACE_CTF_EVENTS_H */
This page took 0.041588 seconds and 4 git commands to generate.