cmtice | 4859f5f | 2014-05-30 13:15:37 -0700 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | # |
| 3 | # Copyright Google Inc. 2014 |
| 4 | |
| 5 | import sys |
| 6 | import time |
| 7 | import optparse |
| 8 | import os |
| 9 | |
| 10 | from utils import constants |
| 11 | from utils import command_executer |
| 12 | |
| 13 | WEEKDAYS = ['Sat', 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri'] |
| 14 | |
| 15 | DATA_ROOT_DIR = os.path.join(constants.CROSTC_WORKSPACE, |
| 16 | 'weekly_test_data') |
| 17 | |
| 18 | EXPERIMENT_FILE = os.path.join(DATA_ROOT_DIR, 'weekly_report') |
| 19 | |
| 20 | |
| 21 | def Generate_Vanilla_Report_File(vanilla_image_paths, board, remote, |
| 22 | chromeos_root, cmd_executer): |
| 23 | |
| 24 | experiment_header = """ |
| 25 | name: weekly_vanilla_report |
| 26 | board: %s |
| 27 | remote: %s |
| 28 | """ % (board, remote) |
| 29 | |
| 30 | |
| 31 | experiment_tests = """ |
| 32 | benchmark: all_perfv2 { |
| 33 | suite: telemetry_Crosperf |
| 34 | iterations: 3 |
| 35 | } |
| 36 | """ |
| 37 | |
| 38 | filename = "%s_%s_vanilla.exp" % (EXPERIMENT_FILE, board) |
| 39 | if os.path.exists(filename): |
| 40 | cmd = "rm %s" % filename |
| 41 | cmd_executer.RunCommand(cmd) |
| 42 | |
| 43 | with open(filename, "w") as f: |
| 44 | print >>f, experiment_header |
| 45 | print >>f, experiment_tests |
| 46 | |
| 47 | # Add each vanilla image |
| 48 | for test_path in vanilla_image_paths: |
| 49 | pieces = test_path.split("/") |
| 50 | test_name = pieces[-1] |
| 51 | test_image = """ |
| 52 | %s { |
| 53 | chromeos_root: %s |
| 54 | chromeos_image: %s |
| 55 | } |
| 56 | """ % (test_name, chromeos_root, os.path.join (test_path, "chromiumos_test_image.bin")) |
| 57 | print >>f, test_image |
| 58 | |
| 59 | return filename |
| 60 | |
| 61 | def Generate_Test_File(test_image_paths, vanilla_image_path, board, remote, |
| 62 | chromeos_root, cmd_executer): |
| 63 | |
| 64 | experiment_header = """ |
| 65 | name: weekly_report |
| 66 | board: %s |
| 67 | remote: %s |
| 68 | """ % (board, remote) |
| 69 | |
| 70 | |
| 71 | experiment_tests = """ |
| 72 | benchmark: all_perfv2 { |
| 73 | suite: telemetry_Crosperf |
| 74 | iterations: 3 |
| 75 | } |
| 76 | """ |
| 77 | |
| 78 | filename = "%s_%s.exp" % (EXPERIMENT_FILE, board) |
| 79 | if os.path.exists(filename): |
| 80 | cmd = "rm %s" % filename |
| 81 | cmd_executer.RunCommand(cmd) |
| 82 | |
| 83 | with open(filename, "w") as f: |
| 84 | print >>f, experiment_header |
| 85 | print >>f, experiment_tests |
| 86 | |
| 87 | # Add vanilla image (first) |
| 88 | vanilla_image = """ |
| 89 | vanilla_image { |
| 90 | chromeos_root: %s |
| 91 | chromeos_image: %s |
| 92 | } |
| 93 | """ % (chromeos_root, os.path.join(vanilla_image_path, "chromiumos_test_image.bin")) |
| 94 | |
| 95 | print >>f, vanilla_image |
| 96 | |
| 97 | # Add each test image |
| 98 | for test_path in test_image_paths: |
| 99 | pieces = test_path.split("/") |
| 100 | test_name = pieces[-1] |
| 101 | test_image = """ |
| 102 | %s { |
| 103 | chromeos_root: %s |
| 104 | chromeos_image: %s |
| 105 | } |
| 106 | """ % (test_name, chromeos_root, os.path.join (test_path, "chromiumos_test_image.bin")) |
| 107 | print >>f, test_image |
| 108 | |
| 109 | return filename |
| 110 | |
| 111 | |
| 112 | |
| 113 | def Main(argv): |
| 114 | |
| 115 | parser = optparse.OptionParser() |
| 116 | parser.add_option('-b', '--board', dest='board', |
| 117 | help='Target board.') |
| 118 | parser.add_option("-r", "--remote", dest="remote", |
| 119 | help="Target device.") |
| 120 | parser.add_option("-v", "--vanilla_only", dest="vanilla_only", |
| 121 | action="store_true", |
| 122 | default=False, |
| 123 | help="Generate a report comparing only the vanilla images.") |
| 124 | |
| 125 | options = parser.parse_args(argv[1:])[0] |
| 126 | |
| 127 | if not options.board: |
| 128 | print "Must specify a board." |
| 129 | return 1 |
| 130 | |
| 131 | if not options.remote: |
| 132 | print "Must specify at least one remote." |
| 133 | return 1 |
| 134 | |
| 135 | cmd_executer = command_executer.GetCommandExecuter(log_level="average") |
| 136 | |
| 137 | # Find all the test image tar files, untar them and add them to |
| 138 | # the list. Also find and untar vanilla image tar files, and keep |
| 139 | # track of the first vanilla image. |
| 140 | report_image_paths = [] |
| 141 | vanilla_image_paths = [] |
| 142 | first_vanilla_image = None |
| 143 | for day in WEEKDAYS: |
| 144 | data_path = os.path.join(DATA_ROOT_DIR, options.board, day) |
| 145 | if os.path.exists(data_path): |
| 146 | # First, untar the test image. |
| 147 | tar_file_name = "%s_test_image.tar" % day |
| 148 | tar_file_path = os.path.join(data_path, tar_file_name) |
| 149 | image_dir = "%s_test_image" % day |
| 150 | image_path = os.path.join(data_path, image_dir) |
| 151 | if os.path.exists(tar_file_path): |
| 152 | if not os.path.exists(image_path): |
| 153 | os.makedirs(image_path) |
| 154 | cmd = ("cd %s; tar -xvf %s -C %s --strip-components 1" % |
| 155 | (data_path, tar_file_path, image_path)) |
| 156 | ret = cmd_executer.RunCommand(cmd) |
| 157 | if not ret: |
| 158 | report_image_paths.append(image_path) |
| 159 | # Next, untar the vanilla image. |
| 160 | vanilla_file = "%s_vanilla_image.tar" % day |
| 161 | v_file_path = os.path.join(data_path, vanilla_file) |
| 162 | image_dir = "%s_vanilla_image" % day |
| 163 | image_path = os.path.join(data_path, image_dir) |
| 164 | if os.path.exists(v_file_path): |
| 165 | if not os.path.exists(image_path): |
| 166 | os.makedirs(image_path) |
| 167 | cmd = ("cd %s; tar -xvf %s -C %s --strip-components 1" % |
| 168 | (data_path, v_file_path, image_path)) |
| 169 | ret = cmd_executer.RunCommand(cmd) |
| 170 | if not ret: |
| 171 | vanilla_image_paths.append(image_path) |
| 172 | if not first_vanilla_image: |
| 173 | first_vanilla_image = image_path |
| 174 | |
| 175 | # Find a chroot we can use. Look for a directory containing both |
| 176 | # an experiment file and a chromeos directory (the experiment file will |
| 177 | # only be created if both images built successfully, i.e. the chroot is |
| 178 | # good). |
| 179 | chromeos_root = None |
| 180 | for day in WEEKDAYS: |
| 181 | startdir = os.path.join(constants.CROSTC_WORKSPACE, day) |
| 182 | num_dirs = os.listdir(startdir) |
| 183 | for d in num_dirs: |
| 184 | exp_file = os.path.join(startdir, d, "toolchain_experiment.txt") |
| 185 | chroot = os.path.join(startdir, d, "chromeos") |
| 186 | if os.path.exists(chroot) and os.path.exists(exp_file): |
| 187 | chromeos_root = chroot |
| 188 | if chromeos_root: |
| 189 | break; |
| 190 | if chromeos_root: |
| 191 | break; |
| 192 | |
| 193 | if not chromeos_root: |
| 194 | print "Unable to locate a usable chroot. Exiting without report." |
| 195 | return 1 |
| 196 | |
| 197 | |
| 198 | # Create the Crosperf experiment file for generating the weekly report. |
| 199 | if not options.vanilla_only: |
| 200 | filename = Generate_Test_File (report_image_paths, first_vanilla_image, |
| 201 | options.board, options.remote, |
| 202 | chromeos_root, cmd_executer) |
| 203 | else: |
| 204 | filename = Generate_Vanilla_Report_File (vanilla_image_paths, |
| 205 | options.board, options.remote, |
| 206 | chromeos_root, cmd_executer) |
| 207 | |
| 208 | # Run Crosperf on the file to generate the weekly report. |
| 209 | cmd = ("%s/toolchain-utils/crosperf/crosperf " |
| 210 | "%s --cache_only=True --email=c-compiler-chrome@google.com" % |
| 211 | (constants.CROSTC_WORKSPACE, filename)) |
| 212 | retval = cmd_executer.RunCommand(cmd) |
| 213 | return retval |
| 214 | |
| 215 | |
| 216 | |
| 217 | if __name__ == '__main__': |
| 218 | retval = Main(sys.argv) |
| 219 | sys.exit(retval) |