• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python threading.setprofile函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中threading.setprofile函数的典型用法代码示例。如果您正苦于以下问题:Python setprofile函数的具体用法?Python setprofile怎么用?Python setprofile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了setprofile函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: replace

    def replace(self, function):
        """ Set a new function in sys.setprofile.

        If the function has been already set and it is not the same as before
        then RuntimeError is raised.

        """
        if hasattr(self, 'previous'):
            if function != sys.getprofile():
                raise RuntimeError(
                    'Cannot replace profile function more than once')
            return
        else:
            self.previous = sys.getprofile()
        if has_threading:
            threading.setprofile(function)
        sys.setprofile(function)
开发者ID:enthought,项目名称:pikos,代码行数:17,代码来源:profile_function_manager.py


示例17: start

 def start(self):
     """Start profiling.
     
     This hooks into threading and will record all calls made until
     stop() is called.
     """
     self._g_threadmap = {}
     self.p = Profiler()
     permitted = self.__class__.profiler_lock.acquire(
         self.__class__.profiler_block)
     if not permitted:
         raise errors.InternalBzrError(msg="Already profiling something")
     try:
         self.p.enable(subcalls=True)
         threading.setprofile(self._thread_profile)
     except:
         self.__class__.profiler_lock.release()
         raise
开发者ID:ArslanRafique,项目名称:dist-packages,代码行数:18,代码来源:lsprof.py


示例18: stop

    def stop(self):
        """Stop profiling.

        This unhooks from threading and cleans up the profiler, returning
        the gathered Stats object.

        :return: A bzrlib.lsprof.Stats object.
        """
        try:
            self.p.disable()
            for pp in self._g_threadmap.values():
                pp.disable()
            threading.setprofile(None)
            p = self.p
            self.p = None
            threads = {}
            for tid, pp in self._g_threadmap.items():
                threads[tid] = Stats(pp.getstats(), {})
            self._g_threadmap = None
            return Stats(p.getstats(), threads)
        finally:
            self.__class__.profiler_lock.release()
开发者ID:ArslanRafique,项目名称:dist-packages,代码行数:22,代码来源:lsprof.py


示例19: trace_execution

def trace_execution(fn, *args):
    import inspect

    itt = ITT("python")

    if itt.lib:
        trace_execution.depth = 0
        file_id = itt.get_string_id('__FILE__')
        line_id = itt.get_string_id('__LINE__')
        module_id = itt.get_string_id('__MODULE__')

        def profiler(frame, event, arg):
            if 'call' in event:
                trace_execution.depth += 1
                name = frame.f_code.co_name
                if 'self' in frame.f_locals:
                    cls = frame.f_locals['self'].__class__.__name__
                    name = cls + "." + name
                mdl = inspect.getmodule(frame)
                itt.lib.itt_task_begin(itt.domain, trace_execution.depth, 0, itt.get_string_id(name), 0)
                itt.lib.itt_metadata_add_str(itt.domain, trace_execution.depth, file_id, frame.f_code.co_filename)
                itt.lib.itt_metadata_add(itt.domain, trace_execution.depth, line_id, frame.f_code.co_firstlineno)
                if mdl:
                    itt.lib.itt_metadata_add_str(itt.domain, trace_execution.depth, module_id, mdl.__name__)
            if 'return' in event:
                itt.lib.itt_task_end(itt.domain, 0)
                trace_execution.depth -= 1

        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:Icaraeus,项目名称:IntelSEAPI,代码行数:36,代码来源:sea.py


示例20: profile_on

def profile_on():
    global p_stats, p_start_time
    p_stats = {}
    p_start_time = time.time()
    threading.setprofile(profiler)
    sys.setprofile(profiler)
开发者ID:BackupGGCode,项目名称:bsdradius,代码行数:6,代码来源:profileBsdradius.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python threading.settrace函数代码示例发布时间:2022-05-27
下一篇:
Python threading.main_thread函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap