Author: Maciej Fijalkowski <[email protected]>
Branch: even-more-jit-hooks
Changeset: r55894:fa2ba5890af2
Date: 2012-07-03 16:36 +0200
http://bitbucket.org/pypy/pypy/changeset/fa2ba5890af2/
Log: progress on counters
diff --git a/pypy/jit/backend/llgraph/runner.py
b/pypy/jit/backend/llgraph/runner.py
--- a/pypy/jit/backend/llgraph/runner.py
+++ b/pypy/jit/backend/llgraph/runner.py
@@ -4,6 +4,7 @@
from pypy.rlib.unroll import unrolling_iterable
from pypy.rlib.objectmodel import we_are_translated
+from pypy.rlib.jit_hooks import LOOP_RUN_CONTAINER
from pypy.rpython.lltypesystem import lltype, llmemory, rclass
from pypy.rpython.ootypesystem import ootype
from pypy.rpython.llinterp import LLInterpreter
@@ -33,6 +34,10 @@
self.arg_types = arg_types
self.count_fields_if_immut = count_fields_if_immut
self.ffi_flags = ffi_flags
+ self._debug = False
+
+ def set_debug(self, v):
+ self._debug = True
def get_arg_types(self):
return self.arg_types
@@ -583,6 +588,9 @@
for x in args_f:
llimpl.do_call_pushfloat(x)
+ def get_all_loop_runs(self):
+ return lltype.malloc(LOOP_RUN_CONTAINER, 0)
+
def force(self, force_token):
token = llmemory.cast_int_to_adr(force_token)
frame = llimpl.get_forced_token_frame(token)
diff --git a/pypy/jit/backend/model.py b/pypy/jit/backend/model.py
--- a/pypy/jit/backend/model.py
+++ b/pypy/jit/backend/model.py
@@ -55,6 +55,20 @@
"""Called once by the front-end when the program stops."""
pass
+ def get_all_loop_runs(self):
+ """ Function that will return number of times all the loops were run.
+ Requires earlier setting of set_debug(True), otherwise you won't
+ get the information.
+
+ Returns an instance of LOOP_RUN_CONTAINER from rlib.jit_hooks
+ """
+ raise NotImplementedError
+
+ def set_debug(self, value):
+ """ Enable or disable debugging info. Does nothing by default
+ """
+ pass
+
def compile_loop(self, inputargs, operations, looptoken, log=True,
name=''):
"""Assemble the given loop.
Should create and attach a fresh CompiledLoopToken to
diff --git a/pypy/jit/backend/x86/assembler.py
b/pypy/jit/backend/x86/assembler.py
--- a/pypy/jit/backend/x86/assembler.py
+++ b/pypy/jit/backend/x86/assembler.py
@@ -750,7 +750,6 @@
@specialize.argtype(1)
def _inject_debugging_code(self, looptoken, operations, tp, number):
if self._debug:
- # before doing anything, let's increase a counter
s = 0
for op in operations:
s += op.getopnum()
diff --git a/pypy/jit/backend/x86/runner.py b/pypy/jit/backend/x86/runner.py
--- a/pypy/jit/backend/x86/runner.py
+++ b/pypy/jit/backend/x86/runner.py
@@ -3,6 +3,7 @@
from pypy.rpython.lltypesystem.lloperation import llop
from pypy.rpython.llinterp import LLInterpreter
from pypy.rlib.objectmodel import we_are_translated
+from pypy.rlib.jit_hooks import LOOP_RUN_CONTAINER
from pypy.jit.codewriter import longlong
from pypy.jit.metainterp import history, compile
from pypy.jit.backend.x86.assembler import Assembler386
@@ -181,6 +182,14 @@
# positions invalidated
looptoken.compiled_loop_token.invalidate_positions = []
+ def get_all_loop_runs(self):
+ l = lltype.malloc(LOOP_RUN_CONTAINER,
+ len(self.assembler.loop_run_counters))
+ for i, ll_s in enumerate(self.assembler.loop_run_counters):
+ l[i].type = ll_s.type
+ l[i].number = ll_s.number
+ l[i].counter = ll_s.i
+ return l
class CPU386(AbstractX86CPU):
backend_name = 'x86'
diff --git a/pypy/jit/metainterp/test/test_jitiface.py
b/pypy/jit/metainterp/test/test_jitiface.py
--- a/pypy/jit/metainterp/test/test_jitiface.py
+++ b/pypy/jit/metainterp/test/test_jitiface.py
@@ -7,7 +7,9 @@
from pypy.rpython.annlowlevel import hlstr
from pypy.jit.metainterp.jitprof import Profiler
-class TestJitHookInterface(LLJitMixin):
+class JitHookInterfaceTests(object):
+ # !!!note!!! - don't subclass this from the backend. Subclass the LL
+ # class later instead
def test_abort_quasi_immut(self):
reasons = []
@@ -169,6 +171,45 @@
Counters.TOTAL_COMPILED_BRIDGES) == 1
assert jit_hooks.stats_get_counter_value(stats,
Counters.TRACING) >= 0
-
self.meta_interp(main, [], ProfilerClass=Profiler)
+
+class LLJitHookInterfaceTests(JitHookInterfaceTests):
+ # use this for any backend, instead of the super class
+
+ def test_ll_get_stats(self):
+ driver = JitDriver(greens = [], reds = ['i', 's'])
+
+ def loop(i):
+ s = 0
+ while i > 0:
+ driver.jit_merge_point(i=i, s=s)
+ if i % 2:
+ s += 1
+ i -= 1
+ s+= 2
+ return s
+
+ def main():
+ loop(30)
+ stats = jit_hooks.get_stats()
+ l = jit_hooks.stats_get_loop_run_times(stats)
+ assert len(l) == 4
+ # completely specific test that would fail each time
+ # we change anything major. for now it's 4
+ # (loop, bridge, 2 entry points)
+ assert l[0].type == 'e'
+ assert l[0].number == 0
+ assert l[0].counter == 4
+ assert l[1].type == 'l'
+ assert l[1].counter == 4
+ assert l[2].type == 'l'
+ assert l[2].counter == 23
+ assert l[3].type == 'b'
+ assert l[3].number == 4
+ assert l[3].counter == 11
+ self.meta_interp(main, [], ProfilerClass=Profiler)
+
+
+class TestJitHookInterface(JitHookInterfaceTests, LLJitMixin):
+ pass
diff --git a/pypy/rlib/jit_hooks.py b/pypy/rlib/jit_hooks.py
--- a/pypy/rlib/jit_hooks.py
+++ b/pypy/rlib/jit_hooks.py
@@ -13,7 +13,9 @@
_about_ = helper
def compute_result_annotation(self, *args):
- return s_result
+ if isinstance(s_result, annmodel.SomeObject):
+ return s_result
+ return annmodel.lltype_to_annotation(s_result)
def specialize_call(self, hop):
from pypy.rpython.lltypesystem import lltype
@@ -132,3 +134,13 @@
@register_helper(annmodel.SomeFloat())
def stats_get_counter_value(llref, no):
return
_cast_to_warmrunnerdesc(llref).metainterp_sd.profiler.get_counter(no)
+
+LOOP_RUN_CONTAINER = lltype.GcArray(lltype.Struct('elem',
+ ('type', lltype.Char),
+ ('number', lltype.Signed),
+ ('counter', lltype.Signed)))
+
+@register_helper(lltype.Ptr(LOOP_RUN_CONTAINER))
+def stats_get_loop_run_times(llref):
+ warmrunnerdesc = _cast_to_warmrunnerdesc(llref)
+ return warmrunnerdesc.metainterp_sd.cpu.get_all_loop_runs()
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit