Beispiel #1
0
def test_direct():
    class MyCode:
        pass

    def get_name(mycode):
        raise NotImplementedError

    rvmprof.register_code_object_class(MyCode, get_name)
    #
    @rvmprof.vmprof_execute_code("mycode",
                                 lambda code, level: code,
                                 _hack_update_stack_untranslated=True)
    def mainloop(code, level):
        if level > 0:
            mainloop(code, level - 1)
        else:
            p, length = traceback.traceback(20)
            traceback.walk_traceback(MyCode, my_callback, 42, p, length)
            lltype.free(p, flavor='raw')

    #
    seen = []

    def my_callback(code, loc, arg):
        seen.append((code, loc, arg))

    #
    code1 = MyCode()
    rvmprof.register_code(code1, "foo")
    mainloop(code1, 2)
    #
    assert seen == [(code1, traceback.LOC_INTERPRETED, 42),
                    (code1, traceback.LOC_INTERPRETED, 42),
                    (code1, traceback.LOC_INTERPRETED, 42)]
Beispiel #2
0
def test_direct():
    class MyCode:
        pass

    def get_name(mycode):
        raise NotImplementedError

    rvmprof.register_code_object_class(MyCode, get_name)
    #
    @rvmprof.vmprof_execute_code("mycode", lambda code, level: code, _hack_update_stack_untranslated=True)
    def mainloop(code, level):
        if level > 0:
            mainloop(code, level - 1)
        else:
            p, length = traceback.traceback(20)
            traceback.walk_traceback(MyCode, my_callback, 42, p, length)
            lltype.free(p, flavor="raw")

    #
    seen = []

    def my_callback(code, loc, arg):
        seen.append((code, loc, arg))

    #
    code1 = MyCode()
    rvmprof.register_code(code1, "foo")
    mainloop(code1, 2)
    #
    assert seen == [
        (code1, traceback.LOC_INTERPRETED, 42),
        (code1, traceback.LOC_INTERPRETED, 42),
        (code1, traceback.LOC_INTERPRETED, 42),
    ]
Beispiel #3
0
 def main(n):
     codes = [CodeObj("main"), CodeObj("not main")]
     for code in codes:
         register_code(code, get_name)
     try:
         f(codes, codes[0], n, 8)
     except MyExc as e:
         return e.c
Beispiel #4
0
 def main(n):
     codes = [CodeObj("main"), CodeObj("not main")]
     for code in codes:
         register_code(code, get_name)
     try:
         f(codes, codes[0], n, 8)
     except MyExc as e:
         return e.c
Beispiel #5
0
 def __init__(self, constants, functions, sources, path):
     self.constants = constants
     self.functions = functions
     self.sources = sources
     self.path = path
     for function in functions:
         function.unit = self
         rvmprof.register_code(function, get_function_name)
Beispiel #6
0
 def main(self, code, count):
     code = self.MyCode('py:main:3:main')
     rvmprof.register_code(code, self.MyCode.get_name)
     code = self.MyCode('py:code:7:native_func')
     rvmprof.register_code(code, self.MyCode.get_name)
     if count > 0:
         return self.main(code, count - 1)
     else:
         return self.native_func(100)
Beispiel #7
0
 def f():
     code = MyCode()
     rvmprof.register_code(code, get_name)
     fd = os.open(tmpfilename, os.O_WRONLY | os.O_CREAT, 0666)
     rvmprof.enable(fd, 0.5)
     res = main(code, 5)
     assert res == 42
     rvmprof.disable()
     os.close(fd)
     return 0
Beispiel #8
0
 def f():
     code = MyCode()
     rvmprof.register_code(code, get_name)
     fd = os.open(tmpfilename, os.O_WRONLY | os.O_CREAT, 0666)
     rvmprof.enable(fd, 0.5)
     res = main(code, 5)
     assert res == 42
     rvmprof.disable()
     os.close(fd)
     return 0
Beispiel #9
0
 def f(num):
     rthread.get_ident() # register TLOFS_thread_ident
     code = MyCode("py:x:foo:3")
     rvmprof.register_code(code, get_name)
     fd = os.open(tmpfilename, os.O_WRONLY | os.O_CREAT, 0666)
     period = 0.0001
     rvmprof.enable(fd, period)
     res = main(code, num)
     #assert res == 499999500000
     rvmprof.disable()
     os.close(fd)
     return 0
Beispiel #10
0
 def entry_point(self, value, delta_t):
     code = self.MyCode('py:code:52:test_enable')
     rvmprof.register_code(code, self.MyCode.get_name)
     fd = os.open(self.tmpfilename, os.O_WRONLY | os.O_CREAT, 0666)
     rvmprof.enable(fd, self.SAMPLING_INTERVAL)
     start = time.time()
     res = 0
     while time.time() < start + delta_t:
         res = self.main(code, value)
     rvmprof.disable()
     os.close(fd)
     return res
Beispiel #11
0
 def f(num):
     rthread.get_ident()  # register TLOFS_thread_ident
     code = MyCode("py:x:foo:3")
     rvmprof.register_code(code, get_name)
     fd = os.open(tmpfilename, os.O_WRONLY | os.O_CREAT, 0666)
     period = 0.0001
     rvmprof.enable(fd, period)
     res = main(code, num)
     #assert res == 499999500000
     rvmprof.disable()
     os.close(fd)
     return 0
Beispiel #12
0
 def f():
     if NonConstant(False):
         # Hack to give os.open() the correct annotation
         os.open('foo', 1, 1)
     code = MyCode()
     rvmprof.register_code(code, get_name)
     fd = os.open(tmpfilename, os.O_RDWR | os.O_CREAT, 0666)
     num = 10000
     period = 0.0001
     rvmprof.enable(fd, period, native=1)
     for i in range(num):
         res = main(code, 3)
     rvmprof.disable()
     os.close(fd)
     return 0
 def f():
     code = MyCode()
     rvmprof.register_code(code, get_name)
     fd = os.open(tmpfilename, os.O_WRONLY | os.O_CREAT, 0666)
     if we_are_translated():
         num = 100000000
         period = 0.0001
     else:
         num = 10000
         period = 0.9
     rvmprof.enable(fd, period)
     res = main(code, num)
     #assert res == 499999500000
     rvmprof.disable()
     os.close(fd)
     return 0
Beispiel #14
0
    def test_vmprof(self):
        from rpython.rlib import rvmprof

        class MyCode:
            _vmprof_unique_id = 0
            def __init__(self, name):
                self.name = name

        def get_name(code):
            return code.name

        code2 = MyCode("py:y:foo:4")
        rvmprof.register_code(code2, get_name)

        try:
            rvmprof.register_code_object_class(MyCode, get_name)
        except rvmprof.VMProfPlatformUnsupported, e:
            py.test.skip(str(e))
Beispiel #15
0
 def f():
     if NonConstant(False):
         # Hack to give os.open() the correct annotation
         os.open('foo', 1, 1)
     code = MyCode()
     rvmprof.register_code(code, get_name)
     fd = os.open(tmpfilename, os.O_WRONLY | os.O_CREAT, 0666)
     if we_are_translated():
         num = 100000000
         period = 0.0001
     else:
         num = 10000
         period = 0.9
     rvmprof.enable(fd, period)
     res = main(code, num)
     #assert res == 499999500000
     rvmprof.disable()
     os.close(fd)
     return 0
Beispiel #16
0
 def f():
     if NonConstant(False):
         # Hack to give os.open() the correct annotation
         os.open('foo', 1, 1)
     code = MyCode()
     rvmprof.register_code(code, get_name)
     fd = os.open(tmpfilename, os.O_WRONLY | os.O_CREAT, 0666)
     if we_are_translated():
         num = 100000000
         period = 0.0001
     else:
         num = 10000
         period = 0.9
     rvmprof.enable(fd, period)
     res = main(code, num)
     #assert res == 499999500000
     rvmprof.disable()
     os.close(fd)
     return 0
Beispiel #17
0
    def test_vmprof(self):
        from rpython.rlib import rvmprof

        class MyCode:
            _vmprof_unique_id = 0
            _vmprof_weak_list = RWeakListMixin()
            _vmprof_weak_list.initialize()

            def __init__(self, name):
                self.name = name

        def get_name(code):
            return code.name

        code2 = MyCode("py:y:foo:4")
        rvmprof.register_code(code2, get_name)

        try:
            rvmprof.register_code_object_class(MyCode, get_name)
        except rvmprof.VMProfPlatformUnsupported, e:
            py.test.skip(str(e))
Beispiel #18
0
def _init_ready(pycode):
    rvmprof.register_code(pycode, _get_full_name)
Beispiel #19
0
    def test_vmprof(self):
        from rpython.rlib import rvmprof

        class MyCode:
            _vmprof_unique_id = 0
            _vmprof_weak_list = RWeakListMixin()
            _vmprof_weak_list.initialize()

            def __init__(self, name):
                self.name = name

        def get_name(code):
            return code.name

        code2 = MyCode("py:y:foo:4")
        rvmprof.register_code(code2, get_name)

        try:
            rvmprof.register_code_object_class(MyCode, get_name)
        except rvmprof.VMProfPlatformUnsupported as e:
            py.test.skip(str(e))

        def get_unique_id(code):
            return rvmprof.get_unique_id(code)

        driver = JitDriver(greens=['code'],
                           reds=['i', 's', 'num'],
                           is_recursive=True,
                           get_unique_id=get_unique_id)

        @rvmprof.vmprof_execute_code("xcode13", lambda code, num: code)
        def main(code, num):
            return main_jitted(code, num)

        def main_jitted(code, num):
            s = 0
            i = 0
            while i < num:
                driver.jit_merge_point(code=code, i=i, s=s, num=num)
                s += (i << 1)
                if i % 3 == 0 and code is not code2:
                    main(code2, 100)
                i += 1
            return s

        tmpfilename = str(udir.join('test_rvmprof'))

        def f(num):
            rthread.get_ident()  # register TLOFS_thread_ident
            code = MyCode("py:x:foo:3")
            rvmprof.register_code(code, get_name)
            fd = os.open(tmpfilename, os.O_WRONLY | os.O_CREAT, 0666)
            period = 0.0001
            rvmprof.enable(fd, period)
            res = main(code, num)
            #assert res == 499999500000
            rvmprof.disable()
            os.close(fd)
            return 0

        def check_vmprof_output():
            from vmprof import read_profile
            tmpfile = str(udir.join('test_rvmprof'))
            stats = read_profile(tmpfile)
            t = stats.get_tree()
            assert t.name == 'py:x:foo:3'
            assert len(t.children) == 1  # jit

        self.meta_interp(f, [1000000], inline=True)
        try:
            import vmprof
        except ImportError:
            pass
        else:
            check_vmprof_output()
Beispiel #20
0
 def switch():
     rvmprof.register_code(codeObj, lambda obj: obj.fullName)
Beispiel #21
0
 def _my_post_init(self):
     from rpython.rlib import rvmprof
     rvmprof.register_code(self, _get_full_name)
Beispiel #22
0
 def _my_post_init(self):
     rvmprof.register_code(self, _get_full_name)
Beispiel #23
0
 def f(argv):
     code1 = MyCode()
     rvmprof.register_code(code1, "foo")
     mainloop(code1, 2)
     return 0
Beispiel #24
0
 def __init__(self, count):
     self.count = count
     rvmprof.register_code(self, MyCode.get_name)
Beispiel #25
0
 def f():
     code = MyCode()
     rvmprof.register_code(code, lambda code: 'some code')
     res = main(code, 5)
     assert res == 42
     return 0
Beispiel #26
0
 def __init__(self, count):
     self.count = count
     rvmprof.register_code(self, MyCode.get_name)
Beispiel #27
0
 def _my_post_init(self):
     rvmprof.register_code(self, _get_full_name)
Beispiel #28
0
 def f(argv):
     jit.set_param(jitdriver, "inlining", 0)
     code1 = MyCode()
     rvmprof.register_code(code1, "foo")
     mainloop(code1, 2, 0)
     return 0
Beispiel #29
0
 def main(n):
     codes = [CodeObj("main"), CodeObj("not main")]
     for code in codes:
         register_code(code, get_name)
     return f(codes, codes[0], n, 8)
Beispiel #30
0
 def entry_point(self):
     code = self.MyCode()
     rvmprof.register_code(code, lambda code: 'some code')
     res = self.main(code, 5)
     assert res == 42
     return 0
Beispiel #31
0
 def main(n):
     codes = [CodeObj("main"), CodeObj("not main")]
     for code in codes:
         register_code(code, get_name)
     return f(codes, codes[0], n, 8)
Beispiel #32
0
    def test_vmprof(self):
        from rpython.rlib import rvmprof

        class MyCode:
            _vmprof_unique_id = 0
            _vmprof_weak_list = RWeakListMixin() ; _vmprof_weak_list.initialize()
            def __init__(self, name):
                self.name = name

        def get_name(code):
            return code.name

        code2 = MyCode("py:y:foo:4")
        rvmprof.register_code(code2, get_name)

        try:
            rvmprof.register_code_object_class(MyCode, get_name)
        except rvmprof.VMProfPlatformUnsupported as e:
            py.test.skip(str(e))

        def get_unique_id(code):
            return rvmprof.get_unique_id(code)

        driver = JitDriver(greens = ['code'], reds = ['i', 's', 'num'],
            is_recursive=True, get_unique_id=get_unique_id)

        @rvmprof.vmprof_execute_code("xcode13", lambda code, num: code)
        def main(code, num):
            return main_jitted(code, num)

        def main_jitted(code, num):
            s = 0
            i = 0
            while i < num:
                driver.jit_merge_point(code=code, i=i, s=s, num=num)
                s += (i << 1)
                if i % 3 == 0 and code is not code2:
                    main(code2, 100)
                i += 1
            return s

        tmpfilename = str(udir.join('test_rvmprof'))

        def f(num):
            rthread.get_ident() # register TLOFS_thread_ident
            code = MyCode("py:x:foo:3")
            rvmprof.register_code(code, get_name)
            fd = os.open(tmpfilename, os.O_WRONLY | os.O_CREAT, 0666)
            period = 0.0001
            rvmprof.enable(fd, period)
            res = main(code, num)
            #assert res == 499999500000
            rvmprof.disable()
            os.close(fd)
            return 0
        
        def check_vmprof_output():
            from vmprof import read_profile
            tmpfile = str(udir.join('test_rvmprof'))
            stats = read_profile(tmpfile)
            t = stats.get_tree()
            assert t.name == 'py:x:foo:3'
            assert len(t.children) == 1 # jit

        self.meta_interp(f, [1000000], inline=True)
        try:
            import vmprof
        except ImportError:
            pass
        else:
            check_vmprof_output()
Beispiel #33
0
 def switch():
     rvmprof.register_code(codeObj, lambda obj: obj.fullName)
Beispiel #34
0
def _init_ready(pycode):
    rvmprof.register_code(pycode, _get_full_name)
Beispiel #35
0
 def f(argv):
     code1 = MyCode()
     rvmprof.register_code(code1, "foo")
     mainloop(code1, 2)
     return 0
Beispiel #36
0
 def f():
     code = MyCode()
     rvmprof.register_code(code, lambda code: 'some code')
     res = main(code, 5)
     assert res == 42
     return 0
Beispiel #37
0
 def f(argv):
     jit.set_param(jitdriver, "inlining", 0)
     code1 = MyCode()
     rvmprof.register_code(code1, "foo")
     mainloop(code1, 2, 0)
     return 0