Exemplo n.º 1
0
    def enable(self, profile):
        pypyjit.set_compile_hook(self.on_compile)
        pypyjit.set_abort_hook(self.on_abort)
        self._backup_stdout = sys.stdout
        self._backup_stderr = sys.stderr
        sys.stdout = RecordingStream(sys.stdout)
        sys.stderr = RecordingStream(sys.stderr)

        self.options["build"]["gc"] = sys.pypy_translation_info["translation.gc"]
        self.options["build"]["gcrootfinder"] = sys.pypy_translation_info["translation.gcrootfinder"]
        self.options["build"]["pypy_version"] = sys._mercurial[2]

        if profile:
            self._profile_mmaps = []
            self._new_mmap()
            sys.setprofile(self.on_profile)

        self._start_time = high_res_time()
Exemplo n.º 2
0
    def disable(self, profile):
        self._end_time = high_res_time()
        self.runtime = self._end_time - self._start_time
        del self._start_time

        if profile:
            sys.setprofile(None)

        pypyjit.set_compile_hook(None)
        pypyjit.set_abort_hook(None)

        self.stdout = sys.stdout._content.getvalue()
        self.stderr = sys.stderr._content.getvalue()
        sys.stdout = self._backup_stdout
        sys.stderr = self._backup_stderr
        del self._backup_stdout
        del self._backup_stderr

        if profile:
            self._find_calls()
        del self._end_time
Exemplo n.º 3
0
    def on_profile(self, frame, event, arg):
        timestamp = high_res_time()
        if event == "call" or event == "c_call":
            event_id = CALL_EVENT
            if event == "call":
                target = frame.f_code.co_name
            elif event == "c_call":
                target = arg.__name__
            content = struct.pack("=dL", timestamp, len(target)) + target
        elif event == "return" or event == "c_return" or event == "c_exception":
            event_id = RETURN_EVENT
            content = struct.pack("=d", timestamp)
        elif event == "exception" or event == "c_exception":
            return
        else:
            self.logger.warning("[profile] Unknown event: %s" % event)
            return

        if self._current_profile_mmap.tell() + len(content) + 2 > len(self._current_profile_mmap):
            self._new_mmap()
        self._current_profile_mmap.write_byte(chr(PROFILE_IDENTIFIER))
        self._current_profile_mmap.write_byte(chr(event_id))
        self._current_profile_mmap.write(content)