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] [--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 opts, args = parser.parse_args(argv[1:])
44 os.environ['TIMESCONS_CALIBRATE'] = '1'
50 command = [sys.executable, 'runtest.py', '--noqmtest', arg]
55 p = subprocess.Popen(command,
56 stdout=subprocess.PIPE,
57 stderr=subprocess.STDOUT)
58 output = p.communicate()[0]
59 vm = variable_re.search(output)
60 em = elapsed_re.search(output)
61 elapsed = float(em.group(1))
62 print "run %3d: %7.3f: %s" % (run, elapsed, ' '.join(vm.groups()))
63 if opts.min < elapsed and elapsed < opts.max:
68 var, value = v.split('=', 1)
69 value = int((int(value) * opts.max) / elapsed)
70 os.environ[var] = str(value)
75 if __name__ == "__main__":