示例#1
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
示例#2
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
示例#3
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
示例#4
0
    def test_run_with_trace(self):
        def rainbow(node):
            return Color.hsv(node.time.fraction * 0.8, 0.4, 0.9)

        def greyscale(node):
            return Color.hsv(0, 0, node.time.fraction / 2 + 0.4)

        def orange_green(node):
            return Color( 0.2 + node.time.fraction * 0.8,
                          0.2 + node.calls.fraction * 0.4 ,
                          0.2)

        from pycallgraph.output import GraphvizOutput
        from pycallgraph import PyCallGraph

        graphviz = GraphvizOutput()
        graphviz.output_file = 'basic.png'
        graphviz.edge_color_func = lambda e: Color(0, 0, 0)
        #graphviz.node_color_func = rainbow #orange_green # greyscale

        config = Config(include_stdlib=True)#max_depth=10)
        config.trace_filter = GlobbingFilter(include=['osbot*','pbx*','boto3*'])

        with PyCallGraph(output=graphviz, config=config):
            try:
                self.handler.run(Test_Data.api_gw_payload_help)
            except Exception as error:
                Dev.pprint(error)
示例#5
0
def main():
    config = Config()
    # 关系图中包括(include)哪些函数名。
    #如果是某一类的函数,例如类gobang,则可以直接写'gobang.*',表示以gobang.开头的所有函数。(利用正则表达式)。
    config.trace_filter = GlobbingFilter(include=[
        'main',
        'pycallgraph.*',
        '*.secret_function',
    ])
    graphviz = GraphvizOutput()
    graphviz.output_file = 'basic.png'  #图片名称

    with PyCallGraph(output=graphviz):
        # coco
        modelpath = "model/"
        start = time.time()
        pose_model = general_coco_model(modelpath)  # 1.加载模型
        print("[INFO]Pose Model loads time: ", time.time() - start)
        # yolo
        start = time.time()
        _yolo = YOLO()  # 1.加载模型
        print("[INFO]yolo Model loads time: ", time.time() - start)

        img_path = 'D:/myworkspace/dataset/My_test/img/a_img/airplane_30.jpg'

        getImgInfo(img_path, pose_model, _yolo)
示例#6
0
def profile(rand=np.random):
    """Profile the embedding"""
    config = Config()
    config.trace_filter = GlobbingFilter(exclude=["pycallgraph.*"])
    graphviz = GraphvizOutput(output_file=f"pc.png")
    pcg = PyCallGraph(output=graphviz, config=config)
    main(rand, pcg)
示例#7
0
def make_callgraph(name: str,
                   id: str,
                   dry_run=NO_CALL_GRAPHS) -> 'PyCallGraph':
    """
    :param name: file name used to generate the call graph
    :param id:  if of the image
    :param dry_run: if True do not generate a call graph
    :return: a context manager
    """
    class DummyCtx:
        def __enter__(self):
            pass

        def __exit__(self, exc_type, exc_val, exc_tb):
            pass

    if dry_run:
        return DummyCtx()

    config = Config()
    config.trace_filter = GlobbingFilter(exclude=[
        'pycallgraph.*', 'tornado*', '*SynchronizedStatStreamStruct*'
    ])
    output = GraphvizOutput(
        output_file='call_graphs/{}_{}.png'.format(name, id))
    return PyCallGraph(output=output, config=config)
示例#8
0
    def main(self):
        parser = argparse.ArgumentParser()
        parser.add_argument('--grouped', action='store_true')
        conf = parser.parse_args()

        if conf.grouped:
            self.run('regexp_grouped.png', Config(groups=True))
        else:
            self.run('regexp_ungrouped.png', Config(groups=False))
示例#9
0
def filter_depth():
    config = Config()
    config.max_depth = 1

    run(
        'max_depth',
        config=config,
        comment='Should only show a depth of one.'
    )
示例#10
0
文件: profiling.py 项目: yghlc/tod
def main(name=None):
    name = name or "1"
    filename = "profiling_test_{}.png".format(name)
    config = Config()
    config.trace_filter = GlobbingFilter(exclude=[
        'a_module_you_want_to_exclude.*',
        '*.a_function_you_want_to_exclude',
    ])

    single_analysis(config, filename)
示例#11
0
def main():
    graphviz = GraphvizOutput()
    graphviz.output_file = 'basic.png'
    config = Config()
    config.max_depth = 5  # 控制最大追踪深度

    with PyCallGraph(output=graphviz, config=config):
        person = Person()
        for a in range(10):
            person.add_banana(Banana())
        person.eat_bananas()
示例#12
0
文件: common.py 项目: chy4412312/MyCT
    def callgraphwrapper(*args, **kwargs):
        if flag == 1 and ISCALLGRAPH:
            config = Config()
            config.trace_filter = GlobbingFilter(exclude=['thirdparty.*'])
            graphviz = GraphvizOutput()
            graphviz.output_file = 'docx/callGraph.png'

            with PyCallGraph(output=graphviz, config=config):
                result = func(*args, **kwargs)
        else:
            result = func(*args, **kwargs)
        return result
示例#13
0
def main(ini=1, end=5, group=True, single=True):

    config = Config()
    config.trace_filter = GlobbingFilter(exclude=[
        'a_module_you_want_to_exclude.*',
        '*.a_function_you_want_to_exclude',
    ])

    if single:
        single_analysis(ini, end)

    if group:
        group_analysis(ini, end)
示例#14
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)
def get_runtime(length):
    filename = os.path.join('tmp', 'hdf5', 'many_runs.hdf5')

    with Environment(filename=filename,
                     log_levels=20,
                     report_progress=(0.0000002, 'progress', 50),
                     overwrite_file=True,
                     purge_duplicate_comments=False,
                     log_stdout=False,
                     summary_tables=False,
                     small_overview_tables=False) as env:

        traj = env.v_traj

        traj.par.f_apar('x', 0, 'parameter')

        traj.f_explore({'x': range(length)})

        max_run = 100

        for idx in range(len(traj)):
            if idx > max_run:
                traj.f_get_run_information(idx, copy=False)['completed'] = 1
        traj.f_store()

        if not os.path.isdir('./tmp'):
            os.mkdir('tmp')
        graphviz = CustomOutput()
        graphviz.output_file = './tmp/run_profile_storage_%d.png' % len(traj)
        service_filter = GlobbingFilter(include=['*storageservice.*'])

        config = Config(groups=True, verbose=True)
        config.trace_filter = service_filter

        print('RUN PROFILE')
        with PyCallGraph(config=config, output=graphviz):
            # start = time.time()
            # env.f_run(job)
            # end = time.time()
            for irun in range(100):
                traj._make_single_run(irun + len(traj) / 2)
                # Measure start time
                traj._set_start()
                traj.f_ares('$set.$', 42, comment='A result')
                traj._set_finish()
                traj._store_final(store_data=2)
                traj._finalize_run()
            print('STARTING_to_PLOT')
        print('DONE RUN PROFILE')
示例#16
0
def run(name, trace_filter=None, config=None, comment=None):
    if not config:
        config = Config()

    if trace_filter:
        config.trace_filter = trace_filter

    graphviz = GraphvizOutput()
    graphviz.output_file = "filter-{}.png".format(name)
    if comment:
        graphviz.graph_attributes["graph"]["label"] = comment

    with PyCallGraph(config=config, output=graphviz):
        banana = Banana()
        banana.eat()
示例#17
0
def run(name, trace_filter=None, config=None, comment=None):
    if not config:
        config = Config()

    if trace_filter:
        config.trace_filter = trace_filter

    graphviz = GraphvizOutput()
    graphviz.output_file = 'filter-{}.png'.format(name)
    if comment:
        graphviz.graph_attributes['graph']['label'] = comment

    with PyCallGraph(config=config, output=graphviz):
        banana = Banana()
        banana.eat()
示例#18
0
 def profiling_context(self, basename):
     from pycallgraph import PyCallGraph, Config  #@UnresolvedImport
     from pycallgraph.output import GraphvizOutput  #@UnresolvedImport
     config = Config()
     graphviz = GraphvizOutput(output_file='%s-%i.png' %
                               (basename, time.monotonic()))
     return PyCallGraph(output=graphviz, config=config)
def stdlib_trace(trace_processor, include_stdlib):
    trace_processor.config = Config(include_stdlib=include_stdlib)
    sys.settrace(trace_processor.process)
    re.match("asdf", "asdf")
    calls.one_nop()
    sys.settrace(None)
    return trace_processor.call_dict
示例#20
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")
示例#21
0
def run(name, trace_grouper=None, config=None, comment=None):
    if not config:
        config = Config()

    config.trace_filter = GlobbingFilter()

    if trace_grouper is not None:
        config.trace_grouper = trace_grouper

    graphviz = GraphvizOutput()
    graphviz.output_file = "grouper-{}.png".format(name)
    if comment:
        graphviz.graph_attributes["graph"]["label"] = comment

    with PyCallGraph(config=config, output=graphviz):
        example_with_submodules.main()
def get_runtime(length):
    filename = os.path.join('tmp', 'hdf5', 'many_runs.hdf5')

    with Environment(filename = filename,
                      log_levels=20, report_progress=(0.0000002, 'progress', 50),
                      overwrite_file=True, purge_duplicate_comments=False,
                      log_stdout=False,
                      summary_tables=False, small_overview_tables=False) as env:

        traj = env.v_traj

        traj.par.f_apar('x', 0, 'parameter')

        traj.f_explore({'x': range(length)})

        max_run = 100

        for idx in range(len(traj)):
            if idx > max_run:
                traj.f_get_run_information(idx, copy=False)['completed'] = 1
        traj.f_store()

        if not os.path.isdir('./tmp'):
            os.mkdir('tmp')
        graphviz = CustomOutput()
        graphviz.output_file = './tmp/run_profile_storage_%d.png' % len(traj)
        service_filter = GlobbingFilter(include=['*storageservice.*'])

        config = Config(groups=True, verbose=True)
        config.trace_filter = service_filter


        print('RUN PROFILE')
        with PyCallGraph(config=config, output=graphviz):
            # start = time.time()
            # env.f_run(job)
            # end = time.time()
            for irun in range(100):
                traj._make_single_run(irun+len(traj)/2)
                # Measure start time
                traj._set_start()
                traj.f_ares('$set.$', 42, comment='A result')
                traj._set_finish()
                traj._store_final(store_data=2)
                traj._finalize_run()
            print('STARTING_to_PLOT')
        print('DONE RUN PROFILE')
示例#23
0
def main_with_callgraph(paramFilename):

    from pycallgraph import PyCallGraph
    from pycallgraph import Config
    from pycallgraph import GlobbingFilter
    from pycallgraph.output import GraphvizOutput

    config = Config()
    config.trace_filter = GlobbingFilter(exclude=[
        'vtk.*',
        'evtk.*',
        'imageToVTK',
    ])
    graphviz = GraphvizOutput()
    graphviz.output_file = 'euler2d_callgraph.png'

    with PyCallGraph(output=graphviz, config=config):
        main()
示例#24
0
def main():
    graphviz = GraphvizOutput()
    graphviz.output_file = 'large.png'
    config = Config(include_stdlib=True)

    with PyCallGraph(output=graphviz, config=config):
        from urllib2 import urlopen
        from xml.dom.minidom import parseString
        parseString(urlopen('http://w3.org/').read())
示例#25
0
def run_with_callgraph(main_func, algo_wrapper, args=None, kwargs=None):

    config = Config()
    config.trace_filter = GlobbingFilter(
        exclude=['pyswarms.base.*', 'pyswarms.utils.*', 'numpy.*'],
        include=[
            'OptimusDem.*', 'RosenWithArgsDigitalTwin.*', 'pyswarms.*optimize',
            'pyswarms.backend.*compute_objective_function', 'main',
            'scipy.optimize.*basinhopping'
        ])
    config.max_depth = 12
    graphviz = GraphvizOutput(output_file='optimus_rosen_trace.png',
                              output_type='png')
    with PyCallGraph(output=graphviz, config=config):
        if args is None:
            main_func(algo_wrapper)
        else:
            main_func(algo_wrapper, args, kwargs)
示例#26
0
def main_with_callgraph(paramFilename):

    from pycallgraph import PyCallGraph
    from pycallgraph import Config
    from pycallgraph import GlobbingFilter
    from pycallgraph.output import GraphvizOutput

    config = Config()
    config.trace_filter = GlobbingFilter(exclude=[
        'vtk.*',
        'evtk.*',
        'imageToVTK',
    ])
    graphviz = GraphvizOutput()
    graphviz.output_file = 'euler2d_callgraph.png'

    with PyCallGraph(output=graphviz, config=config):
        main()
示例#27
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
示例#28
0
    def handle(self):
        if conf.MEASUREMENT_MODE_PROCESSOR:

            utilities.clean_folder(conf.PROF_FOLDER)

            if conf.PROFILER == 'cProfiler':
                import cProfile
                import pstats
                pr = cProfile.Profile()
                pr.enable()
                self.handle_clean()
                pr.disable()

                #pr.dump_stats(conf.PROF_FILE_PROCESSOR + "pickle") #pickled

                #readable
                sortby = 'cumulative'
                ps = pstats.Stats(pr,
                                  stream=open(
                                      conf.PROF_FILE_PROCESSOR + "prof",
                                      'w')).sort_stats(sortby)
                ps.print_stats()

            elif conf.PROFILER == 'LineProfiler':
                import line_profiler
                import pstats
                import io
                pr = line_profiler.LineProfiler(
                    self.handle_clean, get_sketches_from_relays_non_blocking,
                    Classes.CountSketchCt.aggregate, op.median_operation,
                    op.mean_operation, op.variance_operation)
                pr.enable()
                self.handle_clean()
                pr.disable()

                pr.print_stats(open(conf.PROF_FILE_PROCESSOR + "prof",
                                    'w'))  #readable
                #pr.dump_stats(conf.PROF_FILE_PROCESSOR + "pickle") #pickled

            elif conf.PROFILER == "viz":
                from pycallgraph import PyCallGraph
                from pycallgraph.output import GraphvizOutput
                from pycallgraph import Config

                config = Config(max_depth=conf.DEPTH)
                graphviz = GraphvizOutput()
                graphviz.output_file = conf.PROF_FILE_PROCESSOR + 'png'
                with PyCallGraph(output=graphviz, config=config):
                    self.handle_clean()

            else:
                self.handle_clean()

        else:
            self.handle_clean()
示例#29
0
def main():
    graphviz = GraphvizOutput()
    graphviz.output_file = "large.png"
    config = Config(include_stdlib=True)

    with PyCallGraph(output=graphviz, config=config):
        from xml.dom.minidom import parseString

        import requests

        parseString(requests.get("https://w3.org/").content)
示例#30
0
def gscontext(filename, exclude=None, max_depth=None):
    """Generate a call graph for the enclosed context

    Output a call graph to the chosen filename (introspecting the
    format along the way), optionally excluding some items.

    Args:
        filename (str): The output filename
	exclude (Optional[list]): The globbing strings to exclude. Defaults to ['graphstack.*'].
	max_depth (Optional[int]): The maximum recursion depth to plot. Defaults to infinite.

    """

    globkwargs = {
        'exclude': [
            'graphstack.*',
        ],
    }
    if exclude is not None:
    	globkwargs['exclude'].extend(exclude)
    if max_depth is not None:
        globkwargs['max_depth'] = max_depth

    # Configure exclusion filtering
    config = Config()
    config.trace_filter = GlobbingFilter(**globkwargs)

    # Configure GraphViz output
    fnsplit = os.path.splitext(filename)
    if len(fnsplit) == 1:
        outfile = filename + '.pdf'
        filetype = 'pdf'
    elif len(fnsplit) == 2:
        outfile = filename
        filetype = fnsplit[1][1:]
    graphviz = GraphvizOutput(output_file=outfile)
    graphviz.output_type = filetype

    # Set up context manager
    with PyCallGraph(output=graphviz, config=config):
        yield
示例#31
0
    def generate_callgraph(*args, **kwargs):
        """ set up before starting generate callgraph and take function func as starting point """
        from pycallgraph import PyCallGraph
        from pycallgraph import Config
        from pycallgraph.output import GraphvizOutput

        graphviz = GraphvizOutput()
        graphviz.output_file = 'colorvim.png'
        config = Config(groups=True)

        with PyCallGraph(config=config, output=graphviz):
            func(*args, **kwargs)
示例#32
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()
示例#33
0
 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
示例#34
0
def main():
    import_list = (
        'pickle',
        'htmllib',
        'urllib2',
    )
    graphviz = GraphvizOutput()
    config = Config(include_stdlib=True)

    for module in import_list:
        graphviz.output_file = 'import-{}.png'.format(module)
        with PyCallGraph(output=graphviz, config=config):
            __import__(module)
示例#35
0
def profile_callgraph(fn):
    '''
    Given the function to profile (serial function), profiles the python call graph for the function.

    Args:
        fn (python func): Function to profile
    Returns: 
         Nothing (saves a visualization of the call graph to file.) 
    '''
    logging.info('PROFILING CALL GRAPH ...')

    config = Config()
    config.trace_filter = GlobbingFilter(exclude=[
        'ModuleSpec.*', 'logging.*', '*_handle_fromlist*', 'multiprocessing.*',
        'threading.*'
    ])

    graphviz = GraphvizOutput(output_file='profile_example.png')

    with PyCallGraph(output=graphviz, config=config):
        fn()

    logging.info('PROFILED CALL GRAPH.')
示例#36
0
def main():
    import_list = (
        "pickle",
        "html.parser",
        "requests",
        # TODO: import-requests.png is not generated as the other two libraries.
    )
    graphviz = GraphvizOutput()
    config = Config(include_stdlib=True)

    for module in import_list:
        graphviz.output_file = f"import-{module}.png"
        with PyCallGraph(output=graphviz, config=config):
            __import__(module)
示例#37
0
#!/usr/bin/env python

from pycallgraph import PyCallGraph
from pycallgraph import Config
from pycallgraph import GlobbingFilter
from pycallgraph.output import GraphvizOutput

from banana import Banana


config = Config()
config.trace_filter = GlobbingFilter(exclude=[
    'pycallgraph.*',
    '*.secret_function',
])

graphviz = GraphvizOutput(output_file='filter_exclude.png')

with PyCallGraph(output=graphviz, config=config):
    banana = Banana()
    banana.eat()
示例#38
0
pmodelargs2 = [Alpha(1, 0, 0, 0.2, 0, 0., 1)]
pmodelargs3 = [NFW(2, 0, 0, 0, 0, 0.5, 1, 0.5)]
ppolargs2 = [[(0, 0), 0.9, 10, 42]]
# lower bound, upper bound, initial spacing (two sets--for x and y axes)
pcarargs = [
        [-2.5, 2.5, 0.5],
        [-2.5, 2.5, 0.5]
    ]
pimage = [0.25, 0.25]  # image location -if- we want to specify
##############################

# If we want an image with runtime stats, set bool to true, otherwise runs the statement in the else branch.
callgraph = False

if callgraph:
    from pycallgraph import PyCallGraph, Config, GlobbingFilter
    from pycallgraph.output import GraphvizOutput
    filepath = 'runs/alphafintelparallel.png'  # where we want to save the output image with the runtime breakdown
    config = Config()
    config.trace_filter = GlobbingFilter(exclude=[
            'num*',
            'scipy*',
            'pycallgraph*'
        ])
    with PyCallGraph(output=GraphvizOutput(output_file=filepath), config=config):
        example = Gravlens(pcarargs, ppolargs2, pmodelargs2, image=pimage, show_plot=False, include_caustics=False)
        example.run()
else:
    example = Gravlens(pcarargs, ppolargs2, pmodelargs3, image=pimage, include_caustics=True, logging_level='info')
    example.run()
示例#39
0
#!/usr/bin/env python

from pycallgraph import PyCallGraph, Config, GlobbingFilter
from pycallgraph.output import GraphvizOutput

import pond

graphviz = GraphvizOutput(output_file='out.png')
config = Config()
config.trace_filter = GlobbingFilter(exclude=[
    'argparse.*',
    'pycallgraph.*',
])

with PyCallGraph(output=graphviz, config=config):
    pond._main()
示例#40
0
def config_setup():
    config = Config()
    config.trace_filter = GlobbingFilter(include=['hangman.*'])
    return config
#!/usr/bin/env python3

from pycallgraph import PyCallGraph
from pycallgraph import Config
from pycallgraph import GlobbingFilter
from pycallgraph.output import GraphvizOutput

from orthoimage import main

graphviz = GraphvizOutput(output_file='pycallgraph_orthoimage.png')
config = Config(max_depth=10)
config.trace_filter = GlobbingFilter(exclude=[
    'pycallgraph.*',
    'posixpath.*',
    'os.*',
    'contextlib',
])

with PyCallGraph(output=graphviz, config=config):
    main()
示例#42
0
__author__ = 'Docopoper'

from globals import *
import os

if __name__ == '__main__':
    if os.getenv("PROFILE") is not None:
        import subprocess
        from pycallgraph import PyCallGraph
        from pycallgraph import Config
        from pycallgraph import GlobbingFilter
        from pycallgraph.output import GraphvizOutput
        from time import sleep

        config = Config()
        config.trace_filter = GlobbingFilter()#include=['Objects.*', "pyglet.*", "Ctrl.*"],
                                             #exclude=['Objects.Menu.*'])

        if os.getenv("PNG") is None:
            graphviz = GraphvizOutput(output_file='filter_exclude.xdot', output_type='xdot')
        else:
            graphviz = GraphvizOutput(output_file='filter_exclude.png', output_type='png')

        with PyCallGraph(output=graphviz, config=config):
            pyglet.app.run()

        if os.getenv("PNG") is None:
            sleep(1)
            subprocess.call("python -m xdot \"" + os.path.dirname(os.path.realpath(__file__)) + "\\filter_exclude.xdot\"")
    else:
        pyglet.app.run()
示例#43
0
    def test_consecutive_merges(self):

        ntrajs = 41
        for irun in range(ntrajs):
            self.envs.append(self._make_env(irun))
            self.trajs.append(self.envs[-1].v_traj)
            self.trajs[-1].f_add_parameter('x',0)
            self.trajs[-1].f_add_parameter('y',0)
            self.explore(self.trajs[-1])

        timings = []
        for irun in range(ntrajs):
            self.envs[irun].f_run(multiply)
            start = time.time()
            # self.trajs[irun].f_load_skeleton()
            # end = time.time()
            # delta = end -start
            # timings.append(delta)
        print timings

        merge_traj = self.trajs[0]
        merge_traj.f_load_skeleton()

        timings = []

        for irun in range(1, ntrajs):
            start = time.time()
            if False and (irun == ntrajs -1 or irun == 1):
                if not os.path.isdir('./tmp'):
                    os.mkdir('tmp')
                graphviz = CustomOutput()
                graphviz.output_file = './tmp/merge_nskelteon_%d.png' % irun
                # service_filter = GlobbingFilter(include=['*storageservice.*', '*ptcompat.*',
                #                                          '*naturalnaming.*', '*parameter.*',
                #                                          '*trajectory.*'])
                service_filter = GlobbingFilter(include=['*trajectory.*', '*storageservice.*'])
                config = Config(groups=True, verbose=True)
                config.trace_filter = service_filter
                print('RUN MERGE')
                with PyCallGraph(config=config, output=graphviz):
                    merge_traj.f_merge(self.trajs[irun], backup=False, consecutive_merge=True,
                                       delete_other_trajectory=True)
                print('DONE MERGING')
            else:
                merge_traj.f_merge(self.trajs[irun], backup=False, consecutive_merge=True,
                                   delete_other_trajectory=True)
            end = time.time()
            delta = end -start
            timings.append(delta)

        print(timings)
        # # Test if there is no linear dependency for consecutive merges:
        # if self.strictly_increasing(timings) and len(timings) > 1:
        #     raise ValueError('Timings %s are strictly increasing' % str(timings))
        # r, alpha = pearsonr(range(len(timings)), timings)
        # logging.error('R and Alpha of consecutive merge test %s' % str((r,alpha)))
        # if alpha < 0.01:
        #     raise ValueError( 'R and Alpha of consecutive merge test %s\n' % str((r,alpha)),
        #         'Timings %s are lineary increasing' % str(timings))

        merge_traj.f_store()
        merge_traj.f_load(load_data=2)
        self.check_if_z_is_correct(merge_traj)
示例#44
0
+----------------------------------------------+--------------------------+
"""

year, month = 2017, 5
# 3.2 Access to csv file using Vintage class (identical to 3.1)
from csv2df.runner import Vintage


####################  PyCallGraph
from pycallgraph import PyCallGraph
from pycallgraph import GlobbingFilter
from pycallgraph import Config
from pycallgraph import Grouper
from pycallgraph.output import GraphvizOutput

config = Config()

# needed to group by submodules
config.trace_grouper = Grouper(groups=[
        "csv2df.reader.*" ,
        "csv2df.parser.*" ,
        "csv2df.emitter.*" ,
        "csv2df.validator.*" ,  # currently not used
        "csv2df.runner.*" ,

        'csv2df.util_row_splitter.*',
        'csv2df.specification.*',
    ])

config.trace_filter = GlobbingFilter
config.trace_filter = GlobbingFilter(exclude=[
from astropy.table import Table
import progressbar as PGB
import antenna_array as AA
import data_interface as DI
import geometry as GEOM
import sim_observe as SIM
import my_DSP_modules as DSP
from pycallgraph import PyCallGraph, Config, GlobbingFilter
from pycallgraph.output import GraphvizOutput
import ipdb as PDB

infile = '/data3/t_nithyanandan/project_MOFF/data/samples/lwa_data.CDF.fits'
du = DI.DataHandler(indata=infile)
max_n_timestamps = 4

config = Config(max_depth=5, groups=True)
graphviz = GraphvizOutput(output_file='/data3/t_nithyanandan/project_MOFF/data/samples/figures/profile_graph_{0:0d}_iterations.png'.format(max_n_timestamps))
config.trace_filter = GlobbingFilter(include=['antenna_array.*'])

# exclude=['progressbar.*', 'numpy.*', 'warnings.*', 'matplotlib.*', 'scipy.*', 'weakref.*', 'threading.*', 'six.*', 'Queue.*', 'wx.*', 'abc.*', 'posixpath.*', '_weakref*', 'astropy.*', 'linecache.*', 'multiprocessing.*', 'my_*', 'geometry.*'], 

lat = du.latitude
f0 = du.center_freq
nts = du.nchan
nchan = nts * 2
fs = du.sample_rate
dt = 1/fs
freqs = du.freq
channel_width = du.freq_resolution
f_center = f0
bchan = 100
示例#46
0
  parser.add_argument('--server', dest="server_name", type=str, default="",
                      help='the name of the server')

  parser.add_argument('--graph', dest="pcg_graph",
                      action="store_true", default=False)

  args = parser.parse_args()

  # read the program file
  program_file = args.file
  program_raw = program_file.read()
  program_file.close()

  if PCG_AVAILABLE and args.pcg_graph:
    config = Config()
    config.trace_filter = GlobbingFilter(exclude=[
      'pedroclient.*',
      'Queue.*',
      'threading.*',
      'socket.*',
      'pycallgraph.*'
    ])

    parsing_graph_output = GraphvizOutput()
    parsing_graph_output.output_file = 'parsing_graph.png'

    tr_graph_output = GraphvizOutput()
    tr_graph_output.output_file = 'tr_graph.png'

  # parse the program's source code
示例#47
0

def test_load():
    newtraj = load_trajectory(index=-1, filename=filename, load_data=1)


if __name__ == '__main__':
    if not os.path.isdir('./tmp'):
        os.mkdir('tmp')
    graphviz = CustomOutput()
    graphviz.output_file = './tmp/run_profile_traj_slots.png'
    # service_filter = GlobbingFilter(include=['*storageservice.*', '*ptcompat.*',
    #                                          '*naturalnaming.*', '*parameter.*',
    #                                          '*trajectory.*'])
    service_filter = GlobbingFilter(include=['*naturalnaming.*', '*trajectory.*'])

    config = Config(groups=True, verbose=True)
    config.trace_filter = service_filter

    print('RUN PROFILE')
    with PyCallGraph(config=config, output=graphviz):
        test_run()
    print('DONE RUN PROFILE')

    graphviz = CustomOutput()
    graphviz.output_file = './tmp/load_mode_1_profile_traj_slots.png'

    print('LOAD PROFILE')
    with PyCallGraph(config=config, output=graphviz):
        test_load()
    print('DONE LOAD PROFILE')
示例#48
0
#!/usr/bin/env python

from pycallgraph import PyCallGraph
from pycallgraph import Config
from pycallgraph import GlobbingFilter
from pycallgraph.output import GraphvizOutput

from skypyblue_test import *

config = Config()
config.trace_filter = GlobbingFilter(exclude = [
  '*listcomp*',
  '*lambda*',
  '*max_out*',
  '*enum*',
  '*skypyblue_test*',
  '*weaker*',
  '*__init__*',
  '*equality_constraint*',
  '*scale_constraint*',
  '*has_invalid_vars*',
  '*_check_constraints*',
  '*_new_mark*',
  '*pycallgraph*'
])
config.groups = True

graphviz = GraphvizOutput()

with PyCallGraph(output = graphviz, config = config):
  skypyblue(1)
示例#49
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
import time

sys.path.insert(0, '../dac')
import dac

from pycallgraph import GlobbingFilter
from pycallgraph import PyCallGraph
from pycallgraph import Config
from pycallgraph.output import GraphvizOutput

config = Config(max_depth=10, verbose=True)
config.trace_filter = GlobbingFilter(exclude=['lxml.*', 'requests.*',
    'sklearn.*', 'pycallgraph.*'], include=['dac.EntityLinker.link',
    'dac.Context.get_metadata', 'dac.Context.get_entities',
    'dac.Context.get_topics', 'dac.Description.get_vectors',
    'dac.CandidateList.query_solr', 'dac.Entity.suggest'])
graphviz = GraphvizOutput(output_file='profile_' + str(int(time.time())) + '.png')

with PyCallGraph(output=graphviz, config=config):
    linker = dac.EntityLinker(model='svm', debug=True)
    linker.link('http://resolver.kb.nl/resolve?urn=ddd:010734861:mpeg21:a0002:ocr')
    linker.link('http://resolver.kb.nl/resolve?urn=ddd:010616555:mpeg21:a0126:ocr')
    linker.link('http://resolver.kb.nl/resolve?urn=ddd:110577489:mpeg21:a0193:ocr')
    linker.link('http://resolver.kb.nl/resolve?urn=ddd:010620323:mpeg21:a0248:ocr')
    linker.link('http://resolver.kb.nl/resolve?urn=ddd:010369397:mpeg21:a0040:ocr')