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


Python threading.setprofile函数代码示例

本文整理汇总了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)
开发者ID:RuralCat,项目名称:CLipPYME,代码行数:7,代码来源:tProfile.py

示例2: start

def start(builtins=False, profile_threads=True):
    """
    Start profiler.
    """
    if profile_threads:
        threading.setprofile(_callback)
    _yappi.start(builtins, profile_threads)
开发者ID:nirs,项目名称:yappi,代码行数:7,代码来源:yappi.py

示例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)
开发者ID:qbektrix,项目名称:profiling,代码行数:7,代码来源:samplers.py

示例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())
开发者ID:GaZ3ll3,项目名称:profiling,代码行数:8,代码来源:profiler.py

示例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
开发者ID:raiden-network,项目名称:raiden,代码行数:8,代码来源:profiler.py

示例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
开发者ID:sckevmit,项目名称:profiling,代码行数:8,代码来源:samplers.py

示例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
开发者ID:imosts,项目名称:flume,代码行数:8,代码来源:thread_monitor.py

示例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)
开发者ID:01org,项目名称:IntelSEAPI,代码行数:58,代码来源:sea.py

示例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)
开发者ID:socialpercon,项目名称:Pratice-Python,代码行数:9,代码来源:threadprofiler.py

示例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
开发者ID:socialpercon,项目名称:Pratice-Python,代码行数:10,代码来源:threadprofiler.py

示例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)
开发者ID:afeset,项目名称:miner2-tools,代码行数:10,代码来源:yappi.py

示例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')
开发者ID:enthought,项目名称:pikos,代码行数:14,代码来源:profile_function_manager.py

示例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)
开发者ID:raiden-network,项目名称:raiden,代码行数:15,代码来源:profiler.py

示例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()
开发者ID:qbektrix,项目名称:profiling,代码行数:15,代码来源:__init__.py

示例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()
开发者ID:Distrotech,项目名称:libpeas,代码行数:16,代码来源:peas-python-internal.py


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