本文整理汇总了Python中pstats.Stats.sort_stats方法的典型用法代码示例。如果您正苦于以下问题:Python Stats.sort_stats方法的具体用法?Python Stats.sort_stats怎么用?Python Stats.sort_stats使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pstats.Stats
的用法示例。
在下文中一共展示了Stats.sort_stats方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _execute
# 需要导入模块: from pstats import Stats [as 别名]
# 或者: from pstats.Stats import sort_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
示例2: stopTest
# 需要导入模块: from pstats import Stats [as 别名]
# 或者: from pstats.Stats import sort_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)
示例3: __init__
# 需要导入模块: from pstats import Stats [as 别名]
# 或者: from pstats.Stats import sort_stats [as 别名]
def __init__(self):
settings_manager = SettingsManager() # Set up the settings_manager
max_workers = settings_manager.getint('application', 'max-workers') # Get the max workers from settings manager
profiler_on = settings_manager.getint('debugging', 'profiler-on') # Get whether there is a profiler
absolute = settings_manager.getint('save', 'absolute') # Get whether it's an absolute path
save_path = settings_manager.get('save', 'path') # Get whether it's an absolute path
if not absolute:
save_path = PROJECT_PATH + os.path.sep + save_path
executor = ThreadPoolExecutor(max_workers=max_workers, profiler_on=profiler_on) # Set up the thread executor
dis = Disassembler(settings_manager) # Build the disassembler
server = PyDAServer('0.0.0.0',9000) # Set up the PyDA server
save_manager = SaveManager(save_path)
if profiler_on:
profile = Profile()
profile.enable()
app.build_and_run(settings_manager, dis, executor, server, save_manager) # Run the interface
if profiler_on:
profile.disable()
stats = executor.getProfileStats()
if stats == None:
stats = Stats(profile)
else:
stats.add(profile)
with open('profile.stats', 'wb') as statsfile:
stats.stream = statsfile
stats.sort_stats('cumulative').print_stats()
示例4: expose
# 需要导入模块: from pstats import Stats [as 别名]
# 或者: from pstats.Stats import sort_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
示例5: profile
# 需要导入模块: from pstats import Stats [as 别名]
# 或者: from pstats.Stats import sort_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)
示例6: __call__
# 需要导入模块: from pstats import Stats [as 别名]
# 或者: from pstats.Stats import sort_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]
示例7: tearDown
# 需要导入模块: from pstats import Stats [as 别名]
# 或者: from pstats.Stats import sort_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()
示例8: __analyze2
# 需要导入模块: from pstats import Stats [as 别名]
# 或者: from pstats.Stats import sort_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()
示例9: tearDownClass
# 需要导入模块: from pstats import Stats [as 别名]
# 或者: from pstats.Stats import sort_stats [as 别名]
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')
示例10: print_stats
# 需要导入模块: from pstats import Stats [as 别名]
# 或者: from pstats.Stats import sort_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)
示例11: print_profile_data
# 需要导入模块: from pstats import Stats [as 别名]
# 或者: from pstats.Stats import sort_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())
示例12: home_p
# 需要导入模块: from pstats import Stats [as 别名]
# 或者: from pstats.Stats import sort_stats [as 别名]
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")
示例13: profile_call
# 需要导入模块: from pstats import Stats [as 别名]
# 或者: from pstats.Stats import sort_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]
示例14: wrapper
# 需要导入模块: from pstats import Stats [as 别名]
# 或者: from pstats.Stats import sort_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)
示例15: show_time_profiler_results
# 需要导入模块: from pstats import Stats [as 别名]
# 或者: from pstats.Stats import sort_stats [as 别名]
def show_time_profiler_results(pr, top_records):
"""
Show results of timed profiling.
:param pr: profiler instance
:param top_records: how many top function calls to show.
"""
if pr:
st = Stats(pr)
st.strip_dirs()
st.sort_stats('cumulative')
st.print_stats(top_records)