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


Python Stats.print_stats方法代码示例

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


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

示例1: _execute

# 需要导入模块: from pstats import Stats [as 别名]
# 或者: from pstats.Stats import print_stats [as 别名]
    def _execute(self, func, phase_name, n, *args):
        if not self.profile_dir:
            return func(*args)

        basename = '%s-%s-%d-%02d-%d' % (
            self.contender_name, phase_name, self.objects_per_txn, n, self.rep)
        txt_fn = os.path.join(self.profile_dir, basename + ".txt")
        prof_fn = os.path.join(self.profile_dir, basename + ".prof")

        profiler = cProfile.Profile()
        profiler.enable()
        try:
            res = func(*args)
        finally:
            profiler.disable()

        profiler.dump_stats(prof_fn)

        with open(txt_fn, 'w') as f:
            st = Stats(profiler, stream=f)
            st.strip_dirs()
            st.sort_stats('cumulative')
            st.print_stats()

        return res
开发者ID:zodb,项目名称:zodbshootout,代码行数:27,代码来源:speedtest.py

示例2: stopTest

# 需要导入模块: from pstats import Stats [as 别名]
# 或者: from pstats.Stats import print_stats [as 别名]
 def stopTest(self, test):
     super(BenchTestResult, self).stopTest(test)
     if self._benchmark:
         self._profiler.disable()
         stats = Stats(self._profiler)
         stats.sort_stats(self._sort)
         stats.print_stats(self._limit)
开发者ID:lhelwerd,项目名称:mobile-radio-tomography,代码行数:9,代码来源:Test_Result.py

示例3: write_profile

# 需要导入模块: from pstats import Stats [as 别名]
# 或者: from pstats.Stats import print_stats [as 别名]
def write_profile(pfile='./logs/profile.out'):
    global BUBBLE_PROFILE
    if not BUBBLE_PROFILE:
        return
    BUBBLE_PROFILE.disable()
    #s = io.StringIO()
    s = StringIO()
    sortby = 'cumulative'
    #ps = Stats(BUBBLE_PROFILE).sort_stats(sortby)
    ps = Stats(BUBBLE_PROFILE,stream=s).sort_stats(sortby)
    ps.print_stats()
    # print(s.getvalue())
    # now=arrow.now()
    #pstats_file='./logs/profiling'+str(now)+'.pstats'
    #profile_text='./logs/profile'+str(now)+'.txt'
    pstats_file='./logs/profiling.pstats'
    profile_text='./logs/profile.txt'

    BUBBLE_PROFILE.dump_stats(pstats_file)

    with open(profile_text,'a+') as pf:
        pf.write(s.getvalue())
    print("end_profile")
    print('BUBBLE_PROFILE:pstats_file:'+pstats_file)
    print('BUBBLE_PROFILE:profile_text:'+profile_text)
开发者ID:e7dal,项目名称:bubble,代码行数:27,代码来源:profiling.py

示例4: expose

# 需要导入模块: from pstats import Stats [as 别名]
# 或者: from pstats.Stats import print_stats [as 别名]
 def expose(self, widget, event):
     context = widget.window.cairo_create()
     #r = (event.area.x, event.area.y, event.area.width, event.area.height)
     #context.rectangle(r[0]-.5, r[1]-.5, r[2]+1, r[3]+1)
     #context.clip()
     
     if False:
         import profile
         profile.runctx("self.draw(context, event.area)", locals(), globals(), "/tmp/pychessprofile")
         from pstats import Stats
         s = Stats("/tmp/pychessprofile")
         s.sort_stats('cumulative')
         s.print_stats()
     else:
         self.drawcount += 1
         start = time()
         self.animationLock.acquire()
         self.draw(context, event.area)
         self.animationLock.release()
         self.drawtime += time() - start
         #if self.drawcount % 100 == 0:
         #    print "Average FPS: %0.3f - %d / %d" % \
         #      (self.drawcount/self.drawtime, self.drawcount, self.drawtime)
         
     return False
开发者ID:jskurka,项目名称:PyChess-Learning-Module,代码行数:27,代码来源:BoardView.py

示例5: __call__

# 需要导入模块: from pstats import Stats [as 别名]
# 或者: from pstats.Stats import print_stats [as 别名]
    def __call__(self, environ, start_response):
        response_body = []

        def catching_start_response(status, headers, exc_info=None):
            start_response(status, headers, exc_info)
            return response_body.append

        def runapp():
            appiter = self._app(environ, catching_start_response)
            response_body.extend(appiter)
            if hasattr(appiter, 'close'):
                appiter.close()

        p = Profile()
        p.runcall(runapp)
        body = ''.join(response_body)
        stats = Stats(p)
        stats.sort_stats(*self._sort_by)

        self._stream.write('-' * 80)
        self._stream.write('\nPATH: %r\n' % environ.get('PATH_INFO'))
        stats.print_stats(*self._restrictions)
        self._stream.write('-' * 80 + '\n\n')

        return [body]
开发者ID:AndryulE,项目名称:kitsune,代码行数:27,代码来源:profiler.py

示例6: profile

# 需要导入模块: from pstats import Stats [as 别名]
# 或者: from pstats.Stats import print_stats [as 别名]
def profile(to=None, sort_by='cumtime'):
	'''Profiles a chunk of code, use with the ``with`` statement::
	
	    from halonctl.debug import profile
	    
	    with profile('~/Desktop/stats'):
	    	pass # Do something performance-critical here...
	
	Results for individual runs are collected into ``to``. The specifics of how
	reports are done varies depending on what type ``to`` is.
	
	* **File-like objects**: Stats are dumped, according to ``sort_by``, into the stream, separated by newlines - watch out, the file/buffer may grow very big when used in loops.
	* **List-like objects**: A number of pstats.Stats objects are appended.
	* **str and unicode**: Treated as a path and opened for appending. Tildes (~) will be expanded, and intermediary directories created if possible.
	* **None or omitted**: Results are printed to sys.stderr.
	'''
	
	if isinstance(to, six.string_types):
		to = open_fuzzy(to, 'a')
	
	to_is_stream = hasattr(to, 'write')
	to_is_list = hasattr(to, 'append')
	
	p = Profile()
	p.enable()
	yield
	p.disable()
	
	ps = Stats(p, stream=to if to_is_stream else sys.stderr)
	ps.sort_stats('cumtime')
	
	if to_is_stream or to is None:
		ps.print_stats()
	elif to_is_list:
		to.append(ps)
开发者ID:wildegnux,项目名称:halonctl,代码行数:37,代码来源:debug.py

示例7: __analyze2

# 需要导入模块: from pstats import Stats [as 别名]
# 或者: from pstats.Stats import print_stats [as 别名]
 def __analyze2 ():
     import profile
     profile.runctx("self.__analyze2()", locals(), globals(), "/tmp/pychessprofile")
     from pstats import Stats
     s = Stats("/tmp/pychessprofile")
     s.sort_stats('cumulative')
     s.print_stats()
开发者ID:jskurka,项目名称:PyChess-Learning-Module,代码行数:9,代码来源:PyChess.py

示例8: tearDown

# 需要导入模块: from pstats import Stats [as 别名]
# 或者: from pstats.Stats import print_stats [as 别名]
 def tearDown(self):
     if self.should_profile:
         results = Stats(self.profile)
         results.strip_dirs()
         results.sort_stats('cumulative')
         results.print_stats(50)
     super().tearDown()
开发者ID:pamdinevaCfA,项目名称:intake,代码行数:9,代码来源:base.py

示例9: print_stats

# 需要导入模块: from pstats import Stats [as 别名]
# 或者: from pstats.Stats import print_stats [as 别名]
def print_stats(statsfile, statstext):
    with open(statstext, 'w') as f:
        mystats = Stats(statsfile, stream=f)
        mystats.strip_dirs()
        mystats.sort_stats('cumtime')
        # mystats.print_callers('_strptime')
        mystats.print_stats()
    startfile(statstext)
开发者ID:nitetrain8,项目名称:pbslib,代码行数:10,代码来源:open_data_report.py

示例10: profile

# 需要导入模块: from pstats import Stats [as 别名]
# 或者: from pstats.Stats import print_stats [as 别名]
def profile(func, file_path):
    pr = Profile()
    pr.enable()
    func()
    pr.disable()
    s = open(file_path, "w")
    sortby = "cumulative"
    ps = Stats(pr, stream=s).sort_stats(sortby)
    ps.print_stats()
开发者ID:Dexterminator,项目名称:master-thesis,代码行数:11,代码来源:profile_example.py

示例11: print_profile_data

# 需要导入模块: from pstats import Stats [as 别名]
# 或者: from pstats.Stats import print_stats [as 别名]
def print_profile_data():
    """
    Print the collected profile data.
    """
    stream = StringIO()
    statistics = Stats(profiler, stream=stream)
    statistics.sort_stats('cumulative')
    statistics.print_stats()
    print(stream.getvalue())
开发者ID:windyuuy,项目名称:NimLime,代码行数:11,代码来源:internal_tools.py

示例12: profile_call

# 需要导入模块: from pstats import Stats [as 别名]
# 或者: from pstats.Stats import print_stats [as 别名]
def profile_call(_func, *args, **kwargs):
    p = Profile()
    rv = []
    p.runcall(lambda: rv.append(_func(*args, **kwargs)))
    p.dump_stats('/tmp/sentry-%s-%s.prof' % (time.time(), _func.__name__))

    stats = Stats(p, stream=sys.stderr)
    stats.sort_stats('time', 'calls')
    stats.print_stats()
    return rv[0]
开发者ID:280185386,项目名称:sentry,代码行数:12,代码来源:profile.py

示例13: profile

# 需要导入模块: from pstats import Stats [as 别名]
# 或者: from pstats.Stats import print_stats [as 别名]
def profile(func, args=None, kwargs=None, sort="time"):
    prof = profile_.Profile()
    if args is None:
        args = ()
    if kwargs is None:
        kwargs = {}
    ret = prof.runcall(func, *args, **kwargs)
    stats = Stats(prof)
    stats.sort_stats(sort)
    stats.print_stats()
    return ret
开发者ID:flupke,项目名称:pyflu,代码行数:13,代码来源:profile.py

示例14: wrapper

# 需要导入模块: from pstats import Stats [as 别名]
# 或者: from pstats.Stats import print_stats [as 别名]
 def wrapper(*args, **kwg):
     f = func
     res = None
     try:
         cProfile.runctx("res = f(*args, **kwg)", globals(), locals(), filename)
         return res
     finally:
         if filename:
             pstats = Stats(filename)
             pstats.sort_stats(*sort_fields)
             pstats.print_stats(*p_amount)
开发者ID:MrLYC,项目名称:ycyc,代码行数:13,代码来源:decorators.py

示例15: tearDown

# 需要导入模块: from pstats import Stats [as 别名]
# 或者: from pstats.Stats import print_stats [as 别名]
 def tearDown(self):
     for worker in self.driver._workers:
         worker.stop()
         worker.wait()
     self.cvx.endpoint_data.clear()
     super(MechTestBase, self).tearDown()
     if ENABLE_PROFILER:
         p = Stats(self.pr)
         p.strip_dirs()
         p.sort_stats('cumtime')
         p.print_stats()
开发者ID:openstack,项目名称:networking-arista,代码行数:13,代码来源:ml2_test_base.py


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