How to use the birdseye.bird.Iteration function in birdseye

To help you get started, we’ve selected a few birdseye examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github alexmojaki / birdseye / birdseye / bird.py View on Github external
def _add_iteration(self, loops, frame):
        # type: (typing.Sequence[Loop], FrameType) -> None
        """
        Given one or more nested loops, add an iteration for the innermost
        loop (the last in the sequence).
        """
        iteration = self.stack[frame].iteration  # type: Iteration
        for i, loop_node in enumerate(loops):
            loop = iteration.loops[loop_node._tree_index]
            if i == len(loops) - 1:
                loop.append(Iteration())
            else:
                iteration = loop.last()
github alexmojaki / birdseye / birdseye / bird.py View on Github external
def enter_call(self, enter_info):
        # type: (EnterCallInfo) -> None
        frame = enter_info.current_frame  # type: FrameType
        if frame.f_code not in self._code_infos or _tracing_recursively(frame):
            return
        frame_info = self.stack[frame]
        frame_info.start_time = get_unfrozen_datetime()
        frame_info.iteration = Iteration()

        code_info = self._code_infos[frame.f_code]
        if isinstance(enter_info.enter_node.parent, ast.Module):
            arguments = []
        else:
            f_locals = frame.f_locals.copy()  # type: Dict[str, Any]
            arguments = [(name, f_locals.pop(name))
                         for name in code_info.arg_names
                         if name] + [

                            # Local variables other than actual arguments. These are variables from
                            # the enclosing scope. It's handy to treat them like arguments in the UI
                            it for it in f_locals.items()
                            if it[0][0] != '.'  # Appears when using nested tuple arguments
                        ]
        frame_info.arguments = json.dumps([[k, cheap_repr(v)] for k, v in arguments])
github alexmojaki / birdseye / birdseye / bird.py View on Github external
self.index = None  # type: int
        self.keep = False

    def extract_iterations(self):
        # type: () -> Dict[str, Union[int, Dict]]
        return {
            'index': self.index,
            'loops': {
                tree_index: [iteration.extract_iterations()
                             for iteration in iteration_list]
                for tree_index, iteration_list in self.loops.items()
            }
        }


class IterationList(Iterable[Iteration]):
    """
    A list of Iterations, corresponding to a run of a loop.
    If the loop has many iterations, only contains the first and last few
    and any in the middle where unique nodes had values, so that
    any node which appeared during this loop exists in at least some iterations.
    """
    side_len = 3

    def __init__(self):
        # Contains the first few iterations
        # and any after that have unique nodes in them
        self.start = []  # type: List[Iteration]

        # Contains the last few iterations
        self.end = deque(maxlen=self.side_len)  # type: Deque[Iteration]