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

Python sys.getprofile函数代码示例

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

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



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

示例1: test_setprofile

def test_setprofile():
    profiler = TracingProfiler()
    assert sys.getprofile() is None
    with profiler:
        assert sys.getprofile() == profiler._profile
    assert sys.getprofile() is None
    sys.setprofile(lambda *x: x)
    with pytest.raises(RuntimeError):
        profiler.start()
    sys.setprofile(None)
开发者ID:sublee,项目名称:profiling,代码行数:10,代码来源:test_tracing.py


示例2: test_profile_enable_disable

    def test_profile_enable_disable(self):
        prof = self.profilerclass()
        # Make sure we clean ourselves up if the test fails for some reason.
        self.addCleanup(prof.disable)

        prof.enable()
        self.assertIs(sys.getprofile(), prof)

        prof.disable()
        self.assertIs(sys.getprofile(), None)
开发者ID:Eyepea,项目名称:cpython,代码行数:10,代码来源:test_cprofile.py


示例3: test_error_when_set_multiple

    def test_error_when_set_multiple(self):
        self.monitor._profile.replace(self.bar)
        self.assertIs(sys.getprofile(), self.bar)
        self.monitor._profile.replace(self.bar)
        self.assertIs(sys.getprofile(), self.bar)
        self.monitor._profile.recover()

        self.monitor._profile.replace(self.bar)
        self.assertIs(sys.getprofile(), self.bar)
        with self.assertRaises(RuntimeError):
            self.monitor._profile.replace(None)
            self.assertIs(sys.getprofile(), self.bar)
        self.monitor._profile.recover()
开发者ID:enthought,项目名称:pikos,代码行数:13,代码来源:test_profile_functions_manager.py


示例4: test_profile_as_context_manager

    def test_profile_as_context_manager(self):
        prof = self.profilerclass()
        # Make sure we clean ourselves up if the test fails for some reason.
        self.addCleanup(prof.disable)

        with prof as __enter__return_value:
            # profile.__enter__ should return itself.
            self.assertIs(prof, __enter__return_value)

            # profile should be set as the global profiler inside the
            # with-block
            self.assertIs(sys.getprofile(), prof)

        # profile shouldn't be set once we leave the with-block.
        self.assertIs(sys.getprofile(), None)
开发者ID:Eyepea,项目名称:cpython,代码行数:15,代码来源:test_cprofile.py


示例5: get_info_on_next_invocation

    def get_info_on_next_invocation(self, func, callback, needed):
        """
        func is a tuple (filename, funcname)
        needed is a list/tuple of NeededInfo objects
        """

        if isinstance(needed, NeededInfo):
            needed = (needed,)

        request = WatchRequest(needed, {}, callback)
        if func in self.watching_funcs:
            self.watching_funcs[func].requests.append(request)
        else:
            self.watching_funcs[func] = FuncWatchStatus(func, requests=[request])
        fws = self.watching_funcs[func]

        for ni in needed:
            hsh = 0
            for i in range(ni.stmt_idx+1):
                hsh += hash(ni.stmt_sequence[i])
                #cprint ("adding to hash %s: %i"%(str(ni.stmt_sequence[i]), hsh), 'green')
            if hsh in fws.ni_hashmap:
                fws.ni_hashmap[hsh].append((request,ni))
            else:
                fws.ni_hashmap[hsh] = [(request,ni)]

        cprint("finishing up get_info_on_next_invocation", 'red')

        # XXX Why do I need to use both settrace and setprofile?  settrace doesn't
        # XXX trigger on return events, and setprofile doesn't trigger on line events...
        self.old_trace, self.old_profile = sys.gettrace(), sys.getprofile()
        sys.settrace(self.trace_cb)
        sys.setprofile(self.profile_cb)
开发者ID:RichardWarfield,项目名称:heimdall,代码行数:33,代码来源:watcher.py


示例6: __init__

    def __init__(self, metascript):
        # Indicates when activations should be collected
        #   (only after the first call to the script)
        self.enabled = False
        # User files
        self.script = metascript.path
        self.paths = metascript.paths
        # Which function types ('main', 'package' or 'all')
        #   should be considered for the threshold
        self.context = metascript.context
        # How deep we want to go when capturing function activations?
        self.depth_threshold = metascript.depth
        # How deep we want to go beyond our context
        self.non_user_depth_threshold = metascript.non_user_depth

        # Object serializer function
        self.serialize = metascript.serialize

        self.metascript = metascript
        self.trial_id = metascript.trial_id
        self.event_map = defaultdict(lambda: self.trace_empty, {})
        self.default_profile = sys.getprofile()
        self.default_trace = sys.gettrace()

        self.argument_captor = ArgumentCaptor(self)
开发者ID:LEONOB2014,项目名称:noworkflow,代码行数:25,代码来源:base.py


示例7: 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


示例8: task

 def task(self, expected_trace_function=None, expected_profile_function=None):
     # this task tests that the trace/profile function has the
     # expected value
     tasklet = stackless.current
     self.assertIs(sys.gettrace(), expected_trace_function)
     self.assertIs(tasklet.trace_function, expected_trace_function)
     self.assertIs(sys.getprofile(), expected_profile_function)
     self.assertIs(tasklet.profile_function, expected_profile_function)
开发者ID:dev-alex-alex2006hw,项目名称:tools,代码行数:8,代码来源:test_tracing.py


示例9: setUp

 def setUp(self):
     if sys.gettrace() or sys.getprofile():
         self.skipTest("Trace or profile function already active")
     self.addCleanup(sys.settrace, None)
     self.addCleanup(stackless.set_schedule_callback, None)
     self.schedule_callback_exc = []
     self.unexpected_trace_events = []
     self.m = mutex()
开发者ID:dev-alex-alex2006hw,项目名称:tools,代码行数:8,代码来源:test_tracing.py


示例10: 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


示例11: 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


示例12: task2

 def task2(self, expected_trace_function=None, expected_profile_function=None):
     # task switches tasklets and then tests that the trace/profile function has the
     # expected value
     stackless.schedule()
     tasklet = stackless.current
     self.assertIs(sys.gettrace(), expected_trace_function)
     self.assertIs(tasklet.trace_function, expected_trace_function)
     self.assertIs(sys.getprofile(), expected_profile_function)
     self.assertIs(tasklet.profile_function, expected_profile_function)
开发者ID:dev-alex-alex2006hw,项目名称:tools,代码行数:9,代码来源:test_tracing.py


示例13: main

 def main():
     i = 1500
     orig_profile = sys.getprofile()
     sys.setprofile(profile)
     try:
         while i > 0:
             i = sub(i, 1)
     finally:
         sys.setprofile(orig_profile)
开发者ID:alex,项目名称:tracebin,代码行数:9,代码来源:test_hook.py


示例14: testSetTraceOnCurrent

 def testSetTraceOnCurrent(self):
     tf = self.nullTraceFunc
     tasklet = stackless.current
     self.assertIsNone(sys.gettrace())
     self.assertIsNone(sys.getprofile())
     self.assertIsNone(tasklet.trace_function)
     self.assertIsNone(tasklet.profile_function)
     tasklet.trace_function = tf
     self.assertIs(sys.gettrace(), tf)
     self.assertIsNone(sys.getprofile())
     self.assertIs(tasklet.trace_function, tf)
     self.assertIsNone(tasklet.profile_function)
     tasklet.trace_function = None
     self.assertIsNone(sys.gettrace())
     self.assertIsNone(sys.getprofile())
     self.assertIsNone(tasklet.trace_function)
     self.assertIsNone(tasklet.profile_function)
     self.assertGreater(self.tracecount, 0)
开发者ID:dev-alex-alex2006hw,项目名称:tools,代码行数:18,代码来源:test_tracing.py


示例15: uninstall

    def uninstall(self):
        """
        Deactivate this tracer.

        If another profile hook was installed after this tracer was installed,
        nothing will happen. If a different profile hook was installed prior to
        calling ``install()``, it will be restored.
        """
        if sys.getprofile() == self._trace:
            sys.setprofile(self._wrapped_profiler)
开发者ID:caseymacphee,项目名称:twisted-theseus,代码行数:10,代码来源:_tracer.py


示例16: start

def start():
    """
    Turn on memory profiling.
    """
    global _trace_memory
    if sys.getprofile() is not None:
        raise RuntimeError("another profile function is already active.")
    if _trace_memory is None:
        raise RuntimeError("trace.setup() was not called before trace.start().")
    sys.setprofile(_trace_memory)
开发者ID:samtx,项目名称:OpenMDAO,代码行数:10,代码来源:iprof_mem.py


示例17: setUp

    def setUp(self):
        self.old = sys.getprofile()

        def foo():
            pass

        def bar(frame, event, arg):
            pass
        self.foo = foo
        self.bar = bar
        self.monitor = MockNativeMonitor()
开发者ID:enthought,项目名称:pikos,代码行数:11,代码来源:test_profile_functions_manager.py


示例18: collect_events

 def collect_events(func):
     events = []
     def tracer(frame, event, args):
         events.append((frame.f_code, event))
     old_tracer = sys.getprofile()
     sys.setprofile(tracer)
     try:
         func()
     finally:
         sys.setprofile(old_tracer)
     return events
开发者ID:Lehych,项目名称:iktomi,代码行数:11,代码来源:functools.py


示例19: add

    def add(self, gl):
        if id(gl) not in self.gl:
            # don't know about this module / globals yet

            if not self.gl:
                # install the profiler / cleanup handler, but keep the old one
                self.op = sys.getprofile()
                sys.setprofile(self)

            # keep the reference for later
            self.gl[id(gl)] = gl
开发者ID:josiahcarlson,项目名称:mprop,代码行数:11,代码来源:mprop.py


示例20: test_execute_and_capture_locals

def test_execute_and_capture_locals():

    def func():
        a=3
        return a+4

    def outer_func():
        b=4
        def nested():
            return func()+b+5
        return nested

    out, local_vars = execute_and_capture_locals(func)
    assert out == 3+4
    assert local_vars == {'a': 3}
    assert sys.getprofile() is None

    out, local_vars = execute_and_capture_locals(outer_func())
    assert out == 7+4+5
    assert local_vars == {'b': 4, 'func': func}
    assert sys.getprofile() is None
开发者ID:qyx268,项目名称:plato,代码行数:21,代码来源:test_local_capture.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python sys.getrecursionlimit函数代码示例发布时间:2022-05-27
下一篇:
Python sys.getfilesystemencoding函数代码示例发布时间: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