Esempio n. 1
0
def _exec_main(parser, values):
    sconsflags = os.environ.get('SCONSFLAGS', '')
    all_args = sconsflags.split() + sys.argv[1:]

    options, args = parser.parse_args(all_args, values)

    if isinstance(options.debug, list) and "pdb" in options.debug:
        import pdb
        pdb.Pdb().runcall(_main, parser)
    elif options.profile_file:
        # compat layer imports "cProfile" for us if it's available.
        from profile import Profile

        # Some versions of Python 2.4 shipped a profiler that had the
        # wrong 'c_exception' entry in its dispatch table.  Make sure
        # we have the right one.  (This may put an unnecessary entry
        # in the table in earlier versions of Python, but its presence
        # shouldn't hurt anything).
        try:
            dispatch = Profile.dispatch
        except AttributeError:
            pass
        else:
            dispatch['c_exception'] = Profile.trace_dispatch_return

        prof = Profile()
        try:
            prof.runcall(_main, parser)
        except SConsPrintHelpException, e:
            prof.dump_stats(options.profile_file)
            raise e
        except SystemExit:
            pass
Esempio n. 2
0
def runProfiler(logger,
                func,
                args=tuple(),
                kw={},
                verbose=True,
                nb_func=25,
                sort_by=('time', ),
                nb_cal=0):
    """
    Run a function in a profiler and then display the functions sorted by time.
    """
    profile_filename = "/tmp/profiler"
    prof = Profile(bias=calibrate(nb_cal))
    try:
        logger.warning("Run profiler")
        result = prof.runcall(func, *args, **kw)
        logger.error("Profiler: Process data...")
        prof.dump_stats(profile_filename)
        stat = pstats.Stats(prof)
        stat.strip_dirs()
        stat.sort_stats(*sort_by)

        logger.error("Profiler: Result:")
        log = StringIO()
        stat.stream = log
        stat.print_stats(nb_func)
        log.seek(0)
        for line in log:
            logger.error(line.rstrip())
        return result
    finally:
        unlink(profile_filename)
Esempio n. 3
0
def _exec_main(parser, values):
    sconsflags = os.environ.get('SCONSFLAGS', '')
    all_args = string.split(sconsflags) + sys.argv[1:]

    options, args = parser.parse_args(all_args, values)

    if type(options.debug) == type([]) and "pdb" in options.debug:
        import pdb
        pdb.Pdb().runcall(_main, parser)
    elif options.profile_file:
        from profile import Profile

        # Some versions of Python 2.4 shipped a profiler that had the
        # wrong 'c_exception' entry in its dispatch table.  Make sure
        # we have the right one.  (This may put an unnecessary entry
        # in the table in earlier versions of Python, but its presence
        # shouldn't hurt anything).
        try:
            dispatch = Profile.dispatch
        except AttributeError:
            pass
        else:
            dispatch['c_exception'] = Profile.trace_dispatch_return

        prof = Profile()
        try:
            prof.runcall(_main, parser)
        except SConsPrintHelpException, e:
            prof.dump_stats(options.profile_file)
            raise e
        except SystemExit:
            pass
Esempio n. 4
0
 def main(self):
     if len(sys.argv) > 1 and sys.argv[1].lower().startswith('prof'):
         self._shouldProfile = 1
     if self._shouldRunTestSuite:
         from TestCSVParser import main
         main()
     start = time.time()
     if self._shouldProfile:
         prof = Profile()
         prof.runcall(self._main)
         filename = '%s.pstats' % self.__class__.__name__
         prof.dump_stats(filename)
         print 'Wrote', filename
     else:
         self._main()
     duration = time.time() - start
     print '%.1f secs' % duration
Esempio n. 5
0
    # Find a function for the command
    try:
        cmd_func      = commands[cmd]['call']
        cmd_with_args = lambda: cmd_func(options, args)
    except (NameError, KeyError), e:
        log.error("No such command '%s'" % cmd)
        parser.print_help()
        sys.exit(1)

    # Fire off the startup event, register for shutdown
    plugin_manager.dispatch("startup")

    # Execute the chosen command
    try:
        if options.profile:
            from profile import Profile
            p = Profile()
            p.runcall(cmd_with_args)
            p.dump_stats(options.profile)
        else:
            cmd_with_args()

    except CmdException, e:
        log.error("Error: %s" % e)
        parser.print_help()
        sys.exit(1)

    plugin_manager.dispatch("shutdown")

Esempio n. 6
0
 def wrapper(*args, **kwargs):
     profiler = Profile()
     value = profiler.runcall(func, *args, **kwargs)
     profiler.dump_stats('/tmp/{}.prof'.format(func.__name__))
     return value
Esempio n. 7
0
        options = [
            ao.options.testModules, ao.options.profileOut,
            ao.options.coverageOutDir
        ]

        if ao.options.pyprofile:

            # FIXME: factorize me in utils
            from profile import Profile
            myprofiler = Profile()
            myprofiler.create_stats()

            myprofiler.runcall(runTests, *options)

            statfile = mktemp()
            myprofiler.dump_stats(statfile)

            import pstats
            p = pstats.Stats(statfile)
            os.remove(statfile)  # remove temp file
            p.strip_dirs()
            p.sort_stats('cumulative').print_stats(30)

        else:
            runTests(*options)

        # On windows, we make a dummy raw_input so that the
        # python terminal does not shut down after exiting
        if os.name == 'nt':
            raw_input()
Esempio n. 8
0
    # in the album name.
    for album in po.options.albumName.split(','):

	po.options.albumName = album

        progress = ProgressMsg(-1, sys.stderr)
	pytof = Pytof(po, progress)
	if po.options.pyprofile:

	    # FIXME: factorize me in utils
	    from profile import Profile
	    myprofiler = Profile()
	    myprofiler.create_stats()

	    myprofiler.runcall(pytof.main)

	    from tempfile import mktemp
	    statfile = mktemp()
	    myprofiler.dump_stats(statfile)

	    import pstats
	    p = pstats.Stats(statfile)
	    os.remove(statfile) # remove temp file
	    p.strip_dirs()
	    p.sort_stats('cumulative').print_stats(30)

	else:

	    pytof.main()

Esempio n. 9
0
 def wrapper(*args, **kwargs):
     profiler = Profile()
     value = profiler.runcall(func, *args, **kwargs)
     profiler.dump_stats('/tmp/{}.prof'.format(func.__name__))
     return value