diff options
-rw-r--r-- | bart/sched/functions.py | 2 | ||||
-rw-r--r-- | tests/test_sched_functions.py | 30 |
2 files changed, 31 insertions, 1 deletions
diff --git a/bart/sched/functions.py b/bart/sched/functions.py index 8a3d7a0..cb3336e 100644 --- a/bart/sched/functions.py +++ b/bart/sched/functions.py @@ -443,7 +443,7 @@ def get_pids_for_process(ftrace, execname, cls=None): event = getattr(ftrace, cls.name) df = event.data_frame - mask = df["next_comm"].apply(lambda x : True if x.startswith(execname) else False) + mask = df["next_comm"].apply(lambda x : True if x == execname else False) return list(np.unique(df[mask]["next_pid"].values)) def get_task_name(ftrace, pid, cls=None): diff --git a/tests/test_sched_functions.py b/tests/test_sched_functions.py index 164df3c..1a8d4ac 100644 --- a/tests/test_sched_functions.py +++ b/tests/test_sched_functions.py @@ -37,3 +37,33 @@ class TestSchedFunctions(utils_tests.SetupDirectory): trace = trappy.FTrace(trace_file) with self.assertRaises(ValueError): get_pids_for_process(trace, "foo") + + def test_get_pids_for_process_funny_process_names(self): + """get_pids_for_process() works when a process name is a substring of another""" + from bart.sched.functions import get_pids_for_process + + trace_file = "trace.txt" + raw_trace_file = "trace.raw.txt" + in_data = """ <idle>-0 [001] 10826.894644: sched_switch: prev_comm=swapper/1 prev_pid=0 prev_prio=120 prev_state=0 next_comm=rt-app next_pid=3268 next_prio=120 + wmig-3268 [001] 10826.894778: sched_switch: prev_comm=wmig prev_pid=3268 prev_prio=120 prev_state=1 next_comm=rt-app next_pid=3269 next_prio=120 + wmig1-3269 [001] 10826.905152: sched_switch: prev_comm=wmig1 prev_pid=3269 prev_prio=120 prev_state=1 next_comm=wmig next_pid=3268 next_prio=120 + wmig-3268 [001] 10826.915384: sched_switch: prev_comm=wmig prev_pid=3268 prev_prio=120 prev_state=1 next_comm=swapper/1 next_pid=0 next_prio=120 + <idle>-0 [005] 10826.995169: sched_switch: prev_comm=swapper/5 prev_pid=0 prev_prio=120 prev_state=0 next_comm=wmig1 next_pid=3269 next_prio=120 + wmig1-3269 [005] 10827.007064: sched_switch: prev_comm=wmig1 prev_pid=3269 prev_prio=120 prev_state=0 next_comm=wmig next_pid=3268 next_prio=120 + wmig-3268 [005] 10827.019061: sched_switch: prev_comm=wmig prev_pid=3268 prev_prio=120 prev_state=0 next_comm=wmig1 next_pid=3269 next_prio=120 + wmig1-3269 [005] 10827.031061: sched_switch: prev_comm=wmig1 prev_pid=3269 prev_prio=120 prev_state=0 next_comm=wmig next_pid=3268 next_prio=120 + wmig-3268 [005] 10827.050645: sched_switch: prev_comm=wmig prev_pid=3268 prev_prio=120 prev_state=1 next_comm=swapper/5 next_pid=0 next_prio=120 +""" + + # We create an empty trace.txt to please trappy ... + with open(trace_file, "w") as fout: + fout.write("") + + # ... but we only put the sched_switch events in the raw trace + # file because that's where trappy is going to look for + with open(raw_trace_file, "w") as fout: + fout.write(in_data) + + trace = trappy.FTrace(trace_file) + + self.assertEquals(get_pids_for_process(trace, "wmig"), [3268]) |