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"""
14
15from __future__ import print_function
16from __future__ import absolute_import
17
18import os
19import sys
20import re
21from optparse import OptionParser
22
23# dotest.py invocation with no '-e exe-path' uses lldb as the inferior program,
24# unless there is a mentioning of custom executable program.
25benches = [
26    # Measure startup delays creating a target, setting a breakpoint, and run
27    # to breakpoint stop.
28    './dotest.py -v +b %E %X -n -p TestStartupDelays.py',
29
30    # Measure 'frame variable' response after stopping at a breakpoint.
31    './dotest.py -v +b %E %X -n -p TestFrameVariableResponse.py',
32
33    # Measure stepping speed after stopping at a breakpoint.
34    './dotest.py -v +b %E %X -n -p TestSteppingSpeed.py',
35
36    # Measure expression cmd response with a simple custom executable program.
37    './dotest.py +b -n -p TestExpressionCmd.py',
38
39    # Attach to a spawned process then run disassembly benchmarks.
40    './dotest.py -v +b -n %E -p TestDoAttachThenDisassembly.py'
41]
42
43
44def main():
45    """Read the items from 'benches' and run the command line one by one."""
46    parser = OptionParser(usage="""\
47%prog [options]
48Run the standard benchmarks defined in the list named 'benches'.\
49""")
50    parser.add_option('-e', '--executable',
51                      type='string', action='store',
52                      dest='exe',
53                      help='The target program launched by lldb.')
54    parser.add_option('-x', '--breakpoint-spec',
55                      type='string', action='store',
56                      dest='break_spec',
57                      help='The lldb breakpoint spec for the target program.')
58
59    # Parses the options, if any.
60    opts, args = parser.parse_args()
61
62    print("Starting bench runner....")
63
64    for item in benches:
65        command = item.replace('%E',
66                               '-e "%s"' % opts.exe if opts.exe else '')
67        command = command.replace('%X', '-x "%s"' %
68                                  opts.break_spec if opts.break_spec else '')
69        print("Running %s" % (command))
70        os.system(command)
71
72    print("Bench runner done.")
73
74if __name__ == '__main__':
75    main()
76