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


Python pstats.Stats类代码示例

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


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

示例1: stats_for_fib

def stats_for_fib(type_, fib):
    p = Profile()
    p.runcall(fib, 30)
    p.dump_stats(type_.lower().replace(' ', '_') + '.stats')
    s = Stats(p)
    s.strip_dirs().sort_stats('time', 'cumulative')
    print_stats(type_, s)
开发者ID:cristina0botez,项目名称:ExpertPythonProgramming,代码行数:7,代码来源:macro_profiling.py

示例2: __analyze2

 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,代码行数:7,代码来源:PyChess.py

示例3: print_stats

def print_stats(limit=limit, sort=sort, strip_dirs=strip_dirs):
    if _have_stats:
        stats = Stats(_profile)
        if strip_dirs:
            stats.strip_dirs()
        apply(stats.sort_stats, sort)
        apply(stats.print_stats, limit)
开发者ID:wpjunior,项目名称:proled,代码行数:7,代码来源:profiler.py

示例4: __call__

    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,代码行数:25,代码来源:profiler.py

示例5: __init__

    def __init__(self, *args, **kwds):
        Stats.__init__(self, *args, **kwds)

        self.workbook = xlsxwriter.Workbook(args[0] + ".xlsx")
        self.worksheet = self.workbook.add_worksheet()
        self.worksheet.set_column('A:F', 15)
        self.worksheet.set_column('G:H', 90)
开发者ID:Seeincup-Ming,项目名称:CProfileAnalysisTool,代码行数:7,代码来源:CProfileAnalysisTool.py

示例6: run

def run(number=100000):
    sys.path[0] = '.'
    path = os.getcwd()
    print("              msec    rps  tcalls  funcs")
    for framework in frameworks:
        os.chdir(os.path.join(path, framework))
        try:
            main = __import__('app', None, None, ['main']).main

            f = lambda: list(main(environ.copy(), start_response))
            time = timeit(f, number=number)
            st = Stats(profile.Profile().runctx(
                'f()', globals(), locals()))
            print("%-11s %6.0f %6.0f %7d %6d" % (framework, 1000 * time,
                  number / time, st.total_calls, len(st.stats)))
            if 0:
                st = Stats(profile.Profile().runctx(
                    'timeit(f, number=number)', globals(), locals()))
                st.strip_dirs().sort_stats('time').print_stats(10)
            del sys.modules['app']
        except ImportError:
            print("%-15s not installed" % framework)
        modules = [m for m in sys.modules.keys() if m.endswith('helloworld')]
        for m in modules:
            del sys.modules[m]
开发者ID:nbari,项目名称:zunzuncito,代码行数:25,代码来源:benchmark.py

示例7: stopTest

 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,代码行数:7,代码来源:Test_Result.py

示例8: admin_menu

def admin_menu():
    from pygame.display import set_mode, list_modes, set_caption
    from pygame import init, quit

    init()
    screen = set_mode(list_modes()[0])
    set_caption("Hero Misadventures")
    menu = Menu(("Debug", "Release"), screen, text_color=color("White"), surface=color("Black"),
                selection_color=color("Slate Gray"))
    while True:
        choose = menu.update()
        if choose == -1:
            continue
        else:
            if choose == 0:
                from cProfile import runctx
                from pstats import Stats

                runctx("from bin.Interaction import debug_menu; debug_menu(screen)", {"screen": screen}, {}, "test/profiling.prof")
                file = open("test/profiling.txt", "w")
                info = Stats("test/profiling.prof", stream=file)
                info.strip_dirs().sort_stats("cumulative").print_stats()
            elif choose == 1:
                quit()
                start_menu()
            return
开发者ID:creators1303,项目名称:Hex_Platform,代码行数:26,代码来源:Interaction.py

示例9: get_stats

    def get_stats(self, session):
        output = StringIO()
        stats = None
        temp_files = []
        try:
            for profile in session.profiles.all():
                if profile.dump.path:
                    log.debug('Adding local profile dump')
                    path = profile.dump.path
                else:
                    log.debug('Creating a temporary file for remote profile dump')
                    temp, path = mkstemp(dir=self.tempdir)
                    temp = fdopen(temp)
                    temp_files.append((temp, path))
                    log.debug('Copying content from remote dump to tempfile')
                    temp.write(profile.dump.read())
                    log.debug('Adding tempfile profile dump')
                if stats is None:
                    log.debug('Creating a Stats object')
                    stats = Stats(path, stream=output)
                else:
                    log.debug('Appending to existing Stats object')
                    stats.add(path)
        finally:
            for temp, path in temp_files:
                log.debug('Removing temporary file at %s' % (path,))
                temp.close()
                unlink(path)

        return stats, output
开发者ID:TAMUArch,项目名称:django-profiling,代码行数:30,代码来源:db.py

示例10: expose

 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,代码行数:25,代码来源:BoardView.py

示例11: profile

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,代码行数:35,代码来源:debug.py

示例12: write_profile

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,代码行数:25,代码来源:profiling.py

示例13: profile

def profile():
    ''' Function used to profile code for speedups. '''    
    
    import cProfile
    cProfile.run('main(50)', 'pstats')
    from pstats import Stats
    p = Stats('pstats')
    p.strip_dirs().sort_stats('time').print_stats(10)
开发者ID:roesel,项目名称:growth,代码行数:8,代码来源:main.py

示例14: tearDownClass

 def tearDownClass(cls):
     if cls.is_running:
         return
     urlopen('http://localhost:8000/quit')
     cls.cli.close()
     p = Stats(cls.profiler)
     p.strip_dirs()
     p.sort_stats('cumtime')
开发者ID:GUI-Junkie,项目名称:Schema.org-Generator,代码行数:8,代码来源:test_controller.py

示例15: home_p

def home_p(request):
    """Profiled version of home"""
    prof = Profile()
    prof = prof.runctx("home(request)", globals(), locals())
    stream = StringIO()
    stats = Stats(prof, stream=stream)
    stats.sort_stats("time").print_stats(80)
    log.info("Profile data:\n%s", stream.getvalue())
    return HttpResponse(u"OK")
开发者ID:afternoon,项目名称:followize,代码行数:9,代码来源:views.py


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