Author: Diana Popa <diana.p...@intel.com> Branch: new-jit-log Changeset: r83588:4945fd3dc5ba Date: 2016-04-08 15:43 +0300 http://bitbucket.org/pypy/pypy/changeset/4945fd3dc5ba/
Log: (diana, richard) added tests for jitlog to encode debug_merge_point and also the implementation diff --git a/rpython/jit/metainterp/jitlog.py b/rpython/jit/metainterp/jitlog.py --- a/rpython/jit/metainterp/jitlog.py +++ b/rpython/jit/metainterp/jitlog.py @@ -1,5 +1,6 @@ from rpython.rlib.rvmprof.rvmprof import cintf from rpython.jit.metainterp import resoperation as resoperations +from rpython.jit.metainterp.resoperation import rop from rpython.jit.metainterp.history import ConstInt, ConstFloat from rpython.rlib.objectmodel import we_are_translated from rpython.rtyper.lltypesystem import lltype, llmemory, rffi @@ -30,6 +31,7 @@ MARK_JIT_ENTRY_COUNTER = 0x22 MARK_JITLOG_HEADER = 0x23 +MARK_JITLOG_DEBUG_MERGE_POINT = 0x24 IS_32_BIT = sys.maxint == 2**31-1 @@ -179,12 +181,26 @@ le_addr2 = encode_le_addr(absaddr + rel) log._write_marked(MARK_ASM_ADDR, le_addr1 + le_addr2) for i,op in enumerate(ops): + if rop.DEBUG_MERGE_POINT == op.getopnum(): + self.encode_debug_info(op) + continue mark, line = self.encode_op(op) log._write_marked(mark, line) self.write_core_dump(ops, i, op, ops_offset) self.memo = {} + def encode_debug_info(self, op): + log = self.logger + jd_sd = self.metainterp_sd.jitdrivers_sd[op.getarg(0).getint()] + file_name, bytecode, line_number = jd_sd.warmstate.get_location_str(op.getarg(2)) + line = [] + line.append(encode_str(file_name)) + line.append(encode_str(bytecode)) + line.append(encode_str(line_number)) + log._write_marked(MARK_JITLOG_DEBUG_MERGE_POINT, ''.join(line)) + + def encode_op(self, op): """ an operation is written as follows: <marker> <opid (16 bit)> \ diff --git a/rpython/jit/metainterp/test/test_jitlog.py b/rpython/jit/metainterp/test/test_jitlog.py new file mode 100644 --- /dev/null +++ b/rpython/jit/metainterp/test/test_jitlog.py @@ -0,0 +1,44 @@ +from rpython.jit.tool.oparser import pure_parse +from rpython.jit.metainterp import jitlog +from rpython.jit.metainterp.optimizeopt.util import equaloplists +from rpython.jit.metainterp.resoperation import ResOperation, rop +from rpython.jit.backend.model import AbstractCPU +from rpython.jit.metainterp.history import ConstInt, ConstPtr +import tempfile + +class TestLogger(object): + + def make_metainterp_sd(self): + class FakeJitDriver(object): + class warmstate(object): + @staticmethod + def get_location_str(ptr): + if ptr.value == 0: + return ['string', '', ''] + + class FakeMetaInterpSd: + cpu = AbstractCPU() + cpu.ts = None + jitdrivers_sd = [FakeJitDriver()] + def get_name_from_address(self, addr): + return 'Name' + return FakeMetaInterpSd() + + def test_debug_merge_point(self, tmpdir): + logger = jitlog.VMProfJitLogger() + file = tmpdir.join('binary_file') + file.ensure() + fd = file.open('wb') + logger.cintf.jitlog_init(fd.fileno()) + log_trace = logger.log_trace(0, self.make_metainterp_sd(), None) + op = ResOperation(rop.DEBUG_MERGE_POINT, [ConstInt(0), ConstInt(0), ConstInt(0)]) + log_trace.write([], [op]) + #the next line will close 'fd' + fd.close() + logger.finish() + binary = file.read() + assert binary.startswith(b'\x00\x04\x00\x00\x00loop') + assert binary.endswith(b'\x24\x06\x00\x00\x00string\x00\x00\x00\x00\x00\x00\x00\x00') + + + _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit