def _validate_pid(self, pid):
        """Validate the passed pid argument"""

        if not pid:
            pids = sched_funcs.get_pids_for_process(self._ftrace,
                                              self.execname)

            if len(pids) != 1:
                raise RuntimeError(
                    "There should be exactly one PID {0} for {1}".format(
                        pids,
                        self.execname))

            return pids[0]

        elif self.execname:

            pids = sched_funcs.get_pids_for_process(self._ftrace,
                                              self.execname)
            if pid not in pids:
                raise RuntimeError(
                    "PID {0} not mapped to {1}".format(
                        pid,
                        self.execname))
        else:
            self.execname = sched_funcs.get_task_name(self._ftrace, pid)

        return pid
예제 #2
0
    def _populate_pids(self):
        """Map the input execnames to PIDs"""

        if len(self._execnames) == 1:
            return sched_funcs.get_pids_for_process(self._ftrace, self._execnames[0])

        pids = []

        for proc in self._execnames:
            pids += sched_funcs.get_pids_for_process(self._ftrace, proc)

        return list(set(pids))
    def _populate_pids(self, run):
        """Populate the qualifying PIDs from the run"""

        if len(self._execnames) == 1:
            return sched_funcs.get_pids_for_process(run, self._execnames[0])

        pids = []

        for proc in self._execnames:
            pids += sched_funcs.get_pids_for_process(run, proc)

        return list(set(pids))
예제 #4
0
    def _populate_pids(self):
        """Map the input execnames to PIDs"""

        if len(self._execnames) == 1:
            return sched_funcs.get_pids_for_process(self._ftrace, self._execnames[0])

        pids = []

        for proc in self._execnames:
            pids += sched_funcs.get_pids_for_process(self._ftrace, proc)

        return list(set(pids))
예제 #5
0
    def _populate_pids(self, run):
        """Populate the qualifying PIDs from the run"""

        if len(self._execnames) == 1:
            return sched_funcs.get_pids_for_process(run, self._execnames[0])

        pids = []

        for proc in self._execnames:
            pids += sched_funcs.get_pids_for_process(run, proc)

        return list(set(pids))
예제 #6
0
    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])
예제 #7
0
    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")
예제 #8
0
    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])
예제 #10
0
    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"
        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
"""
        with open(trace_file, "w") as fout:
            fout.write(in_data)

        trace = trappy.FTrace(trace_file)
        self.assertEquals(get_pids_for_process(trace, "wmig"), [3268])