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))
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
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
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)
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
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)
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
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)
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")
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)
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 filter_depth(): config = Config() config.max_depth = 1 run( 'max_depth', config=config, comment='Should only show a depth of one.' )
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())
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)
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()
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()
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)
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)
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
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()
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)
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)
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 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)
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')
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()
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 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()
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)
def main(): logger.info('Start calculation') graphviz = GraphvizOutput() date = str(datetime.now().strftime("%Y-%m-%d-%H-%M-%S")) graphviz.output_file = 'results/' + str(date) + '_basic_process_plot.png' logger.info("Time: {} ".format(date)) with PyCallGraph(output=graphviz, config=Config(groups=True)): ego = eGo(jsonpath='scenario_setting_local.json') logger.info('Start testing') ego_testing(ego) # object size logger.info("eGo object size: {} ".format(sys.getsizeof(ego))) logger.info("Time: {} ".format(str(datetime.now())))