- raise IOError("Error adding trace")
-
-# Setting iterator
-bp = IterPos(SEEK_BEGIN)
-ctf_it = ctf.Iterator(ctx, bp)
-
-# Reading events
-event = ctf_it.read_event()
-while event is not None:
- while True:
- if event.get_name() == "sched_switch":
- # Getting scope definition
- sco = event.get_top_level_scope(ctf.scope.STREAM_EVENT_CONTEXT)
- if sco is None:
- print("ERROR: Cannot get definition scope for sched_switch")
- break # Next event
-
- # Getting PID
- pid_field = event.get_field(sco, "_pid")
- pid = pid_field.get_int64()
-
- if ctf.field_error():
- print("ERROR: Missing PID info for sched_switch")
- break # Next event
-
- if usePID and (pid != long(sys.argv[1])):
- break # Next event
-
- sco = event.get_top_level_scope(ctf.scope.EVENT_FIELDS)
-
- # prev_comm
- field = event.get_field(sco, "_prev_comm")
- prev_comm = field.get_char_array()
- if ctf.field_error():
- print("ERROR: Missing prev_comm context info")
-
- # prev_tid
- field = event.get_field(sco, "_prev_tid")
- prev_tid = field.get_int64()
- if ctf.field_error():
- print("ERROR: Missing prev_tid context info")
-
- # prev_prio
- field = event.get_field(sco, "_prev_prio")
- prev_prio = field.get_int64()
- if ctf.field_error():
- print("ERROR: Missing prev_prio context info")
-
- # prev_state
- field = event.get_field(sco, "_prev_state")
- prev_state = field.get_int64()
- if ctf.field_error():
- print("ERROR: Missing prev_state context info")
-
- # next_comm
- field = event.get_field(sco, "_next_comm")
- next_comm = field.get_char_array()
- if ctf.field_error():
- print("ERROR: Missing next_comm context info")
-
- # next_tid
- field = event.get_field(sco, "_next_tid")
- next_tid = field.get_int64()
- if ctf.field_error():
- print("ERROR: Missing next_tid context info")
-
- # next_prio
- field = event.get_field(sco, "_next_prio")
- next_prio = field.get_int64()
- if ctf.field_error():
- print("ERROR: Missing next_prio context info")
-
- # Output
- print("sched_switch, pid = {}, TS = {}, prev_comm = {},\n\t"
- "prev_tid = {}, prev_prio = {}, prev_state = {},\n\t"
- "next_comm = {}, next_tid = {}, next_prio = {}".format(
- pid, event.get_timestamp(), prev_comm, prev_tid,
- prev_prio, prev_state, next_comm, next_tid, next_prio))
-
- break # Next event
-
- # Next event
- ret = ctf_it.next()
- if ret < 0:
- break
- event = ctf_it.read_event()
-
-del ctf_it
+ raise IOError("Error adding trace")
+
+for event in traces.events:
+ if event.name != "sched_switch":
+ continue
+
+ # Getting PID
+ pid = event.field_with_scope("pid", babeltrace.common.CTFScope.STREAM_EVENT_CONTEXT)
+ if pid is None:
+ print("ERROR: Missing PID info for sched_switch")
+ continue # Next event
+
+ if filterPID and (pid != long(sys.argv[1])):
+ continue # Next event
+
+ prev_comm = event["prev_comm"]
+ prev_tid = event["prev_tid"]
+ prev_prio = event["prev_prio"]
+ prev_state = event["prev_state"]
+ next_comm = event["next_comm"]
+ next_tid = event["next_tid"]
+ next_prio = event["next_prio"]
+
+ # Output
+ print("sched_switch, pid = {}, TS = {}, prev_comm = {},\n\t"
+ "prev_tid = {}, prev_prio = {}, prev_state = {},\n\t"
+ "next_comm = {}, next_tid = {}, next_prio = {}".format(
+ pid, event.timestamp, prev_comm, prev_tid,
+ prev_prio, prev_state, next_comm, next_tid, next_prio))