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()
Example #2
0

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
Example #3
0
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",
Example #4
0
import sim_observe as SIM
import my_DSP_modules as DSP
import my_operations as OPS
import aperture as APR
from pycallgraph import PyCallGraph, Config, GlobbingFilter
from pycallgraph.output import GraphvizOutput
import ipdb as PDB

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.*'])

# Antenna initialization

lat = -26.701  # Latitude of MWA in degrees
f0 = 150e6  # Center frequency
nts = 8  # number of time samples in a time-series
nchan = 2 * nts  # number of frequency channels, factor 2 for padding before FFT

identical_antennas = True
antenna_file = '/data3/t_nithyanandan/project_MWA/MWA_128T_antenna_locations_MNRAS_2012_Beardsley_et_al.txt'
ant_info = NP.loadtxt(antenna_file,
                      skiprows=6,
                      comments='#',
                      usecols=(0, 1, 2, 3))
ant_info[:, 1:] = ant_info[:, 1:] - NP.mean(
Example #5
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 import process

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):
    process.main()
Example #6
0
# 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()
Example #7
0
    print('Size is %sMB' % str(size_in_mb))


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()
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()
Example #9
0
    # 查询特定挂单信息,需要提供挂单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()