[pypy-svn] r64904 - in pypy/branch/pyjitpl5/pypy/jit/metainterp: . test
fijal at codespeak.net
fijal at codespeak.net
Fri May 1 02:49:43 CEST 2009
Author: fijal
Date: Fri May 1 02:49:36 2009
New Revision: 64904
Added:
pypy/branch/pyjitpl5/pypy/jit/metainterp/jitprof.py (contents, props changed)
pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_jitprof.py (contents, props changed)
Modified:
pypy/branch/pyjitpl5/pypy/jit/metainterp/history.py
pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py
pypy/branch/pyjitpl5/pypy/jit/metainterp/warmspot.py
Log:
add a rudimentary profiler support
Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/history.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/history.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/history.py Fri May 1 02:49:36 2009
@@ -588,6 +588,7 @@
raise NotImplementedError
class History(RunningMatcher):
+
extratext = ''
def record(self, opnum, argboxes, resbox, descr=None):
op = ResOperation(opnum, argboxes, resbox, descr)
@@ -697,6 +698,7 @@
_about_ = check_descr
def compute_result_annotation(self, s_x):
+ return
from pypy.annotation import model as annmodel
if not annmodel.s_None.contains(s_x):
assert isinstance(s_x, annmodel.SomeInstance)
Added: pypy/branch/pyjitpl5/pypy/jit/metainterp/jitprof.py
==============================================================================
--- (empty file)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/jitprof.py Fri May 1 02:49:36 2009
@@ -0,0 +1,80 @@
+
+""" A small helper module for profiling JIT
+"""
+
+import time
+
+TRACING = 0
+RUNNING = 1
+BLACKHOLE = 2
+END_TRACING = 4
+END_RUNNING = 5
+END_BLACKHOLE = 6
+
+class EmptyProfiler(object):
+ initialized = False
+
+ def start(self):
+ pass
+
+ def finish(self):
+ pass
+
+ def start_normal(self, greenkey=None):
+ pass
+
+ def end_normal(self):
+ pass
+
+ def start_tracing(self, greenkey=None):
+ pass
+
+ def end_tracing(self):
+ pass
+
+ def start_running(self, greenkey=None):
+ pass
+
+ def end_running(self):
+ pass
+
+ def start_blackhole(self, greenkey=None):
+ pass
+
+ def end_blackhole(self):
+ pass
+
+class Profiler(object):
+ initialized = False
+
+ def start(self):
+ self.t0 = time.clock()
+ self.events = []
+
+ def finish(self):
+ self.tk = time.clock()
+ self.print_stats()
+
+ def start_tracing(self, greenkey=None):
+ self.events.append((time.clock(), TRACING))
+
+ def end_tracing(self):
+ self.events.append((time.clock(), END_TRACING))
+
+ def start_running(self, greenkey=None):
+ self.events.append((time.clock(), RUNNING))
+
+ def end_running(self):
+ self.events.append((time.clock(), END_RUNNING))
+
+ def start_blackhole(self, greenkey=None):
+ self.events.append((time.clock(), BLACKHOLE))
+
+ def end_blackhole(self):
+ self.events.append((time.clock(), END_BLACKHOLE))
+
+ def print_stats(self):
+ print "Total: %f" % (self.tk - self.t0)
+ #for t, ev in self.events:
+ # if ev == END_TRACING
+
Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py Fri May 1 02:49:36 2009
@@ -18,6 +18,7 @@
from pypy.jit.metainterp import typesystem
from pypy.rlib.rarithmetic import intmask
from pypy.rlib.objectmodel import specialize
+from pypy.jit.metainterp.jitprof import Profiler, EmptyProfiler
# ____________________________________________________________
@@ -829,7 +830,7 @@
num_green_args = 0
def __init__(self, portal_graph, graphs, cpu, stats, options,
- optimizer=None):
+ optimizer=None, profile=False):
self.portal_graph = portal_graph
self.cpu = cpu
self.stats = stats
@@ -861,6 +862,11 @@
else:
self.ts = typesystem.llhelper
+ if profile:
+ self.profiler = Profiler()
+ else:
+ self.profiler = EmptyProfiler()
+
def _freeze_(self):
return True
@@ -1014,6 +1020,8 @@
while True:
self.framestack[-1].run_one_step()
finally:
+ if isinstance(self.history, history.BlackHole):
+ self.staticdata.profiler.end_blackhole()
if not we_are_translated():
history.log.event('LEAVE' + self.history.extratext)
elif DEBUG:
@@ -1266,6 +1274,7 @@
self.history.operations.append(suboperations[i])
self.extra_rebuild_operations = extra
if not must_compile:
+ self.staticdata.profiler.start_blackhole()
self.history = history.BlackHole(self.cpu)
# the BlackHole is invalid because it doesn't start with
# guard_failure.key.guard_op.suboperations, but that's fine
Added: pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_jitprof.py
==============================================================================
--- (empty file)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_jitprof.py Fri May 1 02:49:36 2009
@@ -0,0 +1,39 @@
+
+from pypy.jit.metainterp.warmspot import ll_meta_interp
+from pypy.rlib.jit import JitDriver
+from pypy.jit.metainterp.test.test_basic import LLJitMixin
+from pypy.jit.metainterp import pyjitpl
+from pypy.jit.metainterp.jitprof import *
+
+class ProfilerMixin(LLJitMixin):
+ def meta_interp(self, *args, **kwds):
+ kwds = kwds.copy()
+ kwds['profile'] = True
+ 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
+ assert len(profiler.events) == 6
+ expected = [
+ TRACING,
+ END_TRACING,
+ RUNNING,
+ END_RUNNING,
+ BLACKHOLE,
+ END_BLACKHOLE
+ ]
+ assert [i[1] for i in profiler.events] == expected
+
Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/warmspot.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/warmspot.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/warmspot.py Fri May 1 02:49:36 2009
@@ -141,7 +141,7 @@
def build_meta_interp(self, CPUClass=None, view="auto",
translate_support_code=False, optimizer=None,
- **kwds):
+ profile=False, **kwds):
assert CPUClass is not None
opt = pyjitpl.Options(**kwds)
self.stats = history.Stats()
@@ -170,7 +170,8 @@
self.jitdriver = block.operations[pos].args[1].value
self.metainterp_sd = MetaInterpStaticData(graph, graphs, cpu,
self.stats, opt,
- optimizer=optimizer)
+ optimizer=optimizer,
+ profile=profile)
def make_enter_function(self):
WarmEnterState = make_state_class(self)
@@ -555,6 +556,10 @@
# not too bad.
def maybe_compile_and_run(self, *args):
+ metainterp_sd = warmrunnerdesc.metainterp_sd
+ if not metainterp_sd.profiler.initialized:
+ metainterp_sd.profiler.start()
+ metainterp_sd.profiler.initialized = True
# get the greenargs and look for the cell corresponding to the hash
greenargs = args[:num_green_args]
argshash = self.getkeyhash(*greenargs)
@@ -568,9 +573,10 @@
self.cells[argshash] = Counter(n)
return
#interp.debug_trace("jit_compile", *greenargs)
- metainterp_sd = warmrunnerdesc.metainterp_sd
metainterp = MetaInterp(metainterp_sd)
+ metainterp_sd.profiler.start_tracing()
loop = metainterp.compile_and_run_once(*args)
+ metainterp_sd.profiler.end_tracing()
else:
# machine code was already compiled for these greenargs
# (or we have a hash collision)
@@ -588,7 +594,9 @@
# ---------- execute assembler ----------
while True: # until interrupted by an exception
metainterp_sd = warmrunnerdesc.metainterp_sd
+ metainterp_sd.profiler.start_running()
fail_op = metainterp_sd.cpu.execute_operations(loop)
+ metainterp_sd.profiler.end_running()
loop = fail_op.descr.handle_fail_op(metainterp_sd, fail_op)
maybe_compile_and_run._dont_inline_ = True
@@ -614,7 +622,10 @@
return None
metainterp_sd = warmrunnerdesc.metainterp_sd
metainterp = MetaInterp(metainterp_sd)
- return metainterp.compile_and_run_once(*args)
+ warmrunnerdesc.metainterp_sd.profiler.start_tracing()
+ res = metainterp.compile_and_run_once(*args)
+ warmrunnerdesc.metainterp_sd.profiler.end_tracing()
+ return res
handle_hash_collision._dont_inline_ = True
def getkeyhash(self, *greenargs):
More information about the Pypy-commit
mailing list