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