Fix: missing paragraph in python bindings license (MIT)
[babeltrace.git] / bindings / python / examples / sequence_test.py
index 403bdabf5efacdb86ce7e7b46a2052f2cfcacc74..8bd2c749c026a8f9266683c12915e4ad05fcc5c4 100644 (file)
 #
 # The above copyright notice and this permission notice shall be included in
 # all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
 
 # This example uses the babeltrace python module
 # to partially test the sequence API
@@ -27,40 +35,32 @@ from babeltrace import *
 
 # Check for path arg:
 if len(sys.argv) < 2:
-       raise TypeError("Usage: sequence_test.py path/to/file")
+    raise TypeError("Usage: sequence_test.py path/to/file")
 
-# Create context and add trace:
-ctx = Context()
-trace_handle = ctx.add_trace(sys.argv[1], "ctf")
+# Create TraceCollection and add trace:
+traces = TraceCollection()
+trace_handle = traces.add_trace(sys.argv[1], "ctf")
 if trace_handle is None:
-       raise IOError("Error adding trace")
+    raise IOError("Error adding trace")
 
 # Listing events
-lst = ctf.get_event_decl_list(trace_handle, ctx)
 print("--- Event list ---")
-for item in lst:
-       print("event : {}".format(item.get_name()))
+for event_declaration in trace_handle.events:
+    print("event : {}".format(event_declaration.name))
 print("--- Done ---")
 
-# Iter trace
-bp = IterPos(SEEK_BEGIN)
-ctf_it = ctf.Iterator(ctx,bp)
-event = ctf_it.read_event()
-
-while(event is not None):
-       print("TS: {}, {} : {}".format(event.get_timestamp(),
-               event.get_cycles(), event.get_name()))
-       field = event.get_field("seq_int_field")
-       if field is not None:
-               print("int sequence values: {}". format(field[0].get_value()))
-       field = event.get_field("seq_long_field")
-       if field is not None:
-               print("long sequence values: {}". format(field[0].get_value()))
+for event in traces.events:
+    print("TS: {}, {} : {}".format(event.timestamp,
+                                   event.cycles, event.name))
 
-       ret = ctf_it.next()
-       if ret < 0:
-               break
-       else:
-               event = ctf_it.read_event()
+    try:
+        sequence = event["seq_int_field"]
+        print("int sequence values: {}". format(sequence))
+    except KeyError:
+        pass
 
-del ctf_it
+    try:
+        sequence = event["seq_long_field"]
+        print("long sequence values: {}". format(sequence))
+    except KeyError:
+        pass
This page took 0.02465 seconds and 4 git commands to generate.