Ejemplo n.º 1
0
    def run(self):
        self.pipe.send(0)  # we're ready
        stop = False
        while True:
            cur_mem = (
                _get_memory(self.monitor_pid, self.backend,
                            timestamps=self.timestamps,
                            include_children=self.include_children)
            )

            if self.stream is not None:
                self.stream.write("MEM {0:.6f} {1:.4f}\n".format(*cur_mem))
                self.stream.flush()

            if not self.max_usage:
                self.mem_usage.append(cur_mem)
            else:
                self.mem_usage = max(cur_mem, self.mem_usage)

            self.n_measurements += 1
            if stop:
                break
            stop = self.pipe.poll(self.interval)
            # do one more iteration

        if self.stream is not None:
            self.stream.close()

        self.pipe.send(self.mem_usage)
        self.pipe.send(self.n_measurements)
Ejemplo n.º 2
0
    def _run_single_test(self, test_context):
        # write current memory usage to file before running the test
        pid = os.getpid()
        current_memory = _get_memory(pid)
        self.queue.put(current_memory)

        super(InstrumentedTestRunner, self)._run_single_test(test_context)
Ejemplo n.º 3
0
    def __init__(self, monitor_pid, interval, pipe, filename, max_usage, backend, *args, **kw):
        self.monitor_pid = monitor_pid
        self.pipe = pipe
        self.interval = interval
        self.backend = backend
        self.n_measurements = 1
        self.stream = open(filename, 'w') if filename is not None else None
        self.max_usage = max_usage

        self.timestamps = kw.pop("timestamps", True)
        self.include_children = kw.pop("include_children", True)

        # get baseline memory usage
        cur_mem = (
            _get_memory(self.monitor_pid, self.backend,
                        timestamps=self.timestamps,
                        include_children=self.include_children)
        )
        self.mem_usage = cur_mem if self.max_usage else [cur_mem]

        if self.stream is not None:
            self.stream.write("MEM {0:.6f} {1:.4f}\n".format(*cur_mem))
            self.stream.flush()

        super(MemTimer, self).__init__(*args, **kw)
Ejemplo n.º 4
0
    def _run_single_test(self, test_context):
        # write current memory usage to file before running the test
        pid = os.getpid()
        current_memory = _get_memory(pid)
        self.queue.put(current_memory)

        super(InstrumentedTestRunner, self)._run_single_test(test_context)
Ejemplo n.º 5
0
    def run(self):
        # get baseline memory usage
        cur_mem = (
            _get_memory(self.monitor_pid, self.backend,
                        timestamps=self.timestamps,
                        include_children=self.include_children)
        )

        n_measurements = 1
        mem_usage = cur_mem if self.max_usage else [cur_mem]

        if self.filename is not None:
            stream = open(self.filename, 'w')
            stream.write("MEM {0:.6f} {1:.4f}\n".format(*cur_mem))
            stream.flush()
        else:
            stream = None

        self.pipe.send(0)  # we're ready
        stop = False
        while True:
            cur_mem = (
                _get_memory(self.monitor_pid, self.backend,
                            timestamps=self.timestamps,
                            include_children=self.include_children)
            )

            if stream is not None:
                stream.write("MEM {0:.6f} {1:.4f}\n".format(*cur_mem))
                stream.flush()

            n_measurements += 1
            if not self.max_usage:
                mem_usage.append(cur_mem)
            else:
                mem_usage = max(cur_mem, mem_usage)

            if stop:
                break
            stop = self.pipe.poll(self.interval)
            # do one more iteration

        if stream is not None:
            stream.close()

        self.pipe.send(mem_usage)
        self.pipe.send(n_measurements)
    def run_single_test(self):
        # write current memory usage to file before running the test
        pid = os.getpid()
        current_memory = _get_memory(pid)
        self.queue.put(current_memory)

        data = super(InstrumentedSerialTestRunner, self).run_single_test()
        return data
Ejemplo n.º 7
0
    def run_single_test(self):
        # write current memory usage to file before running the test
        pid = os.getpid()
        current_memory = _get_memory(pid)
        self.queue.put(current_memory)

        data = super(InstrumentedSerialTestRunner, self).run_single_test()
        return data
Ejemplo n.º 8
0
 def trace_func(self,
                pid,
                timestamps=False,
                include_children=False,
                filename=None):
     return memory_profiler._get_memory(
         pid,
         self.backend,
         timestamps=timestamps,
         include_children=include_children,
         filename=filename,
     )
Ejemplo n.º 9
0
    def run(self):
        start_mem = _get_memory(
            self.monitor_pid,
            self.backend,
            include_children=self.include_children,
        )
        max_mem = 0

        stop, split = False, False
        self.pipe.send(self.START)
        while True:
            mem = _get_memory(
                self.monitor_pid,
                self.backend,
                include_children=self.include_children,
            )
            max_mem = max(max_mem, mem)

            if stop:
                break
            elif split:
                split = False
                self.pipe.send(max(0, max_mem - start_mem))
                start_mem = _get_memory(
                    self.monitor_pid,
                    self.backend,
                    include_children=self.include_children,
                )
                max_mem = 0

            if (self.pipe.poll(self.interval)):
                value = self.pipe.recv()
                if value == self.STOP:
                    stop = True
                elif value == self.SPLIT:
                    split = True

        self.pipe.send(max(0, max_mem - start_mem))
        self.pipe.close()