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


Python pstats.Stats方法代码示例

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


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

示例1: stats

# 需要导入模块: import pstats [as 别名]
# 或者: from pstats import Stats [as 别名]
def stats(self, filename, sortby='cumulative'):
        """:rtype stats(index): output of print_stats() for the given profile.
        """
        sio = io.StringIO()
        if sys.version_info >= (2, 5):
            s = pstats.Stats(os.path.join(self.path, filename), stream=sio)
            s.strip_dirs()
            s.sort_stats(sortby)
            s.print_stats()
        else:
            # pstats.Stats before Python 2.5 didn't take a 'stream' arg,
            # but just printed to stdout. So re-route stdout.
            s = pstats.Stats(os.path.join(self.path, filename))
            s.strip_dirs()
            s.sort_stats(sortby)
            oldout = sys.stdout
            try:
                sys.stdout = sio
                s.print_stats()
            finally:
                sys.stdout = oldout
        response = sio.getvalue()
        sio.close()
        return response 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:26,代码来源:profiler.py

示例2: profile

# 需要导入模块: import pstats [as 别名]
# 或者: from pstats import Stats [as 别名]
def profile(fnc):
    """
    Profiles any function in following class just by adding @profile above function
    """
    import cProfile, pstats, io
    def inner (*args, **kwargs):
        pr = cProfile.Profile()
        pr.enable()
        retval = fnc (*args, **kwargs)
        pr.disable()
        s = io.StringIO()
        sortby = 'cumulative'   #Ordered
        ps = pstats.Stats(pr,stream=s).strip_dirs().sort_stats(sortby)
        n=20                    #reduced the list to be monitored
        ps.print_stats(n)
        #ps.dump_stats("profile.prof")
        print(s.getvalue())
        return retval
    return inner 
开发者ID:pyscf,项目名称:pyscf,代码行数:21,代码来源:gw_iter.py

示例3: profileit

# 需要导入模块: import pstats [as 别名]
# 或者: from pstats import Stats [as 别名]
def profileit(func):
    """
    Decorator straight up stolen from stackoverflow
    """
    def wrapper(*args, **kwargs):
        datafn = func.__name__ + ".profile" # Name the data file sensibly
        prof = cProfile.Profile()
        prof.enable()
        retval = prof.runcall(func, *args, **kwargs)
        prof.disable()
        stats = pstats.Stats(prof)
        stats.sort_stats('tottime').print_stats(20)
        print()
        print()
        stats.sort_stats('cumtime').print_stats(20)
        return retval

    return wrapper 
开发者ID:vertical-knowledge,项目名称:ripozo,代码行数:20,代码来源:profile.py

示例4: __init__

# 需要导入模块: import pstats [as 别名]
# 或者: from pstats import Stats [as 别名]
def __init__(self, scriptName, params, reportTime, dataFile, parent=None):
        MainWindowTabWidgetBase.__init__(self)
        QWidget.__init__(self, parent)

        # The same stats object is needed for both - a table and a graph
        # So, parse profile output once and then pass the object further
        stats = pstats.Stats(dataFile)
        stats.calc_callees()

        self.__profTable = ProfileTableViewer(scriptName, params, reportTime,
                                              dataFile, stats, self)
        self.__profGraph = ProfileGraphViewer(scriptName, params, reportTime,
                                              dataFile, stats, self)
        self.__profTable.hide()

        self.__profTable.sigEscapePressed.connect(self.__onEsc)
        self.__profGraph.sigEscapePressed.connect(self.__onEsc)

        self.__createLayout() 
开发者ID:SergeySatskiy,项目名称:codimension,代码行数:21,代码来源:profwidget.py

示例5: _profile_package

# 需要导入模块: import pstats [as 别名]
# 或者: from pstats import Stats [as 别名]
def _profile_package(self):
        """Runs cProfile on a package."""
        prof = cProfile.Profile()
        prof.enable()
        try:
            runpy.run_path(self._run_object, run_name='__main__')
        except SystemExit:
            pass
        prof.disable()
        prof_stats = pstats.Stats(prof)
        prof_stats.calc_callees()
        return {
            'objectName': self._object_name,
            'callStats': self._transform_stats(prof_stats),
            'totalTime': prof_stats.total_tt,
            'primitiveCalls': prof_stats.prim_calls,
            'totalCalls': prof_stats.total_calls,
            'timestamp': int(time.time())
        } 
开发者ID:nvdv,项目名称:vprof,代码行数:21,代码来源:profiler.py

示例6: _profile_module

# 需要导入模块: import pstats [as 别名]
# 或者: from pstats import Stats [as 别名]
def _profile_module(self):
        """Runs cProfile on a module."""
        prof = cProfile.Profile()
        try:
            with open(self._run_object, 'rb') as srcfile:
                code = compile(srcfile.read(), self._run_object, 'exec')
            prof.runctx(code, self._globs, None)
        except SystemExit:
            pass
        prof_stats = pstats.Stats(prof)
        prof_stats.calc_callees()
        return {
            'objectName': self._object_name,
            'callStats': self._transform_stats(prof_stats),
            'totalTime': prof_stats.total_tt,
            'primitiveCalls': prof_stats.prim_calls,
            'totalCalls': prof_stats.total_calls,
            'timestamp': int(time.time())
        } 
开发者ID:nvdv,项目名称:vprof,代码行数:21,代码来源:profiler.py

示例7: profile_function

# 需要导入模块: import pstats [as 别名]
# 或者: from pstats import Stats [as 别名]
def profile_function(self):
        """Runs cProfile on a function."""
        prof = cProfile.Profile()
        prof.enable()
        result = self._run_object(*self._run_args, **self._run_kwargs)
        prof.disable()
        prof_stats = pstats.Stats(prof)
        prof_stats.calc_callees()
        return {
            'objectName': self._object_name,
            'callStats': self._transform_stats(prof_stats),
            'totalTime': prof_stats.total_tt,
            'primitiveCalls': prof_stats.prim_calls,
            'totalCalls': prof_stats.total_calls,
            'result': result,
            'timestamp': int(time.time())
        } 
开发者ID:nvdv,项目名称:vprof,代码行数:19,代码来源:profiler.py

示例8: profile

# 需要导入模块: import pstats [as 别名]
# 或者: from pstats import Stats [as 别名]
def profile(cmd, globals, locals, sort_order, callers): # pragma: no cover
    # runs a command under the profiler and print profiling output at shutdown
    import os
    import profile
    import pstats
    import tempfile
    fd, fn = tempfile.mkstemp()
    try:
        profile.runctx(cmd, globals, locals, fn)
        stats = pstats.Stats(fn)
        stats.strip_dirs()
        # calls,time,cumulative and cumulative,calls,time are useful
        stats.sort_stats(*sort_order or ('cumulative', 'calls', 'time'))
        if callers:
            stats.print_callers(.3)
        else:
            stats.print_stats(.3)
    finally:
        os.remove(fn) 
开发者ID:MayOneUS,项目名称:pledgeservice,代码行数:21,代码来源:__init__.py

示例9: test_calling_conventions

# 需要导入模块: import pstats [as 别名]
# 或者: from pstats import Stats [as 别名]
def test_calling_conventions(self):
        # Issue #5330: profile and cProfile wouldn't report C functions called
        # with keyword arguments. We test all calling conventions.
        stmts = [
            "[].sort()",
            "[].sort(reverse=True)",
            "[].sort(*(None, None, True))",
            "[].sort(**dict(reverse=True))",
        ]
        for stmt in stmts:
            s = StringIO()
            prof = self.profilerclass(timer, 0.001)
            prof.runctx(stmt, globals(), locals())
            stats = pstats.Stats(prof, stream=s)
            stats.print_stats()
            res = s.getvalue()
            self.assertIn(self.expected_list_sort_output, res,
                "Profiling {0!r} didn't report list.sort:\n{1}".format(stmt, res)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:20,代码来源:test_profile.py

示例10: profileMain

# 需要导入模块: import pstats [as 别名]
# 或者: from pstats import Stats [as 别名]
def profileMain(args, config):  # pragma: no cover
    """This is the main function for profiling
    http://code.google.com/appengine/kb/commontasks.html#profiling
    """
    import cProfile
    import pstats

    eyed3.log.debug("driver profileMain")
    prof = cProfile.Profile()
    prof = prof.runctx("main(args)", globals(), locals())

    stream = StringIO()
    stats = pstats.Stats(prof, stream=stream)
    stats.sort_stats("time")  # Or cumulative
    stats.print_stats(100)  # 80 = how many to print

    # The rest is optional.
    stats.print_callees()
    stats.print_callers()
    sys.stderr.write("Profile data:\n%s\n" % stream.getvalue())

    return 0 
开发者ID:nicfit,项目名称:eyeD3,代码行数:24,代码来源:main.py

示例11: __exit__

# 需要导入模块: import pstats [as 别名]
# 或者: from pstats import Stats [as 别名]
def __exit__(self, type_, value, traceback):
        """Disable profiler and print stats."""
        self._profiler.disable()
        profile_stat = pstats.Stats(
            self._profiler, stream=sys.stdout).sort_stats('cumulative')
        profile_stat.print_stats() 
开发者ID:ContinuumIO,项目名称:ciocheck,代码行数:8,代码来源:utils.py

示例12: runtests

# 需要导入模块: import pstats [as 别名]
# 或者: from pstats import Stats [as 别名]
def runtests(xmlrunner=False):
   ''' Run unit tests '''
   import sys

   if '--profile' in sys.argv:
       import profile
       import pstats

       sys.argv = [x for x in sys.argv if x != '--profile']

       if xmlrunner:
           import xmlrunner as xr
           profile.run("unittest.main(testRunner=xr.XMLTestRunner(output='test-reports', verbosity=2))", '_stats.txt')
       else:
           profile.run('unittest.main()', '_stats.txt')

       stats = pstats.Stats('_stats.txt')
       #stats.strip_dirs()
       stats.sort_stats('cumulative', 'calls')
       stats.print_stats(25)
       stats.sort_stats('time', 'calls')
       stats.print_stats(25)

   elif xmlrunner:
       import xmlrunner as xr
       unittest.main(testRunner=xr.XMLTestRunner(output='test-reports', verbosity=2)) 

   else:
       unittest.main() 
开发者ID:sassoftware,项目名称:python-esppy,代码行数:31,代码来源:utils.py

示例13: run_profile

# 需要导入模块: import pstats [as 别名]
# 或者: from pstats import Stats [as 别名]
def run_profile():
    import profile
    profile.run('for i in range(10): demo()', '/tmp/profile.out')
    import pstats
    p = pstats.Stats('/tmp/profile.out')
    p.strip_dirs().sort_stats('time', 'cum').print_stats(60)
    p.strip_dirs().sort_stats('cum', 'time').print_stats(60) 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:9,代码来源:featurechart.py

示例14: run_profile

# 需要导入模块: import pstats [as 别名]
# 或者: from pstats import Stats [as 别名]
def run_profile():
    import profile
    profile.run('for i in range(1): demo()', '/tmp/profile.out')
    import pstats
    p = pstats.Stats('/tmp/profile.out')
    p.strip_dirs().sort_stats('time', 'cum').print_stats(60)
    p.strip_dirs().sort_stats('cum', 'time').print_stats(60) 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:9,代码来源:featurechart.py

示例15: reset_stats

# 需要导入模块: import pstats [as 别名]
# 或者: from pstats import Stats [as 别名]
def reset_stats(self):
        """Reset accumulated profiler statistics."""
        # Note: not using self.Profile, since pstats.Stats() fails then
        self.stats = pstats.Stats(Profile())
        self.ncalls = 0
        self.skipped = 0 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:8,代码来源:profilehooks.py


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