diff options
author | Javi Merino <javi.merino@arm.com> | 2016-07-13 17:19:57 +0100 |
---|---|---|
committer | Javi Merino <javi.merino@arm.com> | 2016-07-13 17:28:11 +0100 |
commit | 32edbcf6867f9e211259178046fedd4a95cdbe1f (patch) | |
tree | 04dfba668a876103d32a517aeea09e16a3c33c5c | |
parent | e467a1eb564c59de66673a9a3b5795c4b16f4ce8 (diff) | |
download | bart-32edbcf6867f9e211259178046fedd4a95cdbe1f.tar.gz |
sched: functions: cope with processes whose string is a substring of another process
We can't use .startswith() to match processes since sometimes a process
name is a substring of another process name. For example, in a trace
with processes "wmig" (pid 3268) and "wmig1" (pid 3269), if we use
.startswith("wmig"), the second process matches which is wrong. In this
trace, the only pid for the wmig process is 3268.
-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]) |