From b94a25e94aba84459aa050ab4c67b8283da1f4be Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Tue, 18 Feb 2014 02:03:01 -0500 Subject: [PATCH 1/1] Python bindings: sched_switch example clean-up MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Remove unecessary while loop to handle event skipping. Signed-off-by: Jérémie Galarneau --- bindings/python/examples/sched_switch.py | 49 ++++++++++++------------ 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/bindings/python/examples/sched_switch.py b/bindings/python/examples/sched_switch.py index ce116c14..8c475565 100644 --- a/bindings/python/examples/sched_switch.py +++ b/bindings/python/examples/sched_switch.py @@ -31,9 +31,9 @@ from babeltrace import * if len(sys.argv) < 2 or len(sys.argv) > 3: raise TypeError("Usage: python sched_switch.py [pid] path/to/trace") elif len(sys.argv) == 3: - usePID = True + filterPID = True else: - usePID = False + filterPID = False traces = TraceCollection() ret = traces.add_trace(sys.argv[len(sys.argv)-1], "ctf") @@ -41,30 +41,29 @@ if ret is None: raise IOError("Error adding trace") for event in traces.events: - while True: - if event.name == "sched_switch": - # Getting PID - pid = event.field_with_scope("pid", CTFScope.STREAM_EVENT_CONTEXT) - if pid is None: - print("ERROR: Missing PID info for sched_switch") - break # Next event + if event.name != "sched_switch": + continue - if usePID and (pid != long(sys.argv[1])): - break # Next event + # Getting PID + pid = event.field_with_scope("pid", CTFScope.STREAM_EVENT_CONTEXT) + if pid is None: + print("ERROR: Missing PID info for sched_switch") + 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"] + if filterPID and (pid != long(sys.argv[1])): + continue # Next event - # 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)) + 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"] - break # Next event + # 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)) -- 2.34.1