本文整理汇总了Python中yappi.get_func_stats方法的典型用法代码示例。如果您正苦于以下问题:Python yappi.get_func_stats方法的具体用法?Python yappi.get_func_stats怎么用?Python yappi.get_func_stats使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yappi
的用法示例。
在下文中一共展示了yappi.get_func_stats方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: import yappi [as 别名]
# 或者: from yappi import get_func_stats [as 别名]
def main():
"""Just vgraph's main CLI function."""
parser = arg_parser()
args = parser.parse_args()
if args.profile:
import yappi
yappi.start()
try:
run_vgraph(parser, args)
finally:
yappi.stop()
stats = yappi.get_func_stats().sort('tsub').strip_dirs()
stats.print_all(out=sys.stderr, columns={0: ('name', 45), 1: ('ncall', 10), 2: ('tsub', 8), 3: ('ttot', 8), 4: ('tavg', 8)})
else:
run_vgraph(parser, args)
示例2: __call__
# 需要导入模块: import yappi [as 别名]
# 或者: from yappi import get_func_stats [as 别名]
def __call__(self, *args, **kwargs):
import yappi
import io as python_io
yappi.start()
try:
return await self.target(*args, **kwargs)
finally:
yappi.stop()
s = python_io.StringIO()
yappi.get_func_stats().print_all(out=s, columns={
0: ("name", 140),
1: ("ncall", 8),
2: ("tsub", 8),
3: ("ttot", 8),
4: ("tavg", 8)
})
profile = "\n=== Profile START ===\n"
profile += s.getvalue()
profile += "=== Profile END ==="
self.profile_logger.info(profile)
示例3: _capture_profile
# 需要导入模块: import yappi [as 别名]
# 或者: from yappi import get_func_stats [as 别名]
def _capture_profile(fname=''):
if not fname:
yappi.set_clock_type('cpu')
# We need to set context to greenlet to profile greenlets
# https://bitbucket.org/sumerc/yappi/pull-requests/3
yappi.set_context_id_callback(
lambda: id(greenlet.getcurrent()))
yappi.set_context_name_callback(
lambda: greenlet.getcurrent().__class__.__name__)
yappi.start()
else:
yappi.stop()
stats = yappi.get_func_stats()
# User should provide filename. This file with a suffix .prof
# will be created in temp directory.
try:
stats_file = os.path.join(tempfile.gettempdir(), fname + '.prof')
stats.save(stats_file, "pstat")
except Exception as e:
print("Error while saving the trace stats ", str(e))
finally:
yappi.clear_stats()
示例4: cmdloop
# 需要导入模块: import yappi [as 别名]
# 或者: from yappi import get_func_stats [as 别名]
def cmdloop(shell, func, args, use_yappi, single_command):
try:
if use_yappi:
import yappi
yappi.start()
func(*args)
yappi.get_func_stats().print_all()
else:
func(*args)
except (KeyboardInterrupt, SystemExit):
if not single_command:
shell.intro = terminal.fg_red() + \
"\nTo exit asadm utility please run exit command." + \
terminal.fg_clear()
cmdloop(shell, func, args, use_yappi, single_command)
示例5: init_yappi
# 需要导入模块: import yappi [as 别名]
# 或者: from yappi import get_func_stats [as 别名]
def init_yappi():
import atexit
import yappi
print('[YAPPI START]')
# yappi.set_clock_type('')
yappi.start()
@atexit.register
def finish_yappi():
print('[YAPPI STOP]')
yappi.stop()
print('[YAPPI WRITE]')
stats = yappi.get_func_stats()
for stat_type in ['pstat', 'callgrind', 'ystat']:
print('writing run_stats.{}'.format(stat_type))
stats.save('run_stats.{}'.format(stat_type), type=stat_type)
print('\n[YAPPI FUNC_STATS]')
print('writing run_stats.func_stats')
with open('run_stats.func_stats', 'w') as fh:
stats.print_all(out=fh)
print('\n[YAPPI THREAD_STATS]')
print('writing run_stats.thread_stats')
tstats = yappi.get_thread_stats()
with open('run_stats.thread_stats', 'w') as fh:
tstats.print_all(out=fh)
print('[YAPPI OUT]')
示例6: main
# 需要导入模块: import yappi [as 别名]
# 或者: from yappi import get_func_stats [as 别名]
def main():
try:
if conf.ENABLE_PROFILING:
yappi.start()
launcher.main(sys.argv[1:])
yappi.stop()
else:
launcher.main(sys.argv[1:])
except KeyboardInterrupt:
if conf.ENABLE_PROFILING:
yappi.stop()
print('Yappi result (func stats) ======================')
yappi.get_func_stats().print_all()
print('Yappi result (thread stats) ======================')
yappi.get_thread_stats().print_all()
示例7: stop_profiling
# 需要导入模块: import yappi [as 别名]
# 或者: from yappi import get_func_stats [as 别名]
def stop_profiling():
yappi.stop()
yappi.get_func_stats().print_all()
yappi.get_thread_stats().print_all()
has_argv = hasattr(sys, "argv")
if not has_argv:
sys.argv = [""]
profile_path = os.path.join(local.HOME, "yappi_{}.callgrind.out".format(time.time()))
yappi.get_func_stats().save(profile_path, "callgrind")
yappi.clear_stats()
# TODO Remove after adding support for saving OCR data.
# def move_to_text(text, cursor_position=None):
# if not cursor_position:
# cursor_position = screen_ocr.CursorPosition.MIDDLE
# word = str(text)
# screen_contents, ocr_timestamp = ocr_future.result()
# click_position = screen_contents.find_nearest_word_coordinates(word, cursor_position)
# if local.SAVE_OCR_DATA_DIR:
# file_name_prefix = "{}_{:.2f}".format("success" if click_position else "failure", time.time())
# file_path_prefix = os.path.join(local.SAVE_OCR_DATA_DIR, file_name_prefix)
# screen_contents.screenshot.save(file_path_prefix + ".png")
# with open(file_path_prefix + ".txt", "w") as file:
# file.write(word)
# if not click_position:
# # Raise an exception so that the action returns False.
# raise RuntimeError("No matches found after delay {:.2f} for word: {}".format(time.time() - ocr_timestamp, word))
# Mouse("[{}, {}]".format(int(click_position[0]), int(click_position[1]))).execute()
# Actions of commonly used text navigation and mousing commands. These can be
# used anywhere except after commands which include arbitrary dictation.
# TODO: Better solution for holding shift during a single command. Think about whether this could enable a simpler grammar for other modifiers.
示例8: _stop
# 需要导入模块: import yappi [as 别名]
# 或者: from yappi import get_func_stats [as 别名]
def _stop(self, config, current_time):
yappi.stop()
global_log.log(scalyr_logging.DEBUG_LEVEL_0, "Stopping CPU profiling")
stats = yappi.get_func_stats()
if os.path.exists(self._data_file_path):
os.remove(self._data_file_path)
# pylint bug https://github.com/PyCQA/pylint/labels/topic-inference
stats.save(self._data_file_path, "callgrind") # pylint: disable=no-member
lines = 0
# count the lines
f = open(self._data_file_path)
try:
for line in f:
lines += 1
finally:
f.close()
# write a status message to make it easy to find the end of each profile session
f = open(self._data_file_path, "a")
try:
f.write(
"\n# %s, %s clock, total lines: %d\n"
% (self._data_file_path, self._profile_clock, lines)
)
finally:
f.close()
yappi.clear_stats()
del stats
global_log.log(
scalyr_logging.DEBUG_LEVEL_0,
"CPU profiling data written to %s",
self._data_file_path,
)
示例9: profile
# 需要导入模块: import yappi [as 别名]
# 或者: from yappi import get_func_stats [as 别名]
def profile(config_location="/etc/redeem"):
import yappi
yappi.start()
main(config_location)
yappi.get_func_stats().print_all()