Author: Richard Plangger <planri...@gmail.com> Branch: new-jit-log Changeset: r85583:f669d0340e40 Date: 2016-07-06 18:37 +0200 http://bitbucket.org/pypy/pypy/changeset/f669d0340e40/
Log: using the the same trick as done in rlib/jithook to call flush_trace_counters on the assembler diff --git a/rpython/jit/backend/llsupport/assembler.py b/rpython/jit/backend/llsupport/assembler.py --- a/rpython/jit/backend/llsupport/assembler.py +++ b/rpython/jit/backend/llsupport/assembler.py @@ -10,11 +10,16 @@ debug_print) from rpython.rlib.rarithmetic import r_uint from rpython.rlib.objectmodel import specialize, compute_unique_id +from rpython.rlib.jitlog import _log_jit_counter from rpython.rtyper.annlowlevel import cast_instance_to_gcref, llhelper from rpython.rtyper.lltypesystem import rffi, lltype -from rpython.jit.metainterp.debug import (DEBUG_COUNTER, debug_sd, - flush_debug_counters) +DEBUG_COUNTER = lltype.Struct('DEBUG_COUNTER', + # 'b'ridge, 'l'abel or # 'e'ntry point + ('i', lltype.Signed), # first field, at offset 0 + ('type', lltype.Char), + ('number', lltype.Signed) +) class GuardToken(object): def __init__(self, cpu, gcmap, faildescr, failargs, fail_locs, @@ -69,6 +74,7 @@ self.memset_addr = 0 self.rtyper = cpu.rtyper self._debug = False + self.loop_run_counters = [] def stitch_bridge(self, faildescr, target): raise NotImplementedError @@ -333,7 +339,7 @@ self._call_assembler_patch_jmp(jmp_location) def get_loop_run_counters(self, index): - return debug_sd.loop_run_counters[index] + return self.loop_run_counters[index] @specialize.argtype(1) def _inject_debugging_code(self, looptoken, operations, tp, number): @@ -366,16 +372,19 @@ else: assert token struct.number = compute_unique_id(token) - debug_sd.loop_run_counters.append(struct) + # YYY very minor leak -- we need the counters to stay alive + # forever, just because we want to report them at the end + # of the process + self.loop_run_counters.append(struct) return struct def finish_once(self): if self._debug: # TODO remove the old logging system when jitlog is complete debug_start('jit-backend-counts') - length = len(debug_sd.loop_run_counters) + length = len(self.loop_run_counters) for i in range(length): - struct = debug_sd.loop_run_counters[i] + struct = self.loop_run_counters[i] if struct.type == 'l': prefix = 'TargetToken(%d)' % struct.number else: @@ -391,7 +400,20 @@ debug_print(prefix + ':' + str(struct.i)) debug_stop('jit-backend-counts') - flush_debug_counters() + self.flush_trace_counters() + + def flush_trace_counters(self): + # this is always called, the jitlog knows if it is enabled + length = len(self.loop_run_counters) + for i in range(length): + struct = self.loop_run_counters[i] + _log_jit_counter(struct) + # reset the counter, flush in a later point in time will + # add up the counters! + struct.i = 0 + # here would be the point to free some counters + # see YYY comment above! but first we should run this every once in a while + # not just when jitlog_disable is called @staticmethod @rgc.no_collect diff --git a/rpython/jit/metainterp/debug.py b/rpython/jit/metainterp/debug.py deleted file mode 100644 --- a/rpython/jit/metainterp/debug.py +++ /dev/null @@ -1,32 +0,0 @@ -from rpython.rtyper.lltypesystem import rffi, lltype -from rpython.rlib.jitlog import _log_jit_counter - -# YYY very minor leak -- we need the counters to stay alive -# forever, just because we want to report them at the end -# of the process - -class DebugStaticData(object): - def __init__(self): - self.loop_run_counters = [] - -debug_sd = DebugStaticData() - -DEBUG_COUNTER = lltype.Struct('DEBUG_COUNTER', - # 'b'ridge, 'l'abel or # 'e'ntry point - ('i', lltype.Signed), # first field, at offset 0 - ('type', lltype.Char), - ('number', lltype.Signed) -) - -def flush_debug_counters(): - # this is always called, the jitlog knows if it is enabled - length = len(debug_sd.loop_run_counters) - for i in range(length): - struct = debug_sd.loop_run_counters[i] - _log_jit_counter(struct) - # reset the counter, flush in a later point in time will - # add up the counters! - struct.i = 0 - # here would be the point to free some counters - # see YYY comment above! but first we should run this every once in a while - # not just when jitlog_disable is called diff --git a/rpython/jit/metainterp/test/test_ajit.py b/rpython/jit/metainterp/test/test_ajit.py --- a/rpython/jit/metainterp/test/test_ajit.py +++ b/rpython/jit/metainterp/test/test_ajit.py @@ -4,6 +4,7 @@ import weakref from rpython.rlib import rgc +from rpython.rlib.debug import debug_flush_trace_counts from rpython.jit.codewriter.policy import StopAtXPolicy from rpython.jit.metainterp import history from rpython.jit.metainterp.test.support import LLJitMixin, noConst @@ -64,6 +65,20 @@ res = self.interp_operations(f, [8, 98]) assert res == 110 + def test_flush_trace_count(self): + myjitdriver = JitDriver(greens = [], reds = ['i']) + def f(i): + while i > 0: + myjitdriver.can_enter_jit(i=i) + myjitdriver.jit_merge_point(i=i) + if i == 4: + debug_flush_trace_counts(None) + print("4") + i -= 1 + return i + res = self.meta_interp(f, [40]) + assert res == 0 + def test_loop_1(self): myjitdriver = JitDriver(greens = [], reds = ['x', 'y', 'res']) def f(x, y): diff --git a/rpython/jit/metainterp/warmspot.py b/rpython/jit/metainterp/warmspot.py --- a/rpython/jit/metainterp/warmspot.py +++ b/rpython/jit/metainterp/warmspot.py @@ -168,6 +168,7 @@ def find_jit_merge_points(graphs): results = _find_jit_marker(graphs, 'jit_merge_point') + import pdb; pdb.set_trace() if not results: raise Exception("no jit_merge_point found!") seen = set([graph for graph, block, pos in results]) diff --git a/rpython/rlib/jitlog.py b/rpython/rlib/jitlog.py --- a/rpython/rlib/jitlog.py +++ b/rpython/rlib/jitlog.py @@ -12,6 +12,14 @@ from rpython.rlib.objectmodel import compute_unique_id, always_inline from rpython.rlib.objectmodel import we_are_translated, specialize from rpython.rlib.unroll import unrolling_iterable +from rpython.rlib.jit_hooks import register_helper +from rpython.annotator import model as annmodel + +@register_helper(None) +def stats_flush_trace_counts(warmrunnerdesc): + print("hello") + warmrunnerdesc.metainterp_sd.cpu.assembler.flush_trace_counters() + return True def commonprefix(a,b): "Given a list of pathnames, returns the longest common leading component" diff --git a/rpython/rlib/rvmprof/rvmprof.py b/rpython/rlib/rvmprof/rvmprof.py --- a/rpython/rlib/rvmprof/rvmprof.py +++ b/rpython/rlib/rvmprof/rvmprof.py @@ -132,8 +132,8 @@ self.cintf.jitlog_write_marked(jl.MARK_JITLOG_HEADER + blob, len(blob) + 1) def disable_jitlog(self): - from rpython.jit.metainterp.debug import flush_debug_counters - flush_debug_counters() + from rpython.rlib import debug + stats_flush_trace_counts(None) self.cintf.jitlog_teardown() def disable(self): diff --git a/rpython/rtyper/lltypesystem/lloperation.py b/rpython/rtyper/lltypesystem/lloperation.py --- a/rpython/rtyper/lltypesystem/lloperation.py +++ b/rpython/rtyper/lltypesystem/lloperation.py @@ -541,17 +541,18 @@ 'threadlocalref_enum': LLOp(sideeffects=False), # enum all threadlocalrefs # __________ debugging __________ - 'debug_view': LLOp(), - 'debug_print': LLOp(canrun=True), - 'debug_start': LLOp(canrun=True), - 'debug_stop': LLOp(canrun=True), - 'have_debug_prints': LLOp(canrun=True), - 'have_debug_prints_for':LLOp(canrun=True), - 'debug_offset': LLOp(canrun=True), - 'debug_flush': LLOp(canrun=True), - 'debug_assert': LLOp(tryfold=True), - 'debug_fatalerror': LLOp(canrun=True), - 'debug_llinterpcall': LLOp(canraise=(Exception,)), + 'debug_flush_trace_counts': LLOp(), + 'debug_view': LLOp(), + 'debug_print': LLOp(canrun=True), + 'debug_start': LLOp(canrun=True), + 'debug_stop': LLOp(canrun=True), + 'have_debug_prints': LLOp(canrun=True), + 'have_debug_prints_for': LLOp(canrun=True), + 'debug_offset': LLOp(canrun=True), + 'debug_flush': LLOp(canrun=True), + 'debug_assert': LLOp(tryfold=True), + 'debug_fatalerror': LLOp(canrun=True), + 'debug_llinterpcall': LLOp(canraise=(Exception,)), # Python func call 'res=arg[0](*arg[1:])' # in backends, abort() or whatever is fine 'debug_start_traceback': LLOp(), diff --git a/rpython/rtyper/lltypesystem/opimpl.py b/rpython/rtyper/lltypesystem/opimpl.py --- a/rpython/rtyper/lltypesystem/opimpl.py +++ b/rpython/rtyper/lltypesystem/opimpl.py @@ -580,6 +580,9 @@ return hlstr(x) return x +def op_debug_flush_log(): + debug.debug_flush_log() + def op_debug_print(*args): debug.debug_print(*map(_normalize, args)) diff --git a/rpython/translator/c/test/test_standalone.py b/rpython/translator/c/test/test_standalone.py --- a/rpython/translator/c/test/test_standalone.py +++ b/rpython/translator/c/test/test_standalone.py @@ -6,6 +6,7 @@ from rpython.rlib.objectmodel import keepalive_until_here from rpython.rlib.rarithmetic import r_longlong from rpython.rlib.debug import ll_assert, have_debug_prints, debug_flush +from rpython.rlib.jitlog import stats_flush_trace_counts from rpython.rlib.debug import debug_print, debug_start, debug_stop from rpython.rlib.debug import debug_offset, have_debug_prints_for from rpython.rlib.entrypoint import entrypoint_highlevel, secondary_entrypoints @@ -17,6 +18,7 @@ from rpython.tool.udir import udir from rpython.translator import cdir from rpython.conftest import option +from rpython.rlib.jit import JitDriver def setup_module(module): if os.name == 'nt': _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit