Author: Richard Plangger <planri...@gmail.com> Branch: new-jit-log Changeset: r83614:68ab27b22964 Date: 2016-04-12 14:56 +0200 http://bitbucket.org/pypy/pypy/changeset/68ab27b22964/
Log: use tmpdir instead of tempfile, added a version to the jitlog diff --git a/rpython/jit/backend/x86/test/test_jitlog.py b/rpython/jit/backend/x86/test/test_jitlog.py --- a/rpython/jit/backend/x86/test/test_jitlog.py +++ b/rpython/jit/backend/x86/test/test_jitlog.py @@ -4,11 +4,13 @@ from rpython.jit.tool.oparser import pure_parse from rpython.jit.metainterp import logger from rpython.jit.metainterp.typesystem import llhelper +from rpython.jit.metainterp.jitlog import JITLOG_VERSION_16BIT_LE from StringIO import StringIO from rpython.jit.metainterp.optimizeopt.util import equaloplists from rpython.jit.metainterp.history import AbstractDescr, JitCellToken, BasicFailDescr, BasicFinalDescr from rpython.jit.backend.model import AbstractCPU from rpython.rlib.jit import JitDriver +from rpython.rlib.objectmodel import always_inline from rpython.jit.metainterp.test.support import LLJitMixin from rpython.jit.backend.x86.test.test_basic import Jit386Mixin from rpython.rlib.rvmprof import rvmprof @@ -16,42 +18,44 @@ class TestLogger(Jit386Mixin): - def test_explicit_enable(self): + def test_explicit_enable(self, tmpdir): vmprof = rvmprof.VMProf() - fileno, name = tempfile.mkstemp() - self.run_sample_loop(lambda: vmprof.enable_jitlog(fileno)) - assert os.path.exists(name) - with open(name, 'rb') as fd: + file = tmpdir.join('jitlog') + fileno = os.open(file.strpath, os.O_WRONLY | os.O_CREAT) + enable_jitlog = lambda: vmprof.enable_jitlog(fileno) + f = self.run_sample_loop(enable_jitlog) + self.meta_interp(f, [10, 0]) + + assert os.path.exists(file.strpath) + with file.open('rb') as f: # check the file header - assert fd.read(3) == '\x23\xfe\xaf' + assert f.read(3) == '\x23' + JITLOG_VERSION_16BIT_LE + assert len(f.read()) > 0 + + def test_env(self, monkeypatch, tmpdir): + file = tmpdir.join('jitlog') + monkeypatch.setenv("JITLOG", file.strpath) + f = self.run_sample_loop(None) + self.meta_interp(f, [10,0]) + assert os.path.exists(file.strpath) + with file.open('rb') as fd: + # check the file header + assert fd.read(3) == '\x23' + JITLOG_VERSION_16BIT_LE assert len(fd.read()) > 0 - print(name) - def test_env(self, monkeypatch): - fileno, name = tempfile.mkstemp() - monkeypatch.setenv("JITLOG", name) - self.run_sample_loop(None) - assert os.path.exists(name) - with open(name, 'rb') as fd: - # check the file header - assert fd.read(3) == '\x23\xfe\xaf' - assert len(fd.read()) > 0 - print(name) + def test_version(self): + pass - def run_sample_loop(self, func): - myjitdriver = JitDriver(greens = [], reds = ['x', 'y', 'res']) - def f(x, y): + def run_sample_loop(self, func, myjitdriver = None): + if not myjitdriver: + myjitdriver = JitDriver(greens = [], reds = 'auto') + def f(y, x): res = 0 if func: func() while y > 0: - myjitdriver.can_enter_jit(x=x, y=y, res=res) - myjitdriver.jit_merge_point(x=x, y=y, res=res) + myjitdriver.jit_merge_point() res += x - if res > 40: - res += 1 - res -= 2 - res += 1 y -= 1 return res - res = self.meta_interp(f, [6, 20]) + return f 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 @@ -7,6 +7,10 @@ from rpython.rlib.objectmodel import compute_unique_id, always_inline import sys import weakref +import struct + +JITLOG_VERSION = 1 +JITLOG_VERSION_16BIT_LE = struct.pack("<H", JITLOG_VERSION) MARK_INPUT_ARGS = 0x10 MARK_RESOP_META = 0x11 @@ -82,7 +86,7 @@ @staticmethod @always_inline def _write_header(cintf): - header = encode_le_16bit(0xaffe) + header = JITLOG_VERSION_16BIT_LE cintf.jitlog_write_marked(MARK_JITLOG_HEADER, header, len(header)) @@ -193,12 +197,8 @@ 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)) + info = jd_sd.warmstate.get_location_str(op.getarg(2)) + log._write_marked(MARK_JITLOG_DEBUG_MERGE_POINT, encode_str(info)) def encode_op(self, op): diff --git a/rpython/jit/metainterp/test/test_jitlog.py b/rpython/jit/metainterp/test/test_jitlog.py --- a/rpython/jit/metainterp/test/test_jitlog.py +++ b/rpython/jit/metainterp/test/test_jitlog.py @@ -14,7 +14,7 @@ @staticmethod def get_location_str(ptr): if ptr.value == 0: - return ['string', '', ''] + return 'string #3 BYTE_CODE' class FakeMetaInterpSd: cpu = AbstractCPU() _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit