aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKapileshwar Singh <kapileshwarsingh@gmail.com>2016-07-14 12:41:21 +0200
committerGitHub <noreply@github.com>2016-07-14 12:41:21 +0200
commitd5de962ff1755cec99b81caeebeb1d2614f2d2dc (patch)
tree69d76620e64b8df99a9957c9ba51a99fbc5c1936
parentbc2ee35e7f087bdc65965b0a4e43bce3e30edbb0 (diff)
parent32edbcf6867f9e211259178046fedd4a95cdbe1f (diff)
downloadbart-d5de962ff1755cec99b81caeebeb1d2614f2d2dc.tar.gz
Merge pull request #59 from JaviMerino/get_pids_for_process_fixes
get_pids_for_process() fixes
-rw-r--r--bart/sched/functions.py5
-rw-r--r--tests/test_sched_functions.py69
2 files changed, 73 insertions, 1 deletions
diff --git a/bart/sched/functions.py b/bart/sched/functions.py
index 546e8fb..cb3336e 100644
--- a/bart/sched/functions.py
+++ b/bart/sched/functions.py
@@ -436,11 +436,14 @@ def get_pids_for_process(ftrace, execname, cls=None):
df = ftrace.sched_switch.data_frame
except AttributeError:
raise ValueError("SchedSwitch event not found in ftrace")
+
+ if len(df) == 0:
+ raise ValueError("SchedSwitch event not found in ftrace")
else:
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
new file mode 100644
index 0000000..1a8d4ac
--- /dev/null
+++ b/tests/test_sched_functions.py
@@ -0,0 +1,69 @@
+# Copyright 2016-2016 ARM Limited
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+import trappy
+
+import utils_tests
+
+class TestSchedFunctions(utils_tests.SetupDirectory):
+ def __init__(self, *args, **kwargs):
+ super(TestSchedFunctions, self).__init__([], *args, **kwargs)
+
+ def test_get_pids_for_processes_no_sched_switch(self):
+ """get_pids_for_processes() raises an exception if the trace doesn't have a sched_switch event"""
+ from bart.sched.functions import get_pids_for_process
+
+ trace_file = "trace.txt"
+ raw_trace_file = "trace.raw.txt"
+
+ with open(trace_file, "w") as fout:
+ fout.write("")
+
+ with open(raw_trace_file, "w") as fout:
+ fout.write("")
+
+ 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])