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