本文整理汇总了Python中yappi.stop方法的典型用法代码示例。如果您正苦于以下问题:Python yappi.stop方法的具体用法?Python yappi.stop怎么用?Python yappi.stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yappi
的用法示例。
在下文中一共展示了yappi.stop方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: import yappi [as 别名]
# 或者: from yappi import stop [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 stop [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 stop [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: run
# 需要导入模块: import yappi [as 别名]
# 或者: from yappi import stop [as 别名]
def run(self, name: str, testdirn: str, coro, do_profiling=False) -> None:
for _ in range(self.num_iters):
# We set up the cortex each time to avoid intra-cortex caching
# (there's still a substantial amount of OS caching)
async with self.getCortexAndProxy() as (core, prox):
gc.collect()
gc.disable()
if do_profiling:
yappi.start()
start = time.time()
count = await coro(core, prox)
await s_lmdbslab.Slab.syncLoopOnce()
self.measurements[name].append((time.time() - start, count))
if do_profiling:
yappi.stop()
gc.enable()
renderProgress()
示例5: init_yappi
# 需要导入模块: import yappi [as 别名]
# 或者: from yappi import stop [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 stop [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 stop [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: unload
# 需要导入模块: import yappi [as 别名]
# 或者: from yappi import stop [as 别名]
def unload():
for grammar in grammars:
grammar.unload()
if tracker.is_connected:
tracker.disconnect()
webdriver.quit_driver()
timer.stop()
server.shutdown()
server_thread.join()
server.server_close()
wake_dummy_thread_timer.stop()
shutdown_dummy_thread_event.set()
dummy_thread.join()
ocr_executor.shutdown(wait=False)
print("Unloaded _repeat.py")
示例9: normalize
# 需要导入模块: import yappi [as 别名]
# 或者: from yappi import stop [as 别名]
def normalize(args):
"""Normalize variants."""
refs = Fastafile(expanduser(args.reference))
variants = VariantFile(args.sample)
with VariantFile(args.output, 'w', header=variants.header) as out:
# Create parallel locus iterator by chromosome
for _, ref, loci in records_by_chromosome(refs, [variants], [None], args):
loci = sort_almost_sorted(loci[0], key=NormalizedLocus.left_order_key)
for locus in loci:
record = locus.record
start = locus.left.start
stop = locus.left.stop
alleles = locus.left.alleles
if '' in alleles:
pad = ref[start - 1:start]
start -= 1
alleles = [pad + a for a in alleles]
record.alleles = alleles
record.start = start
record.stop = stop
out.write(record)
示例10: _stop
# 需要导入模块: import yappi [as 别名]
# 或者: from yappi import stop [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,
)
示例11: update
# 需要导入模块: import yappi [as 别名]
# 或者: from yappi import stop [as 别名]
def update(self, config, current_time=None):
# type: (Configuration, Optional[float]) -> None
"""
Updates the state of the profiler - either enabling or disabling it, based on the current
time and whether or not the current profiling interval has started/stopped.
"""
if not self._is_available:
return
current_time = current_time or time.time()
try:
# check if profiling is enabled in the config and turn it on/off if necessary
if config.enable_profiling:
if not self._is_enabled:
self._update_start_interval(config, current_time)
self._is_enabled = True
else:
if self._is_running():
self._stop(config, current_time)
self._is_enabled = False
# only do profiling if we are still enabled
if not self._is_enabled:
return
# check if the current profiling interval needs to start or stop
if self._is_running():
if current_time > self._profile_end:
self._stop(config, current_time)
self._update_start_interval(config, current_time)
else:
if current_time >= self._profile_start:
self._start(config, current_time)
except Exception as e:
global_log.log(
scalyr_logging.DEBUG_LEVEL_0,
"Failed to update profiler: %s, %s"
% (six.text_type(e), traceback.format_exc()),
limit_once_per_x_secs=300,
limit_key="profiler-update",
)