示例#1
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
示例#2
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)
     #
     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
示例#3
0
 def run(self,
         func_or_src,
         args=[],
         import_site=False,
         discard_stdout_before_last_line=False,
         **jitopts):
     jitopts.setdefault('threshold', 200)
     jitopts.setdefault('disable_unrolling', 9999)
     if self.pypy_c is None:
         py.test.skip("run with --pypy=PATH")
     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 = [self.pypy_c]
     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()
     # TODO old logging system
     env['PYPYLOG'] = self.log_string + ':' + str(logfile)
     jitlogfile = str(logfile) + '.jlog'
     env['JITLOG'] = str(jitlogfile)
     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 not stdout:
         raise Exception("no stdout produced; stderr='''\n%s'''" %
                         (stderr, ))
     if stderr:
         print '*** stderr of the subprocess: ***'
         print stderr
     #
     if discard_stdout_before_last_line:
         stdout = stdout.splitlines(True)[-1]
     #
     # parse the JIT log
     rawlog = logparser.parse_log_file(str(logfile), verbose=False)
     rawtraces = logparser.extract_category(rawlog, 'jit-log-opt-')
     log = Log(rawtraces)
     log.result = eval(stdout)
     log.logfile = str(logfile)
     log.jitlogfile = jitlogfile
     #
     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