Пример #1
0
    def test_performance_check_select_destination(self, mock_get_extra,
                                                  mock_get_by_uuid,
                                                  mock_get_by_instance_uuid):
        hosts = 2
        requests = 1

        self.flags(service_down_time=240)

        spec_obj = self._get_fake_request_spec()
        host_states = []
        for x in range(hosts):
            host_state = self._get_fake_host_state(x)
            host_states.append(host_state)
        self.driver.all_host_states = {uuids.cell: host_states}
        provider_summaries = {hs.uuid: hs for hs in host_states}

        def run_test():
            a = timeutils.utcnow()

            for x in range(requests):
                self.driver.select_destinations(self.context, spec_obj,
                                                [spec_obj.instance_uuid], {},
                                                provider_summaries)

            b = timeutils.utcnow()
            c = b - a

            seconds = (c.days * 24 * 60 * 60 + c.seconds)
            microseconds = seconds * 1000 + c.microseconds / 1000.0
            per_request_ms = microseconds / requests
            return per_request_ms

        per_request_ms = None
        if ENABLE_PROFILER:
            import pycallgraph
            from pycallgraph import output
            config = pycallgraph.Config(max_depth=10)
            config.trace_filter = pycallgraph.GlobbingFilter(exclude=[
                'pycallgraph.*',
                'unittest.*',
                'testtools.*',
                'nova.tests.unit.*',
            ])
            graphviz = output.GraphvizOutput(output_file='scheduler.png')

            with pycallgraph.PyCallGraph(output=graphviz):
                per_request_ms = run_test()

        else:
            per_request_ms = run_test()

        # This has proved to be around 1 ms on a random dev box
        # But this is here so you can do simply performance testing easily.
        self.assertLess(per_request_ms, 1000)
Пример #2
0
def generate_cfg(out_path):
    '''
    Writes the graphviz generated CFG to out_path.
    Only includes modules from full_pipe, edx_pipe, and curation.
    '''
    config = pycallgraph.Config(max_depth=4)
    config.trace_filter = pycallgraph.GlobbingFilter(
        include=['curation.*', 'edx_pipe.*', 'full_pipe.*'])
    graphviz = pycallgraph.output.GraphvizOutput(output_file=out_path)
    with pycallgraph.PyCallGraph(output=graphviz, config=config):
        full_pipe.main()
Пример #3
0
    def trace(self,
              fn,
              fname,
              exclude_from_trace=None,
              strings_to_delete=None,
              class_colors=None):
        """
        Trace the program flow and creates DOT (*.dot) and GML (*.gml) files.

        # Arguments
            fn (object): function to call for the entry point to trace the program flow
            fname (str): filename for graph files (do not supply file extension)
            exclude_from_trace (list): names (`str`) to exclude from trace (`None` by default)
            strings_to_delete (list): text (`str`) to remove from graph files (`None` by default)
            class_colors (dict): node colors (`None` by default)

        # Returns
            None:

        """
        # 1. filter out some unwanted functions and classes:
        config = pycallgraph.Config()
        if exclude_from_trace is not None:
            config.trace_filter = pycallgraph.GlobbingFilter(
                exclude=exclude_from_trace)

        # 2. trace the program flow:
        with pycallgraph.PyCallGraph(output=self, config=config):
            fn()  # entry point for tracing the program flow
        dotstr = self.generate()

        # 3. customize the output:
        # 3a. delete strings
        if strings_to_delete is not None:
            for rx in strings_to_delete:
                dotstr = rx.sub('', dotstr)

        # 3b. customization: change color for class nodes
        if class_colors is not None:
            dotstr = Graph._colorize(dotstr, class_colors)

        # 4. create the DOT file
        fname_dot = fname + '.dot'
        with open(fname_dot, 'wt') as fdot:
            fdot.write(dotstr)

        # 5. create the GML (XML) file
        fname_gml = fname + '.gml'
        cmd = 'dot ' + fname_dot + ' | gv2gml >' + fname_gml
        os.system(cmd)  # use the dot.exe to convert the DOT file into GML file
Пример #4
0
    def test_performance_check_select_destination(self, mock_get_extra):
        hosts = 2
        requests = 1

        self.flags(service_down_time=240)

        request_spec = self._get_fake_request_spec()
        host_states = []
        for x in xrange(hosts):
            host_state = self._get_fake_host_state(x)
            host_states.append(host_state)
        self.driver.all_host_states = host_states

        def run_test():
            a = timeutils.utcnow()

            for x in xrange(requests):
                self.driver.select_destinations(self.context, request_spec, {})

            b = timeutils.utcnow()
            c = b - a

            seconds = (c.days * 24 * 60 * 60 + c.seconds)
            microseconds = seconds * 1000 + c.microseconds / 1000.0
            per_request_ms = microseconds / requests
            return per_request_ms

        per_request_ms = None
        if ENABLE_PROFILER:
            import pycallgraph
            from pycallgraph import output
            config = pycallgraph.Config(max_depth=10)
            config.trace_filter = pycallgraph.GlobbingFilter(exclude=[
                'pycallgraph.*',
                'unittest.*',
                'patron.tests.unit.*',
            ])
            graphviz = output.GraphvizOutput(output_file='scheduler.png')

            with pycallgraph.PyCallGraph(output=graphviz):
                per_request_ms = run_test()

        else:
            per_request_ms = run_test()

        # This has proved to be around 1 ms on a random dev box
        # But this is here so you can do simply performance testing easily.
        self.assertTrue(per_request_ms < 1000)
Пример #5
0
def main():
    import os, sys
    # Inject the current working directory so modules can be imported.
    sys.path.insert(0, os.getcwd())

    import pycallgraph as __pycallgraph

    __config = __pycallgraph.Config()
    __config.parse_args()
    __config.strip_argv()

    globals()['__file__'] = __config.command

    __file_content = open(__config.command).read()

    with __pycallgraph.PyCallGraph(config=__config):
        exec(__file_content)
Пример #6
0
    def run(self, runWithEnviron=True):
        '''
        Main code runner for testing. To set a new test, update the self.callTest attribute in __init__().

        Note that the default of runWithEnviron imports music21.environment.  That might
        skew results
        '''
        from music21 import environment

        suffix = '.png'  # '.svg'
        outputFormat = suffix[1:]
        _MOD = "test.timeGraphs"

        if runWithEnviron:
            environLocal = environment.Environment(_MOD)
            fp = environLocal.getTempFile(suffix)
        # manually get a temporary file
        else:
            import tempfile
            import os
            import sys
            if os.name in ['nt'] or sys.platform.startswith('win'):
                platform = 'win'
            else:
                platform = 'other'

            tempdir = os.path.join(tempfile.gettempdir(), 'music21')
            if platform != 'win':
                fd, fp = tempfile.mkstemp(dir=tempdir, suffix=suffix)
                if isinstance(fd, int):
                    # on MacOS, fd returns an int, like 3, when this is called
                    # in some context (specifically, programmatically in a
                    # TestExternal class. the fp is still valid and works
                    # TODO: this did not work on MacOS 10.6.8 w/ py 2.7
                    pass
                else:
                    fd.close()
            else:
                tf = tempfile.NamedTemporaryFile(dir=tempdir, suffix=suffix)
                fp = tf.name
                tf.close()

        if self.includeList is not None:
            gf = pycallgraph.GlobbingFilter(include=self.includeList,
                                            exclude=self.excludeList)
        else:
            gf = pycallgraph.GlobbingFilter(exclude=self.excludeList)
        # create instance; will call setup routines
        ct = self.callTest()

        # start timer
        print('%s starting test' % _MOD)
        t = Timer()
        t.start()

        graphviz = pycallgraph.output.GraphvizOutput(output_file=fp)
        graphviz.tool = '/usr/local/bin/dot'

        config = pycallgraph.Config()
        config.trace_filter = gf

        from music21 import meter
        from music21 import note
        #from music21 import converter
        #from music21 import common
        #beeth = common.getCorpusFilePath() + '/beethoven/opus133.mxl'
        #s = converter.parse(beeth, forceSource=True)
        #beeth = common.getCorpusFilePath() + '/bach/bwv66.6.mxl'
        #s = converter.parse(beeth, forceSource=True)

        with pycallgraph.PyCallGraph(output=graphviz, config=config):
            note.Note()
            meter.TimeSignature('4/4')
            ct.testFocus()  # run routine
            pass
        print('elapsed time: %s' % t)
        # open the completed file
        print('file path: ' + fp)
        try:
            environLocal = environment.Environment(_MOD)
            environLocal.launch(outputFormat, fp)
        except NameError:
            pass
Пример #7
0
    def run(self, runWithEnviron=False):
        '''
        Main code runner for testing. To set a new test, 
        update the self.callTest attribute in __init__().
        '''
        suffix = '.png'  # '.svg' no reader for now...
        _MOD = "test.timeGraphImportStar.py"

        if runWithEnviron:
            from music21 import environment
            environLocal = environment.Environment(_MOD)
            fp = environLocal.getTempFile(suffix)
        # manually get a temporary file
        else:
            import tempfile
            import os
            import sys
            if os.name in ['nt'] or sys.platform.startswith('win'):
                platform = 'win'
            else:
                platform = 'other'

            tempdir = os.path.join(tempfile.gettempdir(), 'music21')
            if platform != 'win':
                fd, fp = tempfile.mkstemp(dir=tempdir, suffix=suffix)
                if isinstance(fd, int):
                    # on MacOS, fd returns an int, like 3, when this is called
                    # in some context (specifically, programmatically in a
                    # TestExternal class. the fp is still valid and works
                    # TODO: this did not work on MacOS 10.6.8 w/ py 2.7
                    pass
                else:
                    fd.close()
            else:
                tf = tempfile.NamedTemporaryFile(dir=tempdir, suffix=suffix)
                fp = tf.name
                tf.close()

        if self.includeList is not None:
            gf = pycallgraph.GlobbingFilter(include=self.includeList,
                                            exclude=self.excludeList)
        else:
            gf = pycallgraph.GlobbingFilter(exclude=self.excludeList)
        # create instance; will call setup routines
        ct = self.callTest()

        # start timer
        print('%s starting test' % _MOD)
        t = Timer()
        t.start()

        graphviz = pycallgraph.output.GraphvizOutput(output_file=fp)
        graphviz.tool = '/usr/local/bin/dot'

        config = pycallgraph.Config()
        config.trace_filter = gf

        with pycallgraph.PyCallGraph(output=graphviz, config=config):
            ct.testFocus()  # run routine

        print('elapsed time: %s' % t)
        # open the completed file
        print('file path: ' + fp)
        try:
            environLocal = environment.Environment(_MOD)
            environLocal.launch(format, fp)
        except NameError:
            pass
Пример #8
0
def callgraph(f):
    import pycallgraph
    with pycallgraph.PyCallGraph(output=pycallgraph.output.GraphvizOutput()):
        f()
Пример #9
0
import pycallgraph
import antscheduler.__main__

graphviz = pycallgraph.output.GraphvizOutput()
graphviz.output_file = 'profiler.png'

with pycallgraph.PyCallGraph(output=graphviz):
    antscheduler.__main__.main()
Пример #10
0
times = empty((len(functionsToMeasure), N))
for i in range(0, N):
  # init SDP program
  problem = SDPSolver(c, [A])
  
  # bound the problem
  problem.bound(1)
  
  # pycallgraph config
  config = pycallgraph.Config()
  config.include_stdlib = True
  dot = pycallgraph.output.GraphvizOutput(output_file='profile.dot', output_type='dot')
  graphviz = pycallgraph.output.GraphvizOutput(output_file='profile.png')
  
  # profile
  with pycallgraph.PyCallGraph(output=[graphviz, dot], config=config) as graph:
    # solve
    problem.solve(startPoint, problem.dampedNewton)

  with open('profile.dot', 'r') as f:
    content = f.read()
  
  times[:, i] = array(list(map((lambda r: parseDot(r, content)), regexps)))
  print('.', end='', flush=True)

print()
times = nanmedian(times, axis=1)
for i in range(0, len(functionsToMeasure)):
  print('{:>30s}: {:4.3g} ms'.format(functionsToMeasure[i], times[i]*1000))