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.
29 variable_re
= re
.compile(r
'^VARIABLE: (.*)$', re
.M
)
30 elapsed_re
= re
.compile(r
'^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']
54 command
.extend(['-p', opts
.package
])
60 p
= subprocess
.Popen(command
,
61 stdout
=subprocess
.PIPE
,
62 stderr
=subprocess
.STDOUT
,
63 universal_newlines
=True)
64 output
= p
.communicate()[0]
65 vm
= variable_re
.search(output
)
66 em
= elapsed_re
.search(output
)
68 elapsed
= float(em
.group(1))
69 except AttributeError:
72 print("run %3d: %7.3f: %s" % (run
, elapsed
, ' '.join(vm
.groups())))
73 if opts
.min < elapsed
< opts
.max:
78 var
, value
= v
.split('=', 1)
79 # TODO: this sometimes converges slowly, better algorithm?
80 value
= int((int(value
) * opts
.max) // elapsed
)
81 os
.environ
[var
] = str(value
)
87 if __name__
== "__main__":