1#!/usr/bin/env python
2
3"""
4A simple bench runner which delegates to the ./dotest.py test driver to run the
5benchmarks defined in the list named 'benches'.
6
7You need to hand edit 'benches' to modify/change the command lines passed to the
8test driver.
9
10Use the following to get only the benchmark results in your terminal output:
11
12    ./bench.py -e /Volumes/data/lldb/svn/regression/build/Debug/lldb -x '-F Driver::MainLoop()' 2>&1 | grep -P '^lldb.*benchmark:'
13
14See also bench-history.
15"""
16
17from __future__ import print_function
18from __future__ import absolute_import
19
20import os
21import sys
22import re
23from optparse import OptionParser
24
25# dotest.py invocation with no '-e exe-path' uses lldb as the inferior program,
26# unless there is a mentioning of custom executable program.
27benches = [
28    # Measure startup delays creating a target, setting a breakpoint, and run
29    # to breakpoint stop.
30    './dotest.py -v +b %E %X -n -p TestStartupDelays.py',
31
32    # Measure 'frame variable' response after stopping at a breakpoint.
33    './dotest.py -v +b %E %X -n -p TestFrameVariableResponse.py',
34
35    # Measure stepping speed after stopping at a breakpoint.
36    './dotest.py -v +b %E %X -n -p TestSteppingSpeed.py',
37
38    # Measure expression cmd response with a simple custom executable program.
39    './dotest.py +b -n -p TestExpressionCmd.py',
40
41    # Attach to a spawned process then run disassembly benchmarks.
42    './dotest.py -v +b -n %E -p TestDoAttachThenDisassembly.py'
43]
44
45
46def main():
47    """Read the items from 'benches' and run the command line one by one."""
48    parser = OptionParser(usage="""\
49%prog [options]
50Run the standard benchmarks defined in the list named 'benches'.\
51""")
52    parser.add_option('-e', '--executable',
53                      type='string', action='store',
54                      dest='exe',
55                      help='The target program launched by lldb.')
56    parser.add_option('-x', '--breakpoint-spec',
57                      type='string', action='store',
58                      dest='break_spec',
59                      help='The lldb breakpoint spec for the target program.')
60
61    # Parses the options, if any.
62    opts, args = parser.parse_args()
63
64    print("Starting bench runner....")
65
66    for item in benches:
67        command = item.replace('%E',
68                               '-e "%s"' % opts.exe if opts.exe else '')
69        command = command.replace('%X', '-x "%s"' %
70                                  opts.break_spec if opts.break_spec else '')
71        print("Running %s" % (command))
72        os.system(command)
73
74    print("Bench runner done.")
75
76if __name__ == '__main__':
77    main()
78