3 # Copyright (c) 2009 The SCons Foundation
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 variable_re = re.compile('^VARIABLE: (.*)$', re.M)
31 elapsed_re = re.compile('^ELAPSED: (.*)$', re.M)
37 parser = optparse.OptionParser(usage="calibrate.py [-h] [-p PACKAGE], [--min time] [--max time] timings/*/*-run.py")
38 parser.add_option('--min', type='float', default=9.5,
39 help="minimum acceptable execution time (default 9.5)")
40 parser.add_option('--max', type='float', default=10.00,
41 help="maximum acceptable execution time (default 10.00)")
42 parser.add_option('-p', '--package', type="string",
44 opts, args = parser.parse_args(argv[1:])
46 os.environ['TIMESCONS_CALIBRATE'] = '1'
52 command = [sys.executable, 'runtest.py', '--noqmtest']
54 command.extend(['-p', opts.package])
60 p = subprocess.Popen(command,
61 stdout=subprocess.PIPE,
62 stderr=subprocess.STDOUT)
63 output = p.communicate()[0]
64 vm = variable_re.search(output)
65 em = elapsed_re.search(output)
66 elapsed = float(em.group(1))
67 print "run %3d: %7.3f: %s" % (run, elapsed, ' '.join(vm.groups()))
68 if opts.min < elapsed and elapsed < opts.max:
73 var, value = v.split('=', 1)
74 value = int((int(value) * opts.max) / elapsed)
75 os.environ[var] = str(value)
80 if __name__ == "__main__":