changeset 4150:c78bace5086a

start work on integrating old hooks into mx, work on sanity checks introduce a DB class to access the bench DB in an easier way (create benchmarks and benchmark values automatically in the DB)
author Gilles Duboscq <gilles.m.duboscq@gmail.com>
date Tue, 20 Dec 2011 15:34:43 +0100
parents cf4de9cc1268
children cb22fcb2e2fc
files mx/benchmarkdb.py mx/commands.py mx/sanitycheck.py mxtool/mx.py
diffstat 4 files changed, 141 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mx/benchmarkdb.py	Tue Dec 20 15:34:43 2011 +0100
@@ -0,0 +1,52 @@
+import sqlite3
+
+class BenchmarkDb:
+    def __init__(self, path):
+        self.con = sqlite3.connect(path)
+        c = self.con.cursor();
+        c.execute('pragma foreign_keys = on')
+        c.execute('create table if not exists results (revnum integer, foreign key(benchmarkid) references benchmarks(benchmarkid), foreign key(valueid) references benchmarkvalues(valueid), value real)')
+        c.execute('create table if not exists benchmarks (benchmarkid integer primary key autoincrement, name text)')
+        c.execute('create table if not exists benchmarkvalues (valueid integer primary key autoincrement, name text)')
+        self.con.commit()
+        c.close()
+
+    def insertResults(self, revision, results):
+        c = self.con.cursor()
+        for result in results:
+            if not result.has_key('benchmark'):
+                continue
+            benchmarkName = result['benchmark']
+            del result['benchmark']
+            if len(result.keys()) <= 0:
+                continue
+            
+            benchIdRow = c.execute('select benchmarkid from benchmarks where name="' + benchmarkName + '"').fetchone()
+            benchId = -1;
+            if benchIdRow is None:
+                c.execute('insert into benchmarks (name) values ("' + benchmarkName + '")  values ')
+                benchId = c.lastrowid()
+            else:
+                benchId = benchIdRow['benchmarkid']
+            
+            insertcmd = 'insert into results (revnum, benchmarkid, valueid, value) '
+            first = True
+            for valueName in result.keys():
+                valueIdRow = c.execute('select valueid from benchmarkvalues where name="' + valueName + '"').fetchone()
+                valueId = -1;
+                if valueIdRow is None:
+                    c.execute('insert into benchmarkvalues (name) values ("' + valueName + '")')
+                    valueId = c.lastrowid()
+                else:
+                    valueId = benchIdRow['valueid']
+                
+                if first:
+                    insertcmd = insertcmd + 'select ' + str(revision) + ' as revnum, ' + str(benchId) + ' as benchmarkid, ' + str(valueId) + ' as valueid, ' + result[valueName] + ' as value '
+                else:
+                    insertcmd = insertcmd + 'union select ' + str(revision) + ', ' + str(benchId) + ', ' + str(valueId) + ', ' + result[valueName] + ' '
+            c.execute(insertcmd)
+        self.con.commit()
+        c.close()
+        
+    def close(self):
+        self.con.close()
\ No newline at end of file
--- a/mx/commands.py	Tue Dec 20 10:36:44 2011 +0100
+++ b/mx/commands.py	Tue Dec 20 15:34:43 2011 +0100
@@ -29,6 +29,7 @@
 import os, sys, shutil, tarfile, StringIO
 from os.path import join, exists, dirname, isfile, isdir, isabs
 import mx
+import sanitycheck
 
 _graal_home = dirname(dirname(__file__))
 _vmbuild = 'product'
@@ -82,46 +83,29 @@
 
 def dacapo(args):
     """run one or all DaCapo benchmarks"""
-    
-    benchmarks = {
-        'avrora': ['-n', '5'],
-        'batik': ['-n', '5'],
-        'eclipse': ['-n', '5'],
-        'fop': ['-n', '5'],
-        'h2': ['-n', '5'],
-        'jython': ['-n', '5'],
-        'luindex': ['-n', '5'],
-        'lusearch': ['-n', '5'],
-        'pmd': ['-n', '5'],
-        'sunflow': ['-n', '5'],
-        'tomcat': ['-n', '5'],
-        'tradebeans': ['-n', '5'],
-        'tradesoap': ['-n', '5'],
-        'xalan': ['-n', '5'],
-    }
-    
-    dacapo = mx.check_get_env('DACAPO_CP')
-    if not isfile(dacapo) or not dacapo.endswith('.jar'):
-        mx.abort('Specified DaCapo jar file does not exist or is not a jar file: ' + dacapo)
-            
-    vmOpts = ['-Xms1g', '-Xmx2g', '-esa', '-cp', dacapo]
-
     runs = dict()    
     while len(args) != 0 and not args[0].startswith('-'):
         bm = args[0]
         del args[0]
-        config = benchmarks.get(bm) 
-        if (config is None):
-            mx.abort('unknown benchmark: ' + bm + '\nselect one of: ' + str(benchmarks.keys()))
-        runs[bm] = config
+        n = sanitycheck.dacapoSanityWarmup.get(bm)[sanitycheck.SanityCheckLevel.Normal]
+        if (n is None):
+            mx.abort('unknown benchmark: ' + bm + '\nselect one of: ' + str(sanitycheck.dacapoSanityWarmup.keys()))
+        runs[bm] = n
     
     if len(runs) == 0:
-        runs = benchmarks
-        
-    vmOpts += args
-    for bm in runs:
-        config = benchmarks.get(bm)
-        vm(vmOpts + ['Harness'] + config + [bm])
+        for (key, ns) in sanitycheck.dacapoSanityWarmup.items():
+            runs[key] = ns[sanitycheck.SanityCheckLevel.Normal] 
+
+    for (bench, n) in runs.items():
+        vm(args + sanitycheck.getDacapoCmd(bench, n=n))
+
+def sanitychecks(args):
+    """runs sanity checks"""
+    checks = sanitycheck.getSanityChecks(sanitycheck.SanityCheckLevel.Gate)
+    for check in checks:
+        if not sanitycheck.runSanityCheck(check['cmd'], check['success']):
+            mx.abort("Sanity checks FAILED")
+    mx.log("Sanity checks PASSED")
     
 def _jdk7(build='product', create=False):
     jdk7 = join(_graal_home, 'jdk1.7.0')
@@ -200,7 +184,7 @@
     os.environ.update(ARCH_DATA_MODEL='64', LANG='C', HOTSPOT_BUILD_JOBS='3', ALT_BOOTDIR=jdk7, INSTALL='y')
     mx.run([mx.gmake_cmd(), build + 'graal'], cwd=join(_graal_home, 'make'), err=filterXusage)
     
-def vm(args, vm='-graal'):
+def vm(args, vm='-graal', nonZeroIsFatal=True, out=None, err=None, cwd=None):
     """run the GraalVM"""
   
     build = _vmbuild
@@ -208,7 +192,7 @@
         args = ['-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000'] + args
     os.environ['GRAAL'] = join(_graal_home, 'graal')
     exe = join(_jdk7(build), 'bin', mx.exe_suffix('java'))
-    return mx.run([exe, vm] + args)
+    return mx.run([exe, vm] + args, nonZeroIsFatal=nonZeroIsFatal, out=out, err=err, cwd=cwd)
 
 def ideinit(args):
     """(re)generate Eclipse project configurations
@@ -373,6 +357,7 @@
         'clean': [clean, ''],
         'vm': [vm, '[-options] class [args...]'],
 	    'ideinit': [ideinit, ''],
+        'sanity' : [sanitychecks, ''],
     }
     mx.commands.update(commands)
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mx/sanitycheck.py	Tue Dec 20 15:34:43 2011 +0100
@@ -0,0 +1,67 @@
+from outputparser import OutputParser, Matcher
+import re
+import mx
+import os
+from os.path import isfile
+
+dacapoVMOpts = ['-Xms1g', '-Xmx2g']
+
+dacapoSanityWarmup = {
+    'avrora': [0, 0, 3, 6],
+    'batik': [0 , 0, 5, 5],
+    'eclipse': [1 , 4, 5, 10],
+    'fop': [4 , 8, 10, 20],
+    'h2': [0 , 0, 5, 5],
+    'jython': [0 , 0, 5, 10],
+    'luindex': [0 , 0, 5, 10],
+    'lusearch': [0 , 4, 5, 10],
+    'pmd': [0 , 0, 5, 10],
+    'sunflow': [0 , 0, 5, 10],
+    'tomcat': [0 , 0, 5, 10],
+    'tradebeans': [0 , 0, 5, 10],
+    'tradesoap': [0 , 4, 5, 10],
+    'xalan': [0 , 0, 5, 10],
+}
+
+def getDacapoCmd(bench, vmOpts=dacapoVMOpts,n=5):
+    dacapo = mx.check_get_env('DACAPO_CP')
+    if not isfile(dacapo) or not dacapo.endswith('.jar'):
+        mx.abort('Specified DaCapo jar file does not exist or is not a jar file: ' + dacapo)
+    return vmOpts + ['-cp', dacapo, 'Harness', '-n', str(n), bench]
+
+class SanityCheckLevel:
+    Fast, Gate, Normal, Extensive = range(4)
+
+def getSanityChecks(level=SanityCheckLevel.Normal):
+    checks = []
+    
+    dacapoSuccess = re.compile(r"^===== DaCapo 9\.12 ([a-zA-Z0-9_]+) PASSED in ([0-9]+) msec =====$")
+    for (bench, ns) in dacapoSanityWarmup.items():
+        if ns[level] > 0:
+            checks.append({'cmd' : getDacapoCmd(bench, vmOpts=dacapoVMOpts + ['-esa'], n=ns[level]), 'success' : dacapoSuccess})
+    
+    bootstrapSuccess = re.compile(r"in [0-9]+ ms$");
+    checks.append({'cmd' : ['-esa', '-version'], 'success' : bootstrapSuccess})
+    
+    return checks
+
+def runSanityCheck(cmd, successRE, cwd=None):
+    parser = OutputParser(nonZeroIsFatal=False)
+    jvmError = re.compile(r"\b(?P<jvmerror>([A-Z]:|/).*[/\\]hs_err_pid[0-9]+\.log)\b")
+    parser.addMatcher(Matcher(successRE, {'const:passed' : 'const:1'}))
+    parser.addMatcher(Matcher(jvmError, {'const:jvmError' : 'jvmerror'}))
+    
+    result = parser.parse(cmd, cwd)
+    assert len(result) == 1, 'Sanity check matchers should not return more than one line'
+    parsed = result[0]
+    
+    if parsed.has_key('jvmError'):
+        mx.log('JVM Error : dumping error log...')
+        f = open(parsed['jvmError'], 'rb');
+        for line in iter(f.readline(), ''):
+            mx.log(line)
+        f.close()
+        os.unlink(parsed['jvmError'])
+        return False
+    return parsed.has_key('passed')
+    
\ No newline at end of file
--- a/mxtool/mx.py	Tue Dec 20 10:36:44 2011 +0100
+++ b/mxtool/mx.py	Tue Dec 20 15:34:43 2011 +0100
@@ -335,9 +335,9 @@
                         os.environ[key.strip()] = expandvars_in_property(value.strip())
         
     def _load(self, mxDir, primary):
+        self._load_env(mxDir)
         self._load_includes(mxDir)
         self._load_projects(mxDir)
-        self._load_env(mxDir)
         if primary:
             self._load_commands(mxDir)