sys.getprofile

Here are the examples of the python api sys.getprofile taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

10 Examples 7

Example 1

Project: profiling Source File: test_tracing.py
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)

Example 2

Project: pikos Source File: test_profile_functions_manager.py
Function: 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()

Example 3

Project: profiling Source File: __init__.py
    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 docuemented.
            raise RuntimeError('Another profiler already registered')
        with deferral() as defer:
            self._times_entered.clear()
            self.overhead = 0.0
            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

Example 4

Project: pikos Source File: test_profile_functions_manager.py
Function: set_up
    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()

Example 5

Project: pikos Source File: profile_function_manager.py
    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)

Example 6

Project: twisted-theseus Source File: _tracer.py
Function: install
    def install(self):
        """
        Install this tracer as a global `profile hook
        <https://docs.python.org/2/library/sys.html#sys.setprofile>`_.

        The old profile hook, if one is set, will continue to be called by this
        tracer.
        """
        extant_profiler = sys.getprofile()
        if isinstance(extant_profiler, cProfile.Profile):
            raise RuntimeError(
                "the pure-python Tracer is unable to compose over cProfile's "
                "profile function; you must disable cProfile before "
                "installing this Tracer.")
        self._wrapped_profiler = extant_profiler
        sys.setprofile(self._trace)

Example 7

Project: twisted-theseus Source File: _tracer.py
Function: 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)

Example 8

Project: pymo Source File: test_sys_setprofile.py
Function: test_empty
    def test_empty(self):
        self.assertIsNone(sys.getprofile())

Example 9

Project: imagrium Source File: test_profilehooks.py
Function: test_empty
    @unittest.skip("FIXME: broken")
    def test_empty(self):
        assert sys.getprofile() == None

Example 10

Project: iktomi Source File: functools.py
    def test_return_locals_profile_events(self):
        '''Insure profile function gets events for function decorated with
        return_locals at least the same as for function itself.'''
        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
        def inner():
            return 2
        def outer():
            a = 1
            b = inner()
        events1 = set(collect_events(outer))
        events2 = set(collect_events(return_locals(outer)))
        self.assertTrue(events2.issuperset(events1))