Example #1
0
def test_parse():
    info = parse_prof(DATA)
    assert info.tracing_no == 1
    assert info.tracing_time == 0.006992
    assert info.backend_no == 1
    assert info.backend_time == 0.000525
    assert info.ops.total == 2
    assert info.heapcached_ops == 111
    assert info.recorded_ops.total == 6
    assert info.recorded_ops.calls == 3
    assert info.guards == 1
    assert info.opt_ops == 6
    assert info.opt_guards == 1
    assert info.forcings == 1
    assert info.abort.trace_too_long == 10
    assert info.abort.compiling == 11
    assert info.abort.vable_escape == 12
    assert info.abort.bad_loop == 135
    assert info.abort.force_quasiimmut == 3
    assert info.virtualizables_forced == 1123
    assert info.nvirtuals == 13
    assert info.nvholes == 14
    assert info.nvreused == 15
    assert info.vecopt_tried == 12
    assert info.vecopt_success == 4
Example #2
0
def test_really_run():
    """ This test checks whether output of jitprof did not change.
    It'll explode when someone touches jitprof.py
    """
    mydriver = JitDriver(reds = ['i', 'n'], greens = [])
    def f(n):
        i = 0
        while i < n:
            mydriver.can_enter_jit(i=i, n=n)
            mydriver.jit_merge_point(i=i, n=n)
            i += 1

    cap = py.io.StdCaptureFD()
    try:
        ll_meta_interp(f, [10], CPUClass=runner.LLGraphCPU,
                       ProfilerClass=Profiler)
    finally:
        out, err = cap.reset()

    log = parse_log(err.splitlines(True))
    err_sections = list(extract_category(log, 'jit-summary'))
    [err1] = err_sections    # there should be exactly one jit-summary
    assert err1.count("\n") == JITPROF_LINES
    info = parse_prof(err1)
    # assert did not crash
    # asserts below are a bit delicate, possibly they might be deleted
    assert info.tracing_no == 1
    assert info.backend_no == 1
    assert info.ops.total == 2
    assert info.recorded_ops.total == 2
    assert info.recorded_ops.calls == 0
    assert info.guards == 2
    assert info.opt_ops == 11
    assert info.opt_guards == 2
    assert info.forcings == 0
Example #3
0
def test_really_run():
    """ This test checks whether output of jitprof did not change.
    It'll explode when someone touches jitprof.py
    """
    mydriver = JitDriver(reds = ['i', 'n'], greens = [])
    def f(n):
        i = 0
        while i < n:
            mydriver.can_enter_jit(i=i, n=n)
            mydriver.jit_merge_point(i=i, n=n)
            i += 1

    cap = py.io.StdCaptureFD()
    try:
        ll_meta_interp(f, [10], CPUClass=runner.LLGraphCPU, type_system='lltype',
                       ProfilerClass=Profiler)
    finally:
        out, err = cap.reset()

    log = parse_log(err.splitlines(True))
    err_sections = list(extract_category(log, 'jit-summary'))
    [err1] = err_sections    # there should be exactly one jit-summary
    assert err1.count("\n") == JITPROF_LINES
    info = parse_prof(err1)
    # assert did not crash
    # asserts below are a bit delicate, possibly they might be deleted
    assert info.tracing_no == 1
    assert info.backend_no == 1
    assert info.ops.total == 2
    assert info.recorded_ops.total == 2
    assert info.recorded_ops.calls == 0
    assert info.guards == 2
    assert info.opt_ops == 13
    assert info.opt_guards == 2
    assert info.forcings == 0
Example #4
0
 def run(self, func_or_src, args=[], import_site=False, **jitopts):
     jitopts.setdefault('threshold', 200)
     src = py.code.Source(func_or_src)
     if isinstance(func_or_src, types.FunctionType):
         funcname = func_or_src.func_name
     else:
         funcname = 'main'
     # write the snippet
     arglist = ', '.join(map(repr, args))
     with self.filepath.open("w") as f:
         # we don't want to see the small bridges created
         # by the checkinterval reaching the limit
         f.write("import sys\n")
         f.write("sys.setcheckinterval(10000000)\n")
         f.write(str(src) + "\n")
         f.write("print %s(%s)\n" % (funcname, arglist))
     #
     # run a child pypy-c with logging enabled
     logfile = self.filepath.new(ext='.log')
     #
     cmdline = [sys.executable]
     if not import_site:
         cmdline.append('-S')
     if jitopts:
         jitcmdline = ['%s=%s' % (key, value)
                       for key, value in jitopts.items()]
         cmdline += ['--jit', ','.join(jitcmdline)]
     cmdline.append(str(self.filepath))
     #
     env = os.environ.copy()
     env['PYPYLOG'] = self.log_string + ':' + str(logfile)
     pipe = subprocess.Popen(cmdline,
                             env=env,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE)
     stdout, stderr = pipe.communicate()
     if getattr(pipe, 'returncode', 0) < 0:
         raise IOError("subprocess was killed by signal %d" % (
             pipe.returncode,))
     if stderr.startswith('SKIP:'):
         py.test.skip(stderr)
     if stderr.startswith('debug_alloc.h:'):   # lldebug builds
         stderr = ''
     assert not stderr
     #
     # parse the JIT log
     rawlog = logparser.parse_log_file(str(logfile))
     rawtraces = logparser.extract_category(rawlog, 'jit-log-opt-')
     log = Log(rawtraces)
     log.result = eval(stdout)
     log.logfile = str(logfile)
     #
     summaries  = logparser.extract_category(rawlog, 'jit-summary')
     if len(summaries) > 0:
         log.jit_summary = parse_prof(summaries[-1])
     else:
         log.jit_summary = None
     #
     return log
Example #5
0
 def run(self, src, call, **jitopts):
     jitopts.setdefault('threshold', 200)
     # write the snippet
     with self.filepath.open("w") as f:
         # we don't want to see the small bridges created
         # by the checkinterval reaching the limit
         f.write(str(src) + "\n")
     #
     # run a child pyrolog-c with logging enabled
     logfile = self.filepath.new(ext='.log')
     #
     cmdline = [strexecutable]
     cmdline.append(str(self.filepath))
     #
     print cmdline, logfile
     env = {'PYPYLOG': 'jit-log-opt,jit-summary:' + str(logfile)}
     #env={'PYPYLOG': ':' + str(logfile)}
     pipe = subprocess.Popen(cmdline,
                             env=env,
                             stdin=subprocess.PIPE,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE)
     pipe.stdin.write(call + "\n")
     stdout, stderr = pipe.communicate()
     if stderr.startswith('SKIP:'):
         py.test.skip(stderr)
     if stderr.startswith('debug_alloc.h:'):  # lldebug builds
         stderr = ''
     assert not stderr
     #
     # parse the JIT log
     rawlog = logparser.parse_log_file(str(logfile))
     rawtraces = logparser.extract_category(rawlog, 'jit-log-opt-')
     log = Log(rawtraces)
     log.result = stdout
     if "ParseError" in log.result or "ERROR" in log.result:
         assert 0, log.result
     #
     summaries = logparser.extract_category(rawlog, 'jit-summary')
     if len(summaries) > 0:
         log.jit_summary = parse_prof(summaries[-1])
     else:
         log.jit_summary = None
     #
     return log
Example #6
0
 def run(self, src, call, **jitopts):
     jitopts.setdefault('threshold', 200)
     # write the snippet
     with self.filepath.open("w") as f:
         # we don't want to see the small bridges created
         # by the checkinterval reaching the limit
         f.write(str(src) + "\n")
     #
     # run a child pyrolog-c with logging enabled
     logfile = self.filepath.new(ext='.log')
     #
     cmdline = [strexecutable]
     cmdline.append(str(self.filepath))
     #
     print cmdline, logfile
     env={'PYPYLOG': 'jit-log-opt,jit-summary:' + str(logfile)}
     #env={'PYPYLOG': ':' + str(logfile)}
     pipe = subprocess.Popen(cmdline,
                             env=env,
                             stdin=subprocess.PIPE,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE)
     pipe.stdin.write(call + "\n")
     stdout, stderr = pipe.communicate()
     if stderr.startswith('SKIP:'):
         py.test.skip(stderr)
     if stderr.startswith('debug_alloc.h:'):   # lldebug builds
         stderr = ''
     assert not stderr
     #
     # parse the JIT log
     rawlog = logparser.parse_log_file(str(logfile))
     rawtraces = logparser.extract_category(rawlog, 'jit-log-opt-')
     log = Log(rawtraces)
     log.result = stdout
     if "ParseError" in log.result or "ERROR" in log.result:
         assert 0, log.result
     #
     summaries  = logparser.extract_category(rawlog, 'jit-summary')
     if len(summaries) > 0:
         log.jit_summary = parse_prof(summaries[-1])
     else:
         log.jit_summary = None
     #
     return log
Example #7
0
def test_parse():
    info = parse_prof(DATA)
    assert info.tracing_no == 1
    assert info.tracing_time == 0.006992
    assert info.backend_no == 1
    assert info.backend_time == 0.000525
    assert info.ops.total == 2
    assert info.recorded_ops.total == 6
    assert info.recorded_ops.calls == 3
    assert info.guards == 1
    assert info.opt_ops == 6
    assert info.opt_guards == 1
    assert info.forcings == 1
    assert info.abort.trace_too_long == 10
    assert info.abort.compiling == 11
    assert info.abort.vable_escape == 12
    assert info.abort.bad_loop == 135
    assert info.abort.force_quasiimmut == 3
    assert info.nvirtuals == 13
    assert info.nvholes == 14
    assert info.nvreused == 15
Example #8
0
 def run(self,
         func_or_src,
         args=[],
         import_site=False,
         discard_stdout_before_last_line=False,
         **jitopts):
     jitopts.setdefault('threshold', 200)
     src = py.code.Source(func_or_src)
     if isinstance(func_or_src, types.FunctionType):
         funcname = func_or_src.func_name
     else:
         funcname = 'main'
     # write the snippet
     arglist = ', '.join(map(repr, args))
     with self.filepath.open("w") as f:
         # we don't want to see the small bridges created
         # by the checkinterval reaching the limit
         f.write("import sys\n")
         f.write("sys.setcheckinterval(10000000)\n")
         f.write(str(src) + "\n")
         f.write("print %s(%s)\n" % (funcname, arglist))
     #
     # run a child pypy-c with logging enabled
     logfile = self.filepath.new(ext='.log')
     #
     cmdline = [sys.executable]
     if not import_site:
         cmdline.append('-S')
     if jitopts:
         jitcmdline = [
             '%s=%s' % (key, value) for key, value in jitopts.items()
         ]
         cmdline += ['--jit', ','.join(jitcmdline)]
     cmdline.append(str(self.filepath))
     #
     env = os.environ.copy()
     env['PYPYLOG'] = self.log_string + ':' + str(logfile)
     pipe = subprocess.Popen(cmdline,
                             env=env,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE)
     stdout, stderr = pipe.communicate()
     if pipe.wait() < 0:
         raise IOError("subprocess was killed by signal %d" %
                       (pipe.returncode, ))
     if stderr.startswith('SKIP:'):
         py.test.skip(stderr)
     if stderr.startswith('debug_alloc.h:'):  # lldebug builds
         stderr = ''
     assert not stderr
     #
     if discard_stdout_before_last_line:
         stdout = stdout.splitlines(True)[-1]
     #
     # parse the JIT log
     rawlog = logparser.parse_log_file(str(logfile))
     rawtraces = logparser.extract_category(rawlog, 'jit-log-opt-')
     log = Log(rawtraces)
     log.result = eval(stdout)
     log.logfile = str(logfile)
     #
     summaries = logparser.extract_category(rawlog, 'jit-summary')
     if len(summaries) > 0:
         log.jit_summary = parse_prof(summaries[-1])
     else:
         log.jit_summary = None
     #
     return log