Пример #1
0
    async def _get_raw_data(self):
        """ Collect raw data asynchronously using perf """
        self.start_time = datetime.datetime.now()

        sub_process = await asyncio.create_subprocess_shell(
            "perf record -ag -o " + self._PERF_FILE_NAME +
            " -e '{mem-loads,mem-stores}' sleep " + str(self.time),
            stderr=asyncio.subprocess.PIPE)

        _, err = await sub_process.communicate()
        self.end_time = datetime.datetime.now()
        if sub_process.returncode != 0:
            raise exceptions.SubprocessedErorred(err.decode())

        sub_process = await asyncio.create_subprocess_shell(
            "perf script -i " + self._PERF_FILE_NAME,
            stdout=asyncio.subprocess.PIPE,
            stderr=asyncio.subprocess.PIPE)
        out, err = await sub_process.communicate()
        if sub_process.returncode != 0:
            raise exceptions.SubprocessedErorred(err.decode())

        os.remove(os.getcwd() + "/" + self._PERF_FILE_NAME)

        return StringIO(out.decode())
Пример #2
0
    async def _get_raw_data(self):
        """ Collect raw data asynchronously using perf. """
        # Delete old probes and create a new one tracking allocation size
        sub_process = await asyncio.create_subprocess_shell(
            "perf probe -q --del *malloc*", stderr=asyncio.subprocess.PIPE)
        _, err = await sub_process.communicate()

        sub_process = await asyncio.create_subprocess_shell(
            "perf probe -qx /lib*/*/libc.so.* malloc:1 size=%di",
            stderr=asyncio.subprocess.PIPE)
        _, err = await sub_process.communicate()

        # Record perf data
        self.start_time = datetime.datetime.now()
        sub_process = await asyncio.create_subprocess_shell(
            "perf record -ag -o " + self._PERF_FILE_NAME +
            " -e probe_libc:malloc: sleep " + str(self.time),
            stderr=asyncio.subprocess.PIPE)
        _, err = await sub_process.communicate()
        self.end_time = datetime.datetime.now()
        if sub_process.returncode != 0:
            raise exceptions.SubprocessedErorred(err.decode())

        sub_process = await asyncio.create_subprocess_shell(
            "perf script -i " + self._PERF_FILE_NAME,
            stdout=asyncio.subprocess.PIPE,
            stderr=asyncio.subprocess.PIPE)
        out, err = await sub_process.communicate()
        if sub_process.returncode != 0:
            raise exceptions.SubprocessedErorred(err.decode())

        os.remove(os.getcwd() + "/" + self._PERF_FILE_NAME)

        return StringIO(out.decode())
Пример #3
0
    async def _get_raw_data(self):
        """
        Collect raw data asynchronously using tcptracer.

        Call tcptracer, and discard the KeyboardInterrupt error message
        resulting from terminating the script.

        """
        cmd = BCC_TOOLS_PATH + 'tcptracer ' + '-tv'

        self.start_time = datetime.datetime.now()
        sub_process = await asyncio.create_subprocess_shell(
            cmd,
            stdout=asyncio.subprocess.PIPE,
            stderr=asyncio.subprocess.PIPE,
            preexec_fn=os.setsid)

        # Timeout the subprocess
        _, pending = await asyncio.wait(
            [asyncio.ensure_future(sub_process.communicate())],
            timeout=self.time)
        self.end_time = datetime.datetime.now()
        os.killpg(sub_process.pid, signal.SIGINT)

        out, err = await (pending.pop())
        # Check for unexpected errors
        # We expect tcptracer to print a stack trace on termination -
        # anything more than that must be logged
        pattern = r"^Traceback \(most recent call last\):" \
                  r"(\S*\s)*KeyboardInterrupt\s$"
        if not re.fullmatch(pattern, err.decode()):
            if sub_process.returncode != 0:
                raise exceptions.SubprocessedErorred(err.decode())

        return StringIO(out.decode())
Пример #4
0
    async def _get_raw_data(self):
        """ Collect raw data asynchronously from smem """
        # Dict for the datapoints to be collected
        datapoints = {}
        # Set the start time
        start_time = time.monotonic()
        current_time = 0.0
        self.start_time = datetime.datetime.now()
        while current_time < self.time:
            if self.options.mode not in self.modes:
                raise ValueError("mode {} not supported.".format(
                    self.options.mode))

            smem = await asyncio.create_subprocess_shell(
                "smem -c \"{} pss\"".format(self.options.mode),
                stdout=asyncio.subprocess.PIPE,
                stderr=asyncio.subprocess.PIPE)

            out, err = await smem.communicate()
            if smem.returncode != 0:
                # Set an end_time
                raise exceptions.SubprocessedErorred(err.decode())

            datapoints[current_time] = {}

            # Get lines and get rid of the title line (Name       PSS) and the
            # empty line produced by the split
            lines = out.decode().split("\n")[1:-1]
            # TODO: Check why it's in reverse
            for idx in reversed(range(len(lines))):
                line = lines[idx]

                match = re.match(
                    r"\s*(?P<label>\S+(\s\S+)*)\s*"
                    r"(?P<memory>\d+)", line)
                if match is None:
                    raise IOError(
                        "Invalid output format from smem: {}".format(line))

                label = match.group("label")
                memory = float(match.group("memory")) / 1024.0

                if label in datapoints[current_time]:
                    memory += float(datapoints[current_time][label])

                datapoints[current_time][label] = memory

            # Update the clock
            await asyncio.sleep(self.options.frequency)
            current_time = time.monotonic() - start_time

        self.end_time = datetime.datetime.now()
        return datapoints
Пример #5
0
    async def _get_raw_data(self):
        """ Collect raw data asynchronously using the mallockstacks module. """
        self.start_time = datetime.datetime.now()

        sub_process = await asyncio.create_subprocess_exec(
            'sudo',
            'python',
            BCC_TOOLS_PATH + 'mallocstacks.py',
            '-f',
            str(self.time),
            stderr=asyncio.subprocess.PIPE,
            stdout=asyncio.subprocess.PIPE)
        out, err = await sub_process.communicate()

        self.end_time = datetime.datetime.now()
        if sub_process.returncode != 0:
            raise exceptions.SubprocessedErorred(err.decode())

        return StringIO(out.decode())
Пример #6
0
    async def _get_raw_data(self):
        """ Get raw data asynchronously using memleak.py """
        self.start_time = datetime.datetime.now()

        sub_process = await asyncio.create_subprocess_exec(
            'sudo',
            'python',
            BCC_TOOLS_PATH + 'memleak.py',
            '-t',
            str(self.time),
            '-T',
            str(self.options.top_processes),
            stderr=asyncio.subprocess.PIPE,
            stdout=asyncio.subprocess.PIPE)

        out, err = await sub_process.communicate()
        self.end_time = datetime.datetime.now()
        if sub_process.returncode != 0:
            raise exceptions.SubprocessedErorred(err.decode())

        return StringIO(out.decode())