Source

pypy / pypy / jit / metainterp / test / test_jitprof.py

Full commit
Maciej Fijalkows… f0a41ee 

Maciej Fijalkows… 89681dd 
Maciej Fijalkows… f38e5da 
Maciej Fijalkows… f0a41ee 
Maciej Fijalkows… 89681dd 
Maciej Fijalkows… f0a41ee 
Maciej Fijalkows… d0add28 
Amaury Forgeot d… 0bf8e32 
Armin Rigo c43469d 
Amaury Forgeot d… 0bf8e32 
Armin Rigo c43469d 
Armin Rigo 40312ab 
Maciej Fijalkows… d0add28 




Armin Rigo c43469d 






Maciej Fijalkows… d0add28 
Maciej Fijalkows… f0a41ee 


Armin Rigo a31b5d1 
Maciej Fijalkows… f0a41ee 















Armin Rigo a31b5d1 
Maciej Fijalkows… f0a41ee 
Maciej Fijalkows… 89681dd 



Maciej Fijalkows… f0a41ee 
Armin Rigo c43469d 
Armin Rigo 11ca118 

Hakan Ardo aff240c 
Samuele Pedroni 6af90f8 

















Armin Rigo a31b5d1 
Armin Rigo 203b62f 
Samuele Pedroni 6af90f8 
Samuele Pedroni d5b8c09 
Carl Friedrich B… 382f399 
Samuele Pedroni d5b8c09 









Armin Rigo bafb1dc 
Samuele Pedroni d5b8c09 


Armin Rigo bafb1dc 
Armin Rigo a31b5d1 
Armin Rigo 203b62f 

from pypy.jit.metainterp.warmspot import ll_meta_interp
from pypy.rlib.jit import JitDriver, dont_look_inside, elidable, Counters
from pypy.jit.metainterp.test.support import LLJitMixin
from pypy.jit.metainterp import pyjitpl
from pypy.jit.metainterp.jitprof import Profiler

class FakeProfiler(Profiler):
    def start(self):
        self.counter = 123456
        Profiler.start(self)
        self.events = []
        self.times = [0, 0]
    
    def timer(self):
        self.counter += 1
        return self.counter - 1

    def _start(self, event):
        Profiler._start(self, event)
        self.events.append(event)

    def _end(self, event):
        Profiler._end(self, event)
        self.events.append(~event)

class ProfilerMixin(LLJitMixin):
    def meta_interp(self, *args, **kwds):
        kwds = kwds.copy()
        kwds['ProfilerClass'] = FakeProfiler
        return LLJitMixin.meta_interp(self, *args, **kwds)

class TestProfile(ProfilerMixin):

    def test_simple_loop(self):
        myjitdriver = JitDriver(greens = [], reds = ['x', 'y', 'res'])
        def f(x, y):
            res = 0
            while y > 0:
                myjitdriver.can_enter_jit(x=x, y=y, res=res)
                myjitdriver.jit_merge_point(x=x, y=y, res=res)
                res += x
                y -= 1
            return res * 2
        res = self.meta_interp(f, [6, 7])
        assert res == 84
        profiler = pyjitpl._warmrunnerdesc.metainterp_sd.profiler
        expected = [
            Counters.TRACING,
            Counters.BACKEND,
            ~ Counters.BACKEND,
            ~ Counters.TRACING,
            ]
        assert profiler.events == expected
        assert profiler.times == [2, 1]
        assert profiler.counters == [1, 1, 3, 3, 1, 15, 2, 0, 0, 0, 0,
                                     0, 0, 0, 0, 0]

    def test_simple_loop_with_call(self):
        @dont_look_inside
        def g(n):
            pass
        
        myjitdriver = JitDriver(greens = [], reds = ['x', 'y', 'res'])
        def f(x, y):
            res = 0
            while y > 0:
                myjitdriver.can_enter_jit(x=x, y=y, res=res)
                myjitdriver.jit_merge_point(x=x, y=y, res=res)
                res += x
                g(x)
                y -= 1
            return res * 2
        res = self.meta_interp(f, [6, 7])
        assert res == 84
        profiler = pyjitpl._warmrunnerdesc.metainterp_sd.profiler
        assert profiler.calls == 1

    def test_blackhole_pure(self):
        @elidable
        def g(n):
            return n+1
        
        myjitdriver = JitDriver(greens = ['z'], reds = ['y', 'x','res'])
        def f(x, y, z):
            res = 0
            while y > 0:
                myjitdriver.can_enter_jit(x=x, y=y, res=res, z=z)
                myjitdriver.jit_merge_point(x=x, y=y, res=res, z=z)
                res += x
                res += g(z)
                y -= 1
            return res * 2
        res = self.meta_interp(f, [6, 7, 2])
        assert res == f(6, 7, 2)
        profiler = pyjitpl._warmrunnerdesc.metainterp_sd.profiler
        assert profiler.calls == 1