experiment_gen.py revision f81680c018729fd4499e1e200d04b48c4b90127c
1#!/usr/bin/python
2# Copyright 2012 Google Inc. All Rights Reserved.
3"""This script generates a crosperf overhead-testing experiment file for MoreJS.
4
5Use: experiment_gen.py --crosperf=/home/mrdmnd/depot2/crosperf --chromeos_root=
6/home/mrdmnd/chromiumos --remote-host=chromeos-zgb3.mtv --board=x86-zgb --event=
7cycles -F 10 -F 20 -c 10582 -c 10785211 --perf_options="-g"
8"""
9
10import optparse
11import subprocess
12import sys
13import time
14
15HEADER = """
16board: %s
17remote: %s
18benchmark: baseline {
19 iterations: %s
20 autotest_name: desktopui_PyAutoPerfTests
21 autotest_args: --args='--iterations=%s perf.PageCyclerTest.testMoreJSFile'
22}"""
23
24EXPERIMENT = """
25benchmark: %s {
26 iterations: %s
27 autotest_name: desktopui_PyAutoPerfTests
28 autotest_args: --args='--iterations=%s perf.PageCyclerTest.testMoreJSFile' --profiler=custom_perf --profiler_args='perf_options="record -a %s %s -e %s"' \n}"""  # pylint: disable-msg=C6310
29
30DEFAULT_IMAGE = """
31default {
32 chromeos_image: %s/src/build/images/%s/latest/chromiumos_test_image.bin
33}"""
34
35
36def main():
37  parser = optparse.OptionParser()
38  parser.add_option('--crosperf', dest='crosperf_root', action='store',
39                    default='/home/mrdmnd/depot2/crosperf',
40                    help='Crosperf root directory.')
41  parser.add_option('--chromeos_root', dest='chromeos_root', action='store',
42                    default='/home/mrdmnd/chromiumos',
43                    help='ChromiumOS root directory.')
44  parser.add_option('--remote', dest='remote', action='store',
45                    help='Host to run test on. Required.')
46  parser.add_option('--board', dest='board', action='store',
47                    help='Board architecture to run on. Required.')
48  parser.add_option('--event', dest='event', action='store',
49                    help='Event to profile. Required.')
50  parser.add_option('-F', dest='sampling_frequencies', action='append',
51                    help='A target frequency to sample at.')
52  parser.add_option('-c', dest='sampling_periods', action='append',
53                    help='A target period to sample at. Event specific.')
54  parser.add_option('--benchmark-iterations', dest='benchmark_iterations',
55                    action='store', default=4, help='Number of benchmark iters')
56  parser.add_option('--test-iterations', dest='test_iterations',
57                    action='store', default=10, help='Number of test iters')
58  parser.add_option('-p', dest='print_only', action='store_true',
59                    help='If enabled, will print experiment file and exit.')
60  parser.add_option('--perf_options', dest='perf_options', action='store',
61                    help='Arbitrary flags to perf. Surround with dblquotes.')
62  options = parser.parse_args()[0]
63  if options.remote is None:
64    print '%s requires a remote hostname.' % sys.argv[0]
65    return 1
66  elif options.board is None:
67    print '%s requires a target board.' % sys.argv[0]
68    return 1
69  elif options.event is None:
70    print '%s requires an event to profile.' % sys.argv[0]
71    return 1
72  else:
73    crosperf_root = options.crosperf_root
74    chromeos_root = options.chromeos_root
75    remote = options.remote
76    board = options.board
77    event = options.event
78    bench_iters = options.benchmark_iterations
79    test_iters = options.test_iterations
80    perf_opts = options.perf_options
81    # Set up baseline test.
82    experiment_file = HEADER % (board, remote, bench_iters, test_iters)
83    # Set up experimental tests.
84    if options.sampling_frequencies:
85      for freq in options.sampling_frequencies:
86        test_string = str(freq) + 'Freq'
87        experiment_file += EXPERIMENT % (test_string, bench_iters, test_iters,
88                                         '-F %s' % freq,
89                                         '' if perf_opts is None else perf_opts,
90                                         event)
91    if options.sampling_periods:
92      for period in options.sampling_periods:
93        test_string = str(period) + 'Period'
94        experiment_file += EXPERIMENT % (test_string, bench_iters, test_iters,
95                                         '-c %s' % period,
96                                         '' if perf_opts is None else perf_opts,
97                                         event)
98    # Point to the target image.
99    experiment_file += DEFAULT_IMAGE % (chromeos_root, board)
100    if options.print_only:
101      print experiment_file
102    else:
103      current_time = int(round(time.time() * 1000))
104      file_name = 'perf_overhead_%s' % str(current_time)
105      with open(file_name, "w") as f:
106        f.write(experiment_file)
107      try:
108        process = subprocess.Popen(['%s/crosperf' % crosperf_root, file_name])
109        process.communicate()
110      except OSError:
111        print 'Could not find crosperf, make sure --crosperf flag is set right.'
112        return 1
113    return 0
114
115if __name__ == '__main__':
116  exit(main())
117