예제 #1
1
def main():
    graphviz = GraphvizOutput()
    pycallgraph = PyCallGraph(
        output=graphviz,
        config=Config(include_stdlib=True)
    )

    pycallgraph.start()
    import HTMLParser  # noqa
    pycallgraph.stop()

    # Set the edge colour to black for all examples
    graphviz.edge_color_func = lambda e: Color(0, 0, 0)

    # Default node colouring
    graphviz.output_file = 'colours-default.png'
    graphviz.done()

    def run(func, output_file):
        graphviz.node_color_func = func
        graphviz.output_file = output_file
        graphviz.done()

    run(rainbow, 'colors-rainbow.png')
    run(greyscale, 'colors-greyscale.png')
    run(orange_green, 'colors-orange-green.png')
    run(rand, 'colors-random.png')
예제 #2
0
    def process_view(self, request, callback, callback_args, callback_kwargs):
        if settings.DEBUG and 'graph' in request.GET:
            visualize_modules = request.GET['graph'].split(',')
            exclude_extra = request.GET.get('exclude_extra', '').split(',')
            exclude = PyCallGraphMiddleware.DEFAULT_EXCLUDE + exclude_extra
            graph_output = request.GET.get('graph_output', 'png')
            groups = request.GET.get('groups', False)
            max_depth = int(request.GET.get('max_depth', 99999))
            tool = request.GET.get('tool', 'dot')
            ##https://graphviz.org/
            ## Roadmap

            if graph_output not in PyCallGraphMiddleware.VALID_OUTPUT_TYPE:
                raise Exception(
                    f'"{graph_output}" not in "{PyCallGraphMiddleware.VALID_OUTPUT_TYPE}"'
                )

            output_file = 'pycallgraph-{}-{}.{}'.format(
                time.time(), tool, graph_output)

            output = GraphvizOutput(output_file=output_file,
                                    tool=tool,
                                    output_type=graph_output)

            config = Config(groups=groups, max_depth=max_depth)
            config.trace_filter = GlobbingFilter(include=visualize_modules,
                                                 exclude=exclude)

            pycallgraph = PyCallGraph(output=output, config=config)
            pycallgraph.start()

            self.pycallgraph = pycallgraph
예제 #3
0
    def process_view(self, request, callback, callback_args, callback_kwargs):

        if settings.DEBUG and 'graph' in request.GET:
            pycallgraph = PyCallGraph(output=GraphvizOutput(
                output_file='callgraph-' + str(time.time()) + '.png'))
            pycallgraph.start()
            self.pycallgraph = pycallgraph
예제 #4
0
    def __call__(self, request):

        # Code to be executed for each request before
        # the view (and later middleware) are called.
        if settings.DEBUG and self.to_debug(request):
            config = Config()
            config.trace_filter = GlobbingFilter(include=['contracts.*'],
                                                 exclude=[])
            graphviz = GraphvizOutput(output_file='callgraph-' +
                                      str(time.time()) + '.svg',
                                      output_type='svg')  # or 'png'
            pycallgraph = PyCallGraph(output=graphviz, config=config)
            pycallgraph.start()
            # noinspection PyAttributeOutsideInit
            self.pycallgraph = pycallgraph

            response = self.get_response(request)
            # Code to be executed for each request/response after
            # the view is called.

            self.pycallgraph.done()
        else:
            response = self.get_response(request)

        return response
예제 #5
0
def create_graph(output_type='dot'):
    '''
    starts the graph call. Keep the returned object and run done() on it to finish the graph creation.
    '''

    config = Config()
    config.trace_filter = GlobbingFilter(exclude=[
        'pycallgraph.*',
        'django.core.*',
        'collections.*',
        'copy.*',
        'threading.*',
        'logging.*',
        'multiprocessing.*',
        'inspect.*',
        'string.*',
        'Cookie.*',
        'importlib.*',
        'pdb.*',
        'shutil.*',
        're.*',
        'os.*',
        'sys.*',
        'json.*',
        'decimal.*',
        'urllib.*',
    ])

    output_type = 'dot'
    output_file = 'tccallgraph-{}.{}'.format(str(time.time()), output_type)
    graphviz = GraphvizOutput(output_file=output_file, output_type=output_type)
    pycallgraph = PyCallGraph(output=graphviz, config=config)
    pycallgraph.start(reset=True)

    return pycallgraph
예제 #6
0
def main():
    graphviz = GraphvizOutput()
    pycallgraph = PyCallGraph(output=graphviz,
                              config=Config(include_stdlib=True))

    pycallgraph.start()
    from html.parser import HTMLParser  # noqa

    pycallgraph.stop()

    # Set the edge colour to black for all examples
    graphviz.edge_color_func = lambda e: Color(0, 0, 0)

    # Default node colouring
    graphviz.output_file = "colours-default.png"
    graphviz.done()

    def run(func, output_file):
        graphviz.node_color_func = func
        graphviz.output_file = output_file
        graphviz.done()

    run(rainbow, "colors-rainbow.png")
    run(greyscale, "colors-greyscale.png")
    run(orange_green, "colors-orange-green.png")
    run(rand, "colors-random.png")
예제 #7
0
파일: stat.py 프로젝트: mgroth0/mlib
def enable_py_call_graph(output):
    # Makes code about 4 times slower
    DEFAULT_PY_CALL_GRAPH = PyCallGraph(
        output=GraphvizOutput(
            output_file=mlib.file.abspath
        ),
        config=Config(
            max_depth=2
        )
    )
    atexit.register(DEFAULT_PY_CALL_GRAPH.done)
    DEFAULT_PY_CALL_GRAPH.start()
예제 #8
0
    def on_request(self, request_handler, run):
        filename = "%s/%s/pycallgraph.dot" % (self.output_path, run.id)

        config = Config()
        config.trace_filter = GlobbingFilter(include=[
            'element.*',
            'ioc.*',
        ])

        callgraph = PyCallGraph(output=DotGraphvizOutput(output_file=filename), config=config)
        callgraph.start()

        request_handler.run.add_data('callgraph', callgraph)
        request_handler.run.add_metric('callgraph', True)
예제 #9
0
def create_graph(output_type='dot'):
    '''
    starts the graph call. Keep the returned object and run done() on it to finish the graph creation.
    '''

    config = Config()
    config.trace_filter = GlobbingFilter(exclude=['pycallgraph.*', 'django.core.*', 'collections.*', 'copy.*',
                                                  'threading.*', 'logging.*', 'multiprocessing.*', 'inspect.*',
                                                  'string.*', 'Cookie.*', 'importlib.*', 'pdb.*', 'shutil.*',
                                                  're.*', 'os.*', 'sys.*', 'json.*', 'decimal.*', 'urllib.*',
                                                  ])

    output_type = 'dot'
    output_file = 'tccallgraph-{}.{}'.format(str(time.time()), output_type)
    graphviz = GraphvizOutput(output_file=output_file, output_type=output_type)
    pycallgraph = PyCallGraph(output=graphviz, config=config)
    pycallgraph.start(reset=True)

    return pycallgraph
예제 #10
0
class PyCallgraphProvider(CallgraphProviderBase):
    def __init__(self,
                 configuration: CallgraphConfiguration,
                 caller_name: str = None):
        super().__init__(configuration, caller_name)
        self._config = Config()
        self._config.trace_filter = GlobbingFilter(exclude=[
            'pycallgraph.*'
            'excallgraph', 'excallgraph.*', 'providers.*'
        ])
        if self._configuration.excludes is not None:
            self._config.trace_filter.exclude += self._configuration.excludes
        if self._configuration.includes is not None:
            self._config.trace_filter.include = self._configuration.includes

    def __enter__(self):
        self._provider = PyCallGraph(output=GraphvizOutput(
            output_file=path.join(
                self._path,
                f"{self._caller_name}.{self._configuration.format}"),
            output_format=self._configuration.format),
                                     config=self._config)
        return self

    def __exit__(self, exc_type, exc_val, exc_tb):
        if self._provider is not None:
            self._provider.stop()
            return self._provider.__exit__(exc_type, exc_val, exc_tb)

    def start(self):
        '''Starts Capturing Trace'''
        return self._provider.start()

    def stop(self):
        '''Stop Capture Trace'''
        return self._provider.stop()

    def get_path(self):
        return self._configuration.path

    def get_format(self):
        return self._configuration.format

    def create_path_if_not_exists(self):
        try:
            makedirs(self.get_path())
        except OSError as ex:
            if ex.errno == errno.EEXIST and os.path.isdir(self.get_path()):
                pass
            else:
                raise