Add intersect mode to python bindings
authorAntoine Busque <abusque@efficios.com>
Mon, 2 May 2016 18:59:07 +0000 (14:59 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 3 May 2016 19:42:41 +0000 (15:42 -0400)
Signed-off-by: Antoine Busque <abusque@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
bindings/python/babeltrace.i.in
bindings/python/python-complements.c
bindings/python/python-complements.h

index 3dc1791010dc4202b34cb1346ca1a64b0ec9b20d..914ea87f8e1456b28cfb1ea9a46d2be9586cbc5b 100644 (file)
@@ -100,6 +100,11 @@ const char *_bt_python_get_sequence_string(struct bt_definition *field);
 int _bt_python_field_integer_get_signedness(const struct bt_ctf_field *field);
 enum ctf_type_id _bt_python_get_field_type(const struct bt_ctf_field *field);
 struct bt_iter_pos *_bt_python_create_iter_pos(void);
+struct bt_ctf_iter *_bt_python_ctf_iter_create_intersect(
+        struct bt_context *ctx,
+        struct bt_iter_pos *inter_begin_pos,
+        struct bt_iter_pos *inter_end_pos);
+int _bt_python_has_intersection(struct bt_context *ctx);
 
 /* =================================================================
                CONTEXT.H, CONTEXT-INTERNAL.H
@@ -134,8 +139,9 @@ class TraceCollection:
        The TraceCollection is the object that contains all currently opened traces.
        """
 
-       def __init__(self):
+       def __init__(self, intersect_mode=False):
                self._tc = _bt_context_create()
+        self.intersect_mode = intersect_mode
 
        def __del__(self):
                _bt_context_put(self._tc)
@@ -226,8 +232,9 @@ class TraceCollection:
                """
                begin_pos_ptr = _bt_python_create_iter_pos()
                end_pos_ptr = _bt_python_create_iter_pos()
-               begin_pos_ptr.type = SEEK_BEGIN
-               end_pos_ptr.type = SEEK_LAST
+        if not self.intersection_mode:
+                   begin_pos_ptr.type = SEEK_BEGIN
+            end_pos_ptr.type = SEEK_LAST
 
                for event in self._events(begin_pos_ptr, end_pos_ptr):
                        yield event
@@ -277,7 +284,20 @@ class TraceCollection:
                return ev.timestamp
 
        def _events(self, begin_pos_ptr, end_pos_ptr):
-               ctf_it_ptr = _bt_ctf_iter_create(self._tc, begin_pos_ptr, end_pos_ptr)
+        if self.intersect_mode:
+            has_intersection = _bt_python_has_intersection(self._tc)
+            if not has_intersection:
+                # There are no events to provide.
+                return
+
+            ctf_it_ptr = _bt_python_ctf_iter_create_intersect(
+                self._tc, begin_pos_ptr, end_pos_ptr
+            )
+        else:
+            ctf_it_ptr = _bt_ctf_iter_create(
+                self._tc, begin_pos_ptr, end_pos_ptr
+            )
+
                if ctf_it_ptr is None:
                        raise NotImplementedError(
                                "Creation of multiple iterators is unsupported.")
@@ -803,7 +823,7 @@ class Event(collections.Mapping):
        def _field_list_with_scope(self, scope):
                fields = []
                scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
-               
+
                # Returns a list [list_ptr, count]. If list_ptr is NULL, SWIG will only
                # provide the "count" return value
                count = 0
index 52465aa229a83495ea2c46cba7d4be5559291042..6b47ff9bf9aaaaac16213b00e9cb854c9752b89f 100644 (file)
@@ -22,6 +22,8 @@
 #include <babeltrace/ctf-writer/event-types-internal.h>
 #include <babeltrace/ctf-writer/event-fields-internal.h>
 #include <babeltrace/iterator.h>
+#include <babeltrace/ctf/iterator.h>
+#include <babeltrace/ctf/events-internal.h>
 #include <glib.h>
 
 /* FILE functions
@@ -249,3 +251,22 @@ struct bt_iter_pos *_bt_python_create_iter_pos(void)
 {
        return g_new0(struct bt_iter_pos, 1);
 }
+
+struct bt_ctf_iter *_bt_python_ctf_iter_create_intersect(
+               struct bt_context *ctx,
+               struct bt_iter_pos *inter_begin_pos,
+               struct bt_iter_pos *inter_end_pos)
+{
+       return bt_ctf_iter_create_intersect(ctx, &inter_begin_pos,
+                       &inter_end_pos);
+}
+
+int _bt_python_has_intersection(struct bt_context *ctx)
+{
+       int ret;
+       uint64_t begin = 0, end = ULLONG_MAX;
+
+       ret = ctf_find_packets_intersection(ctx, &begin, &end);
+
+       return ret == 0 ? 1 : 0;
+}
index bd2259805cd9b4b15172a52e0b557f435c92266d..0e787d62d81eb81e1552463a67214b78f68e6191 100644 (file)
@@ -74,3 +74,8 @@ enum ctf_type_id _bt_python_get_field_type(const struct bt_ctf_field *field);
 
 /* iterator */
 struct bt_iter_pos *_bt_python_create_iter_pos(void);
+struct bt_ctf_iter *_bt_python_ctf_iter_create_intersect(
+               struct bt_context *ctx,
+               struct bt_iter_pos *inter_begin_pos,
+               struct bt_iter_pos *inter_end_pos);
+int _bt_python_has_intersection(struct bt_context *ctx);
This page took 0.037207 seconds and 4 git commands to generate.