当前位置: 首页>>代码示例>>Python>>正文


Python hotshot.stats方法代码示例

本文整理汇总了Python中hotshot.stats方法的典型用法代码示例。如果您正苦于以下问题:Python hotshot.stats方法的具体用法?Python hotshot.stats怎么用?Python hotshot.stats使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在hotshot的用法示例。


在下文中一共展示了hotshot.stats方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __call__

# 需要导入模块: import hotshot [as 别名]
# 或者: from hotshot import stats [as 别名]
def __call__(self, *args, **kw):
        """Profile a singe call to the function."""
        self.ncalls += 1
        if self.skip > 0:
            self.skip -= 1
            self.skipped += 1
            return self.fn(*args, **kw)
        if FuncProfile.in_profiler:
            # handle recursive calls
            return self.fn(*args, **kw)
        # You cannot reuse the same profiler for many calls and accumulate
        # stats that way.  :-/
        profiler = self.Profile()
        try:
            FuncProfile.in_profiler = True
            return profiler.runcall(self.fn, *args, **kw)
        finally:
            FuncProfile.in_profiler = False
            self.stats.add(profiler)
            if self.immediate:
                self.print_stats()
                self.reset_stats() 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:24,代码来源:profilehooks.py

示例2: print_stats

# 需要导入模块: import hotshot [as 别名]
# 或者: from hotshot import stats [as 别名]
def print_stats(self):
        """Print profile information to sys.stdout."""
        stats = self.stats
        if self.filename:
            stats.dump_stats(self.filename)
        if self.stdout:
            funcname = self.fn.__name__
            filename = self.fn.__code__.co_filename
            lineno = self.fn.__code__.co_firstlineno
            print("")
            print("*** PROFILER RESULTS ***")
            print("%s (%s:%s)" % (funcname, filename, lineno))
            if self.skipped:
                skipped = " (%d calls not profiled)" % self.skipped
            else:
                skipped = ""
            print("function called %d times%s" % (self.ncalls, skipped))
            print("")
            if not self.dirs:
                stats.strip_dirs()
            stats.sort_stats(*self.sort)
            stats.print_stats(self.entries) 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:24,代码来源:profilehooks.py

示例3: process_response

# 需要导入模块: import hotshot [as 别名]
# 或者: from hotshot import stats [as 别名]
def process_response(self, request, response):
        if (settings.DEBUG or request.user.is_superuser) and 'prof' in request.GET:
            self.prof.close()

            out = io.StringIO()
            old_stdout = sys.stdout
            sys.stdout = out

            stats = hotshot.stats.load(self.tmpfile)
            stats.sort_stats('time', 'calls')
            stats.print_stats()

            sys.stdout = old_stdout
            stats_str = out.getvalue()

            if response and response.content and stats_str:
                response.content = "<pre>" + stats_str + "</pre>"

            response.content = "\n".join(response.content.split("\n")[:40])

            response.content += self.summary_for_files(stats_str)

            os.unlink(self.tmpfile)

        return response 
开发者ID:sfu-fas,项目名称:coursys,代码行数:27,代码来源:profiling.py

示例4: main

# 需要导入模块: import hotshot [as 别名]
# 或者: from hotshot import stats [as 别名]
def main(logfile):
    p = hotshot.Profile(logfile)
    benchtime, stones = p.runcall(test.pystone.pystones)
    p.close()

    print "Pystone(%s) time for %d passes = %g" % \
          (test.pystone.__version__, test.pystone.LOOPS, benchtime)
    print "This machine benchmarks at %g pystones/second" % stones

    stats = hotshot.stats.load(logfile)
    stats.strip_dirs()
    stats.sort_stats('time', 'calls')
    try:
        stats.print_stats(20)
    except IOError, e:
        if e.errno != errno.EPIPE:
            raise 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:19,代码来源:stones.py

示例5: run_hotshot

# 需要导入模块: import hotshot [as 别名]
# 或者: from hotshot import stats [as 别名]
def run_hotshot(filename, profile, args):
    prof = hotshot.Profile(profile)
    sys.path.insert(0, os.path.dirname(filename))
    sys.argv = [filename] + args
    prof.run("execfile(%r)" % filename)
    prof.close()
    stats = hotshot.stats.load(profile)
    stats.sort_stats("time", "calls")

    # print_stats uses unadorned print statements, so the only way
    # to force output to stderr is to reassign sys.stdout temporarily
    save_stdout = sys.stdout
    sys.stdout = sys.stderr
    stats.print_stats()
    sys.stdout = save_stdout

    return 0 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:19,代码来源:hotshotmain.py

示例6: print_stats

# 需要导入模块: import hotshot [as 别名]
# 或者: from hotshot import stats [as 别名]
def print_stats(self):
        """Print profile information to sys.stdout."""
        funcname = self.fn.__name__
        filename = self.fn.__code__.co_filename
        lineno = self.fn.__code__.co_firstlineno
        print("")
        print("*** PROFILER RESULTS ***")
        print("%s (%s:%s)" % (funcname, filename, lineno))
        if self.skipped:
            skipped = "(%d calls not profiled)" % self.skipped
        else:
            skipped = ""
        print("function called %d times%s" % (self.ncalls, skipped))
        print("")
        stats = self.stats
        if self.filename:
            stats.dump_stats(self.filename)
        if not self.dirs:
            stats.strip_dirs()
        stats.sort_stats(*self.sort)
        stats.print_stats(self.entries) 
开发者ID:lrq3000,项目名称:pyFileFixity,代码行数:23,代码来源:profilehooks.py

示例7: runMain

# 需要导入模块: import hotshot [as 别名]
# 或者: from hotshot import stats [as 别名]
def runMain(main, options, args):
    if options.profile:
        if True:
            import hotshot
            profile = hotshot.Profile(options.profile)
            profile.runcall(main, options, args)
            profile.close()
            import hotshot.stats
            stats = hotshot.stats.load(options.profile)
        else:
            import profile
            profile.run('main(options, args)', options.profile)
            import pstats
            stats = pstats.Stats(options.profile)
        stats.strip_dirs()
        stats.sort_stats('time', 'calls')
        stats.print_stats(20)
    elif options.psyco:
        import psyco
        psyco.full()
        status = main(options, args)
    else:
        status = main(options, args)
    return status 
开发者ID:sequitur-g2p,项目名称:sequitur-g2p,代码行数:26,代码来源:tool.py

示例8: count_xfs

# 需要导入模块: import hotshot [as 别名]
# 或者: from hotshot import stats [as 别名]
def count_xfs(bk):
        bk_header(bk)
        for shx in range(bk.nsheets):
            sh = bk.sheet_by_index(shx)
            nrows, ncols = sh.nrows, sh.ncols
            print("sheet %d: name = %r; nrows = %d; ncols = %d" %
                (shx, sh.name, sh.nrows, sh.ncols))
            # Access all xfindexes to force gathering stats
            type_stats = [0, 0, 0, 0, 0, 0, 0]
            for rowx in xrange(nrows):
                for colx in xrange(sh.row_len(rowx)):
                    xfx = sh.cell_xf_index(rowx, colx)
                    assert xfx >= 0
                    cty = sh.cell_type(rowx, colx)
                    type_stats[cty] += 1
            print("XF stats", sh._xf_index_stats)
            print("type stats", type_stats)
            print()
            if bk.on_demand: bk.unload_sheet(shx) 
开发者ID:alexfeng,项目名称:InternationalizationScript-iOS,代码行数:21,代码来源:runxlrd.py

示例9: run

# 需要导入模块: import hotshot [as 别名]
# 或者: from hotshot import stats [as 别名]
def run(self, reactor):
        """
        Run reactor under the hotshot profiler.
        """
        try:
            import hotshot.stats
        except (ImportError, SystemExit), e:
            # Certain versions of Debian (and Debian derivatives) raise
            # SystemExit when importing hotshot if the "non-free" profiler
            # module is not installed.  Someone eventually recognized this
            # as a bug and changed the Debian packaged Python to raise
            # ImportError instead.  Handle both exception types here in
            # order to support the versions of Debian which have this
            # behavior.  The bug report which prompted the introduction of
            # this highly undesirable behavior should be available online at
            # <http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=334067>.
            # There seems to be no corresponding bug report which resulted
            # in the behavior being removed. -exarkun
            self._reportImportError("hotshot", e)

        # this writes stats straight out 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:23,代码来源:app.py

示例10: _testStats

# 需要导入模块: import hotshot [as 别名]
# 或者: from hotshot import stats [as 别名]
def _testStats(self, statsClass, profile):
        out = StringIO.StringIO()

        # Patch before creating the pstats, because pstats binds self.stream to
        # sys.stdout early in 2.5 and newer.
        stdout = self.patch(sys, 'stdout', out)

        # If pstats.Stats can load the data and then reformat it, then the
        # right thing probably happened.
        stats = statsClass(profile)
        stats.print_stats()
        stdout.restore()

        data = out.getvalue()
        self.assertIn("function calls", data)
        self.assertIn("(run)", data) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:18,代码来源:test_twistd.py

示例11: test_profileSaveStats

# 需要导入模块: import hotshot [as 别名]
# 或者: from hotshot import stats [as 别名]
def test_profileSaveStats(self):
        """
        With the C{savestats} option specified, L{app.ProfileRunner.run}
        should save the raw stats object instead of a summary output.
        """
        config = twistd.ServerOptions()
        config["profile"] = self.mktemp()
        config["profiler"] = "profile"
        config["savestats"] = True
        profiler = app.AppProfiler(config)
        reactor = DummyReactor()

        profiler.run(reactor)

        self.assertTrue(reactor.called)
        self._testStats(pstats.Stats, config['profile']) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:18,代码来源:test_twistd.py

示例12: test_profilePrintStatsError

# 需要导入模块: import hotshot [as 别名]
# 或者: from hotshot import stats [as 别名]
def test_profilePrintStatsError(self):
        """
        When an error happens during the print of the stats, C{sys.stdout}
        should be restored to its initial value.
        """
        class ErroneousProfile(profile.Profile):
            def print_stats(self):
                raise RuntimeError("Boom")
        self.patch(profile, "Profile", ErroneousProfile)

        config = twistd.ServerOptions()
        config["profile"] = self.mktemp()
        config["profiler"] = "profile"
        profiler = app.AppProfiler(config)
        reactor = DummyReactor()

        oldStdout = sys.stdout
        self.assertRaises(RuntimeError, profiler.run, reactor)
        self.assertIdentical(sys.stdout, oldStdout) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:21,代码来源:test_twistd.py

示例13: test_hotshotSaveStats

# 需要导入模块: import hotshot [as 别名]
# 或者: from hotshot import stats [as 别名]
def test_hotshotSaveStats(self):
        """
        With the C{savestats} option specified, L{app.HotshotRunner.run} should
        save the raw stats object instead of a summary output.
        """
        config = twistd.ServerOptions()
        config["profile"] = self.mktemp()
        config["profiler"] = "hotshot"
        config["savestats"] = True
        profiler = app.AppProfiler(config)
        reactor = DummyReactor()

        profiler.run(reactor)

        self.assertTrue(reactor.called)
        self._testStats(hotshot.stats.load, config['profile']) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:18,代码来源:test_twistd.py

示例14: test_cProfileSaveStats

# 需要导入模块: import hotshot [as 别名]
# 或者: from hotshot import stats [as 别名]
def test_cProfileSaveStats(self):
        """
        With the C{savestats} option specified,
        L{app.CProfileRunner.run} should save the raw stats object
        instead of a summary output.
        """
        config = twistd.ServerOptions()
        config["profile"] = self.mktemp()
        config["profiler"] = "cProfile"
        config["savestats"] = True
        profiler = app.AppProfiler(config)
        reactor = DummyReactor()

        profiler.run(reactor)

        self.assertTrue(reactor.called)
        self._testStats(pstats.Stats, config['profile']) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:19,代码来源:test_twistd.py

示例15: runWithHotshot

# 需要导入模块: import hotshot [as 别名]
# 或者: from hotshot import stats [as 别名]
def runWithHotshot(reactor, config):
    """Run reactor under hotshot profiler."""
    try:
        import hotshot.stats
    except ImportError, e:
        s = "Failed to import module hotshot: %s" % e
        s += """
This is most likely caused by your operating system not including
profile.py due to it being non-free. Either do not use the option
--profile, or install profile.py; your operating system vendor
may provide it in a separate package.
"""
        traceback.print_exc(file=log.logfile)
        log.msg(s)
        log.deferr()
        sys.exit('\n' + s + '\n')

    # this writes stats straight out 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:20,代码来源:app.py


注:本文中的hotshot.stats方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。