本文整理汇总了Python中threading.setprofile函数的典型用法代码示例。如果您正苦于以下问题:Python setprofile函数的具体用法?Python setprofile怎么用?Python setprofile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setprofile函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: profile_on
def profile_on(*filenames):
global p_stats, p_start_time, files
p_stats = []
p_start_time = time.time()
files = filenames
threading.setprofile(profiler)
sys.setprofile(profiler)
示例2: start
def start(builtins=False, profile_threads=True):
"""
Start profiler.
"""
if profile_threads:
threading.setprofile(_callback)
_yappi.start(builtins, profile_threads)
示例3: run
def run(self, profiler):
profile = functools.partial(self._profile, profiler)
sys.setprofile(profile)
threading.setprofile(profile)
yield
threading.setprofile(None)
sys.setprofile(None)
示例4: start
def start(self):
if sys.getprofile() is not None:
raise RuntimeError('Another profiler already registered.')
self._running = True
sys.setprofile(self._profile)
threading.setprofile(self._profile)
self.timer.start()
self.stats.record_starting(time.clock())
示例5: stop_profiler
def stop_profiler():
# we keep the _state around for the user until the next session
# Unregister the profiler in this order, otherwise we will have extra
# measurements in the end
sys.setprofile(None)
threading.setprofile(None)
greenlet.settrace(None) # pylint: disable=no-member
示例6: run
def run(self, profiler):
profile = functools.partial(self._profile, profiler)
with deferral() as defer:
sys.setprofile(profile)
defer(sys.setprofile, None)
threading.setprofile(profile)
defer(threading.setprofile, None)
yield
示例7: activate_hook
def activate_hook():
""" Activates the thread monitor hook. Note that this interferes
with any kind of profiler and some debugging extensions. """
global hook_enabled
sys.setprofile(dump_hook)
threading.setprofile(dump_hook)
hook_enabled = True
示例8: trace_execution
def trace_execution(fn, args, save_to=None):
import inspect
if save_to:
os.environ["INTEL_SEA_SAVE_TO"] = save_to
itt = ITT("python")
if itt.lib:
file_id = itt.get_string_id("__FILE__")
line_id = itt.get_string_id("__LINE__")
module_id = itt.get_string_id("__MODULE__")
trace_execution.frames = {}
trace_execution.recurrent = False
high_part = 2 ** 32
def profiler(frame, event, arg): # https://pymotw.com/2/sys/tracing.html
if trace_execution.recurrent:
return
trace_execution.recurrent = True
task_id = id(frame.f_code)
if "call" in event:
if task_id in trace_execution.frames:
trace_execution.frames[task_id] += 1
else:
trace_execution.frames[task_id] = 1
task_id += trace_execution.frames[task_id] * high_part
name = frame.f_code.co_name + ((" (%s)" % arg.__name__) if arg else "")
if "self" in frame.f_locals:
cls = frame.f_locals["self"].__class__.__name__
name = cls + "." + name
# print event, name, task_id, arg
mdl = inspect.getmodule(frame)
itt.lib.itt_task_begin_overlapped(itt.domain, task_id, 0, itt.get_string_id(name), 0)
itt.lib.itt_metadata_add_str(itt.domain, task_id, file_id, frame.f_code.co_filename)
itt.lib.itt_metadata_add(itt.domain, task_id, line_id, frame.f_code.co_firstlineno)
if mdl:
itt.lib.itt_metadata_add_str(itt.domain, task_id, module_id, mdl.__name__)
elif "return" in event:
# print event, frame.f_code.co_name, task_id + trace_execution.frames[task_id] * high_part
if task_id in trace_execution.frames:
itt.lib.itt_task_end_overlapped(
itt.domain, 0, task_id + trace_execution.frames[task_id] * high_part
)
if trace_execution.frames[task_id] > 1:
trace_execution.frames[task_id] -= 1
else:
del trace_execution.frames[task_id]
trace_execution.recurrent = False
print trace_execution.frames
old_profiler = sys.getprofile()
sys.setprofile(profiler)
old_threading_profiler = threading.setprofile(profiler)
fn(*args)
sys.setprofile(old_profiler)
threading.setprofile(old_threading_profiler)
else:
fn(*args)
示例9: runcall
def runcall(self, func, *args, **kw):
self.set_cmd(repr(func))
threading.setprofile(self.dispatcher)
sys.setprofile(self.dispatcher)
try:
return func(*args, **kw)
finally:
sys.setprofile(None)
threading.setprofile(None)
示例10: runctx
def runctx(self, cmd, globals, locals):
self.set_cmd(cmd)
threading.setprofile(self.dispatcher)
sys.setprofile(self.dispatcher)
try:
exec cmd in globals, locals
finally:
sys.setprofile(None)
threading.setprofile(None)
return self
示例11: start
def start(builtins=False):
'''
Args:
builtins: If set true, then builtin functions are profiled too.
timing_sample: will cause the profiler to do timing measuresements
according to the value. Will increase profiler speed but
decrease accuracy.
'''
threading.setprofile(__callback)
_yappi.start(builtins)
示例12: recover
def recover(self):
""" Unset the current function in the sys.setprofile.
If available the previous method is recovered in setprofile. A
RuntimeError is raised if the `previous` attribute does not exist.
"""
if hasattr(self, 'previous'):
sys.setprofile(self.previous)
if has_threading:
threading.setprofile(self.previous)
del self.previous
else:
raise RuntimeError('A profile function has not been set')
示例13: start_profiler
def start_profiler():
global _state
_state = GlobalState()
frame = sys._getframe(0)
current_greenlet = greenlet.getcurrent() # pylint: disable=no-member
thread_state = ensure_thread_state(current_greenlet, frame)
_state.last = thread_state
# this needs to be instantiate before the handler is installed
greenlet.settrace(greenlet_profiler) # pylint: disable=no-member
sys.setprofile(thread_profiler)
threading.setprofile(thread_profiler)
示例14: run
def run(self):
if sys.getprofile() is not None:
# NOTE: There's no threading.getprofile().
# The profiling function will be stored at threading._profile_hook
# but it's not documented.
raise RuntimeError('Another profiler already registered')
with deferral() as defer:
sys.setprofile(self._profile)
defer(sys.setprofile, None)
threading.setprofile(self._profile)
defer(threading.setprofile, None)
self.timer.start(self)
defer(self.timer.stop)
yield
self._times_entered.clear()
示例15: __init__
def __init__(self):
super(Hooks, self).__init__()
sort = os.getenv('PEAS_PYTHON_PROFILE', default='time')
self.__stat_sort = sort.split(';')
self.__stats = None
self.__stats_lock = threading.Lock()
self.__thread_refs = []
self.__thread_local = threading.local()
threading.setprofile(self.__init_thread)
self.__profile = cProfile.Profile()
self.__profile.enable()