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 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 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 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 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 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 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
from pycallgraph import PyCallGraph from pycallgraph import Config from pycallgraph.output import GraphvizOutput from pycallgraph import GlobbingFilter import main config = Config(max_depth=5) graphviz = GraphvizOutput(output_file='filter_max_depth.png') config.trace_filter = GlobbingFilter(exclude=[ 'pycallgraph.*', '*.secret_function', 'open', 'print', '*.append', '*.keys', '*.items', '*.close', '_find_and_load', '*._find_and_load' ]) graphviz = GraphvizOutput(output_file='filter_exclude.png') with PyCallGraph(output=graphviz, config=config): main.main()
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,
filename = None def to_test(traj, length): for irun in range(length): traj._add_run_info(irun) 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/traj_add_run_info.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): to_test(Trajectory(), 10000) print('DONE RUN PROFILE')
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 parsed_program = grammar.program.parseString(program_raw) if PCG_AVAILABLE and args.pcg_graph: with PyCallGraph(output=parsing_graph_output, config=config):
from pycallgraph import Config from pycallgraph import GlobbingFilter import config_parser import key_validator ################## # Parser section ################## parser_graphviz = GraphvizOutput( output_file='../../media/CallGraphDiagrams/parser_call_graph.png') parser_config = Config() parser_config.trace_filter = GlobbingFilter( include=['config.parser.*', "util*", "config.util*"], exclude=['*listcomp*', "*genexpr*"]) with PyCallGraph(output=parser_graphviz, config=parser_config): config_parser.main([ "-i", "config/parser/parser_test_resources/test_input.config", "--jsonTemplate", "config/parser/parser_test_resources/test_output_template.json", "-o", "config/parser/parser_test_resources/test_output.json" ]) ##################### # Validator section ##################### validator_graphviz = GraphvizOutput(
from pycallgraph import PyCallGraph from pycallgraph import Config from pycallgraph.output import GraphvizOutput from pycallgraph import GlobbingFilter from . import SymEngineFast import symengine as si import os if (__name__ == "__main__"): config = Config(max_depth=4) config.trace_filter = GlobbingFilter( include=['C_F_S*', '__main__', '<module>', 'MainProg', 'ctypes*']) graphviz = GraphvizOutput(output_file='PyCallGraphMinimizer.png') with PyCallGraph(output=graphviz, config=config): SymEngineFast.MainProg()
import os import argparse from src.iohandler import Input from src.two_element_beam_model import TwoElementBeamModel from src.kite_model import KiteModel from pycallgraph import PyCallGraph from pycallgraph import Config from pycallgraph import GlobbingFilter from pycallgraph.output import GraphvizOutput config = Config(groups=True) config.trace_filter = GlobbingFilter(exclude=[ 'codecs*', '_bootlocale*', '_weakrefset*', 'pycallgraph.*', 'posixpath*', 'abc*', ]) # Parse the input arguments description = "Creates a set of MBDyn input files from a model definition." parser = argparse.ArgumentParser(description=description) parser.add_argument("-i", "--input-file", nargs=1, required=True, help="Path to the preprocessor input file") parser.add_argument( "-o", "--output-directory",
def config_setup(): config = Config() config.trace_filter = GlobbingFilter(include=['hangman.*']) return config
from pycallgraph import PyCallGraph from pycallgraph import Config from pycallgraph import GlobbingFilter from pycallgraph.output import GraphvizOutput import test if __name__ == '__main__': config = Config() config.trace_filter = GlobbingFilter(include=[ 'pycallgraph.*', 'Search_V2.*', '*test*', ]) graphviz = GraphvizOutput() graphviz.output_file = 'basic2.png' with PyCallGraph(output=graphviz, config=config): test.test_data_system()
# 查询特定挂单信息,需要提供挂单ID # d = Dealer(market = "btctrade", coin = "btc", logging = True) # print d.fetch_order() # 查询挂单信息 # d = Dealer(market = "btctrade", coin = "btc", logging = True) # print d.get_orders('all') #code_to_profile() if __name__ == '__main__': #import related libraries from pycallgraph import PyCallGraph from pycallgraph.output import GraphvizOutput from pycallgraph import Config, GlobbingFilter #config here, check definitions to find more options config = Config(max_depth=10) graphviz = GraphvizOutput(output_type='svg', output_file='filter_max_depth.svg') #graphviz = GraphvizOutput(output_type='png', output_file='filter_max_depth.png') config.trace_filter = GlobbingFilter(exclude=['abc.*', 'okk']) #do profiling and intercall relationship graphing with PyCallGraph(output=graphviz, config=config): # run main program main()
rgbimage.rgb_image_show_color(result_image, maxvalue=255, color="color", compress_ratio=1) if __name__ == "__main__": config = Config() # 关系图中包括(include)哪些函数名。 # 如果是某一类的函数,例如类gobang,则可以直接写'gobang.*',表示以gobang.开头的所有函数。(利用正则表达式)。 config.trace_filter = GlobbingFilter(include=[ 'main', 'rgb2ycbcr', 'grey_world', 'auto_threshold', 'set_border', 'dilation33', 'gDer', 'NormDerivative', 'grey_edge', 'apply_raw', 'apply_to_rgb', 'rgb_separation', 'raw_awb_separation', 'raw_white_balance', 'RGB_white_balance' ]) # 该段作用是关系图中不包括(exclude)哪些函数。(正则表达式规则) # config.trace_filter = GlobbingFilter(exclude=[ # 'pycallgraph.*', # '*.secret_function', # 'FileFinder.*', # 'ModuleLockManager.*', # 'SourceFilLoader.*'
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')
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)
def make_server(host, port, app, server_class=WSGIServer, handler_class=WSGIRequestHandler): """Create a new WSGI server listening on `host` and `port` for `app`""" server = server_class((host, port), handler_class) server.set_app(app) return server config = Config(max_depth=200) config.trace_filter = GlobbingFilter(include=[ 'socketserver.*', 'http.server.*' 'wsgiref.*', 'selectors.*', 'bottle.*' ]) graphviz = GraphvizOutput(output_file='grpah.png') if __name__ == '__main__': with PyCallGraph(output=graphviz, config=config): app = Bottle() @app.route('/hello') def hello(): return "Hello World!" with make_server('', 8000, app) as httpd: sa = httpd.socket.getsockname() print("Serving HTTP on", sa[0], "port", sa[1], "...") # import webbrowser
methods = [csp.recursive_solution, csp.memo_dict_solution, csp.dp_solution] time_costs = {} for method in methods: time_costs[method.__name__] = [] for n in range(1, 20): time_start = time.time() results = method(n) time_cost = time.time() - time_start time_costs[method.__name__].append(time_cost) # 三种算法的对比 plt.figure(figsize=[8, 6]) for method_name in time_costs.keys(): plt.plot(time_costs[method_name]) plt.legend([p[:-9] for p in time_costs.keys()]) plt.xlabel('number of stairs') plt.ylabel('time cost (seconds)') plt.grid(True) if __name__ == '__main__': config = Config() config.trace_filter = GlobbingFilter(exclude=[ 'pycallgraph.*', '*.secret_function', '*pydev*', '_handle_fromlist', '__new__' ]) graphviz = GraphvizOutput() graphviz.output_file = 'graph.png' with PyCallGraph(output=graphviz, config=config): main()
import os import unittest from src.dtd_parser.dtd_parser import DTDParser os.environ["PATH"] += os.pathsep + 'C:/Program Files (x86)/Graphviz2.38/bin/' from pycallgraph import PyCallGraph, Config, GlobbingFilter from pycallgraph.output import GraphvizOutput class TestDTDParserParseString(unittest.TestCase): def test_1element(self): parser = DTDParser() parser.parse_string('<!ELEMENT note (#PCDATA)>') self.assertEqual(len(parser._tokens), 1) config = Config(groups=True) config.trace_filter = GlobbingFilter(include=['src.*', 'Test*']) with PyCallGraph(config=config, output=GraphvizOutput(output_file='graph.png')): x = TestDTDParserParseString() x.setUp() x.test_1element()
#!/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')
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)
_GENERATE_CALL_GRAPH = False _CALL_GRAPHS_PATH = path.abspath(path.join(".", "calls")) # Create Call diagrams folder if _GENERATE_CALL_GRAPH: try: os.makedirs(_CALL_GRAPHS_PATH) except OSError as ex: if ex.errno == errno.EEXIST and os.path.isdir(_CALL_GRAPHS_PATH): pass else: raise _call_graph_config = Config() _call_graph_config.trace_filter = GlobbingFilter(exclude=['pycallgraph.*']) def call_graph_ignore(*args): global _call_graph_config for exclude in args: if exclude not in _call_graph_config.trace_filter.exclude: _call_graph_config.trace_filter.exclude.append(exclude) def generate_call_graph(func): """Generates Call Graph for the called function""" def wrapper(s, *args, **kwargs): if _GENERATE_CALL_GRAPH: caller_func = func.__name__ if len(args) > 1:
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()
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. """ import sys from floris.floris import Floris from pycallgraph import PyCallGraph from pycallgraph import Config from pycallgraph import GlobbingFilter from pycallgraph.output import GraphvizOutput config = Config(groups=True) config.trace_filter = GlobbingFilter(exclude=[ 'pycallgraph.*', 'json*', 'codecs*', '_bootlocale*', '_weakrefset*' ]) graphviz = GraphvizOutput() graphviz.output_file = 'initialization.png' with PyCallGraph(config=config, output=graphviz): if len(sys.argv) > 1: floris = Floris(sys.argv[1]) else: floris = Floris("example_input.json") graphviz = GraphvizOutput() graphviz.output_file = 'calculate_wake.png' with PyCallGraph(config=config, output=graphviz): floris.farm.flow_field.calculate_wake()
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=[ 'csv2df.util_row_splitter.*', 'csv2df.specification.*', "csv2df.reader.*" , "config.*" , ]) graphviz = GraphvizOutput() graphviz.output_file = 'pcg_example_Vintage.svg' graphviz.output_type = 'svg' with PyCallGraph(output=graphviz, config=config):
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)
from pycallgraph import PyCallGraph from pycallgraph.output import GraphvizOutput from pycallgraph import Config from pycallgraph import GlobbingFilter #import torch.nn as nn from torch.nn.modules.module import Module config = Config() config.trace_filter = GlobbingFilter(include=[ 'torch.nn.modules.module.Module.parameters', 'torch.nn.modules.module.Module.named_parameters', 'torch.nn.modules.module.Module._named_members', 'torch.nn.modules.module.Module.named_modules' ]) graphviz = GraphvizOutput() graphviz.font_size = 10 graphviz.group_font_size = 10 graphviz.output_file = 'graph.png' with PyCallGraph(output=graphviz, config=config): mod = Module() for item in mod.parameters(): pass
# 关系图中包括(include)哪些函数名。 # 如果是某一类的函数,例如类gobang,则可以直接写'gobang.*',表示以gobang.开头的所有函数。(利用正则表达式)。 # config.trace_filter = GlobbingFilter(include=myinclude), # 该段作用是关系图中不包括(exclude)哪些函数。(正则表达式规则) ################# 排除过滤 ######################## # config.trace_filter = GlobbingFilter(exclude=[ # 'pycallgraph.*', # '*.secret_function', # 'FileFinder.*', # '_ModuleLockManager.*', # 'SourceFilLoader.*', # ], # include=myinclude) ################# end ########################### ################# 包含过滤 ######################## config.trace_filter = GlobbingFilter(include=myinclude) ################# end ########################### graphviz = GraphvizOutput() save_name = 'graph.png' graphviz.output_file = save_name with PyCallGraph(output=graphviz, config=config): # with PyCallGraph(output=graphviz): vis_program() # mat = cv2.imread(save_name) # cv2.imshow(save_name,mat) # cv2.waitKey(10000) #显示图片,不用cv2 command = 'eog ' + save_name str = os.system('%s' % (command))
# add profiling - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - from pycallgraph import PyCallGraph from pycallgraph.output import GraphvizOutput # for globbing filter - include / exclude sections of call graph to focus from pycallgraph import Config from pycallgraph import GlobbingFilter config = Config(max_depth=4) config.trace_filter = GlobbingFilter( exclude=[ 'urllib.*', # 'pprint.*', # 'http.*', # #'pycallgraph.*', # #'*.secret_function', ], include=[ # '*', 'helpers.*', 'populate_db.*', ]) # profiling output into PNG format image - not searchable graphviz = GraphvizOutput(output_file='filter_A.png') # add profiling - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - from pathlib import Path # loads csv file from server and loads into database LIVE
from pycallgraph import Config from pycallgraph import GlobbingFilter from pycallgraph.output import GraphvizOutput from solar_system import * config = Config() config.trace_filter = GlobbingFilter(exclude=[ 'pycallgraph.*', '*.secret_function', '_*', 'SourceFileLoader*', 'ModuleSpec*', 'ExtensionFileLoader*', 'FileFinder*', 'find_spec*', '<listcomp>', 'spec_*', 'module_*', 'cache_*', '<genexpr>', 'cb', '*FileFinder', '<setcomp>', ]) graphviz = GraphvizOutput(output_file='PyCallGraph.png') with PyCallGraph(output=graphviz, config=config): x = SolarSim(TOTAL_TIME=3000, INITIAL_SPACEBODIES=150, ANIMATION_INTERVAL=50, FRAME_SAMPLE_RATE=15)
import os from db import DB from modules import FileSystem #from: https://pycallgraph.readthedocs.io/en/master/guide/filtering.html from pycallgraph import PyCallGraph from pycallgraph import Config from pycallgraph import GlobbingFilter from pycallgraph.output import GraphvizOutput config = Config() config.trace_filter = GlobbingFilter(include=['db.*', 'DB.*', 'modules.*']) # config.trace_filter = GlobbingFilter(include=[ # 'db.trans*', # 'db.cat*', # 'db.OP*', # 'db.DB.__*', # 'db.CAT.__', # 'db.TRANS.add*' # ]) #graphviz = GraphvizOutput(output_file='./testing/structure_PyCallGraph.dot', output_type='dot') graphviz = GraphvizOutput(output_file='./testing/structure_PyCallGraph.png') graph = False def foo(): fs = FileSystem() db = DB()
try: from pycallgraph import PyCallGraph from pycallgraph import Config from pycallgraph import GlobbingFilter from pycallgraph import Grouper from pycallgraph.output import GraphvizOutput except ImportError: print "You need to install pycallgraph (for instance with `pip install pycallgraph`)." raise from run_finmag import run_simulation config = Config() config.trace_grouper = Grouper(groups=[ "finmag.util.*", "finmag.integrators.*", "finmag.energies.*", "finmag.sim.*", ]) # `max_depth`=15 is the level that would account for all calls to # Exchange.__compute_field_petsc; 14 would miss those from TableWriter.save config.trace_filter = GlobbingFilter(include=[ 'finmag.*', 'run_finmag.*', ]) graphviz = GraphvizOutput(output_file='finmag_callgraph.png') with PyCallGraph(output=graphviz, config=config): run_simulation()
a1 = PyMacroParser() a1.load("b.cpp") a1.dumpDict() a1.dump('c.cpp') if __name__ == "__main__": config = Config() config.trace_filter = GlobbingFilter(include=[ 'filterComment', 'deelWithIfelse', 'load', 'preDefine', 'deelStringtest', 'deeltab', 'string2other', 'dictDataConversion', 'dataInCpp', 'tuple2cpp', 'dumpDict', 'dump', 'tip', ]) graphviz = GraphvizOutput() graphviz.output_file = 'graph.png' with PyCallGraph(output=graphviz, config=config): main()
from pycallgraph import PyCallGraph from pycallgraph import Config from pycallgraph import GlobbingFilter from pycallgraph.output import GraphvizOutput config = Config() config.trace_filter = GlobbingFilter(exclude=[ '*_find_and_load_unlocked', '*_load_unlocked', '*_handle_fromlist', '*ModuleSpec*' ]) import numpy as np import matplotlib.pyplot as plt import less np.random.seed(42) x = np.linspace(0, 2 * np.pi, 50) y = np.sin(x) y2 = y + 0.1 * np.random.normal(size=x.shape) mask = np.abs(y - y2) > 0.18 # tweak one point to be better within bounds i = [i for i, e in enumerate(mask) if e][-1] y2[i] += 2 * (y[i] - y2[i]) typical_x, typical_y = x[mask == False], y2[mask == False] outlier_x, outlier_y = x[mask], y2[mask] with PyCallGraph(output=GraphvizOutput(), config=config):
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 echan = 925 max_antenna_radius = 75.0 # in meters
__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()
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 echan = 925 max_antenna_radius = 75.0 # in meters
#!/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()
#!/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()
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations under # the License. # See https://floris.readthedocs.io for documentation import sys from pycallgraph import Config, PyCallGraph, GlobbingFilter from floris.simulation import Floris from pycallgraph.output import GraphvizOutput config = Config(groups=True) config.trace_filter = GlobbingFilter(exclude=[ "pycallgraph.*", "json*", "codecs*", "_bootlocale*", "_weakrefset*" ]) graphviz = GraphvizOutput() graphviz.output_file = "initialization.png" with PyCallGraph(config=config, output=graphviz): if len(sys.argv) > 1: floris = Floris(sys.argv[1]) else: floris = Floris("../examples/example_input.json") graphviz = GraphvizOutput() graphviz.output_file = "calculate_wake.png" with PyCallGraph(config=config, output=graphviz): floris.farm.flow_field.calculate_wake()
import matplotlib.pyplot as plt from gastop import GenAlg, utilities from pycallgraph import PyCallGraph from pycallgraph import Config from pycallgraph import GlobbingFilter from pycallgraph.output import GraphvizOutput # Parse input paramters from init.txt file init_file_path = 'gastop-config/struct_making_test_init2.txt' config = utilities.init_file_parser(init_file_path) pop_size = config['ga_params']['pop_size'] num_gens = config['ga_params']['num_generations'] conf = Config() conf.trace_filter = GlobbingFilter(include=['__main__', 'gastop.*']) graphviz = GraphvizOutput(output_file='filter_exclude4.png') with PyCallGraph(output=graphviz, config=conf): # Create the Genetic Algorithm Object ga = GenAlg(config) ga.initialize_population(200) best, progress_history = ga.run(num_generations=10, progress_display=1, num_threads=1) # con = best.edges.copy() # matl = best.properties.copy() # matl = matl[(con[:, 0]) >= 0]
# See the License for the specific language governing permissions and # limitations under the License. """ This script creates the pycallgraph file output_file='pyrate_with_roipac.png'. This script can be run from the 'PyRate' directory. Change the name of the config file as required. """ import sys from pycallgraph import PyCallGraph from pycallgraph import Config from pycallgraph import GlobbingFilter from pycallgraph.output import GraphvizOutput from pyrate.scripts import run_pyrate config = Config() config.trace_filter = GlobbingFilter(exclude=[ 'pycallgraph.*', '*.secret_function', ]) graphviz = GraphvizOutput(output_file='pyrate_with_roipac.png') config = Config(max_depth=6, groups=False, threaded=True) # sys.argv[0]: name of this script # sys.argv[1]: name of the config file sys.argv = ['pyrate_profile.py', 'pyrate.conf'] with PyCallGraph(output=graphviz, config=config): run_pyrate.main()
#!/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()