OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Archives or replays webpages and creates SKPs in a Google Storage location. | 6 """Archives or replays webpages and creates SKPs in a Google Storage location. |
7 | 7 |
8 To archive webpages and store SKP files (archives should be rarely updated): | 8 To archive webpages and store SKP files (archives should be rarely updated): |
9 | 9 |
10 cd ../buildbot/slave/skia_slave_scripts | 10 cd ../buildbot/slave/skia_slave_scripts |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 SKPICTURES_DIR_NAME = 'skps' | 66 SKPICTURES_DIR_NAME = 'skps' |
67 | 67 |
68 | 68 |
69 # Local archive and SKP directories. | 69 # Local archive and SKP directories. |
70 LOCAL_PLAYBACK_ROOT_DIR = os.path.join( | 70 LOCAL_PLAYBACK_ROOT_DIR = os.path.join( |
71 tempfile.gettempdir(), ROOT_PLAYBACK_DIR_NAME) | 71 tempfile.gettempdir(), ROOT_PLAYBACK_DIR_NAME) |
72 LOCAL_REPLAY_WEBPAGES_ARCHIVE_DIR = os.path.join( | 72 LOCAL_REPLAY_WEBPAGES_ARCHIVE_DIR = os.path.join( |
73 os.path.abspath(os.path.dirname(__file__)), 'page_sets', 'data') | 73 os.path.abspath(os.path.dirname(__file__)), 'page_sets', 'data') |
74 TMP_SKP_DIR = tempfile.mkdtemp() | 74 TMP_SKP_DIR = tempfile.mkdtemp() |
75 | 75 |
| 76 # Location of the credentials.json file and the string that represents missing |
| 77 # passwords. |
| 78 CREDENTIALS_FILE_PATH = os.path.join( |
| 79 os.path.abspath(os.path.dirname(__file__)), 'page_sets', 'data', |
| 80 'credentials.json' |
| 81 ) |
| 82 |
76 # Stdout that signifies that a recording has failed. | 83 # Stdout that signifies that a recording has failed. |
77 RECORD_FAILURE_MSG = 'The recording has not been updated for these pages.' | 84 RECORD_FAILURE_MSG = 'The recording has not been updated for these pages.' |
78 | 85 |
79 # Name of the SKP benchmark | 86 # Name of the SKP benchmark |
80 SKP_BENCHMARK = 'skpicture_printer' | 87 SKP_BENCHMARK = 'skpicture_printer' |
81 | 88 |
82 # The max base name length of Skp files. | 89 # The max base name length of Skp files. |
83 MAX_SKP_BASE_NAME_LEN = 31 | 90 MAX_SKP_BASE_NAME_LEN = 31 |
84 | 91 |
85 # Dictionary of device to platform prefixes for SKP files. | 92 # Dictionary of device to platform prefixes for SKP files. |
86 DEVICE_TO_PLATFORM_PREFIX = { | 93 DEVICE_TO_PLATFORM_PREFIX = { |
87 'desktop': 'desk', | 94 'desktop': 'desk', |
88 'galaxynexus': 'mobi', | 95 'galaxynexus': 'mobi', |
89 'nexus10': 'tabl' | 96 'nexus10': 'tabl' |
90 } | 97 } |
91 | 98 |
92 # How many times the record_wpr binary should be retried. | 99 # How many times the record_wpr binary should be retried. |
93 RETRY_RECORD_WPR_COUNT = 5 | 100 RETRY_RECORD_WPR_COUNT = 5 |
94 # How many times the run_benchmark binary should be retried. | 101 # How many times the run_benchmark binary should be retried. |
95 RETRY_RUN_MEASUREMENT_COUNT = 5 | 102 RETRY_RUN_MEASUREMENT_COUNT = 5 |
96 | 103 |
| 104 # Location of the credentials.json file in Google Storage. |
| 105 CREDENTIALS_GS_PATH = '/playback/credentials/credentials.json' |
| 106 |
97 X11_DISPLAY = os.getenv('DISPLAY', ':0') | 107 X11_DISPLAY = os.getenv('DISPLAY', ':0') |
98 | 108 |
99 GS_PREDEFINED_ACL = gs_utils.GSUtils.PredefinedACL.PRIVATE | 109 GS_PREDEFINED_ACL = gs_utils.GSUtils.PredefinedACL.PRIVATE |
100 GS_FINE_GRAINED_ACL_LIST = [ | 110 GS_FINE_GRAINED_ACL_LIST = [ |
101 (gs_utils.GSUtils.IdType.GROUP_BY_DOMAIN, 'google.com', | 111 (gs_utils.GSUtils.IdType.GROUP_BY_DOMAIN, 'google.com', |
102 gs_utils.GSUtils.Permission.READ), | 112 gs_utils.GSUtils.Permission.READ), |
103 ] | 113 ] |
104 | 114 |
105 | 115 |
106 class SkPicturePlayback(object): | 116 class SkPicturePlayback(object): |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 # Explode and return the glob. | 157 # Explode and return the glob. |
148 ps = glob.glob(page_sets) | 158 ps = glob.glob(page_sets) |
149 else: | 159 else: |
150 ps = page_sets.split(',') | 160 ps = page_sets.split(',') |
151 ps.sort() | 161 ps.sort() |
152 return ps | 162 return ps |
153 | 163 |
154 def Run(self): | 164 def Run(self): |
155 """Run the SkPicturePlayback BuildStep.""" | 165 """Run the SkPicturePlayback BuildStep.""" |
156 | 166 |
| 167 # Download the credentials file if it was not previously downloaded. |
| 168 if self._skip_all_gs_access: |
| 169 print """\n\nPlease create a %s file that contains: |
| 170 { |
| 171 "google": { |
| 172 "username": "google_testing_account_username", |
| 173 "password": "google_testing_account_password" |
| 174 }, |
| 175 "facebook": { |
| 176 "username": "facebook_testing_account_username", |
| 177 "password": "facebook_testing_account_password" |
| 178 } |
| 179 }\n\n""" % CREDENTIALS_FILE_PATH |
| 180 raw_input("Please press a key when you are ready to proceed...") |
| 181 elif not os.path.isfile(CREDENTIALS_FILE_PATH): |
| 182 # Download the credentials.json file from Google Storage. |
| 183 gs_bucket = self._dest_gsbase.lstrip(gs_utils.GS_PREFIX) |
| 184 gs_utils.GSUtils().download_file(gs_bucket, CREDENTIALS_GS_PATH, |
| 185 CREDENTIALS_FILE_PATH) |
| 186 |
157 # Delete any left over data files in the data directory. | 187 # Delete any left over data files in the data directory. |
158 for archive_file in glob.glob( | 188 for archive_file in glob.glob( |
159 os.path.join(LOCAL_REPLAY_WEBPAGES_ARCHIVE_DIR, 'skia_*')): | 189 os.path.join(LOCAL_REPLAY_WEBPAGES_ARCHIVE_DIR, 'skia_*')): |
160 os.remove(archive_file) | 190 os.remove(archive_file) |
161 | 191 |
162 # Delete the local root directory if it already exists. | 192 # Delete the local root directory if it already exists. |
163 if os.path.exists(LOCAL_PLAYBACK_ROOT_DIR): | 193 if os.path.exists(LOCAL_PLAYBACK_ROOT_DIR): |
164 shutil.rmtree(LOCAL_PLAYBACK_ROOT_DIR) | 194 shutil.rmtree(LOCAL_PLAYBACK_ROOT_DIR) |
165 | 195 |
166 # Create the required local storage directories. | 196 # Create the required local storage directories. |
(...skipping 30 matching lines...) Expand all Loading... |
197 # If we get here then record_wpr did not succeed and thus did not | 227 # If we get here then record_wpr did not succeed and thus did not |
198 # break out of the loop. | 228 # break out of the loop. |
199 raise Exception('record_wpr failed for page_set: %s' % page_set) | 229 raise Exception('record_wpr failed for page_set: %s' % page_set) |
200 | 230 |
201 else: | 231 else: |
202 if not self._skip_all_gs_access: | 232 if not self._skip_all_gs_access: |
203 # Get the webpages archive so that it can be replayed. | 233 # Get the webpages archive so that it can be replayed. |
204 self._DownloadWebpagesArchive(wpr_data_file, page_set_basename) | 234 self._DownloadWebpagesArchive(wpr_data_file, page_set_basename) |
205 | 235 |
206 page_set_name = os.path.basename(page_set).split('.')[0] | 236 page_set_name = os.path.basename(page_set).split('.')[0] |
| 237 page_set_dir = os.path.dirname(page_set) |
207 run_benchmark_cmd = ( | 238 run_benchmark_cmd = ( |
| 239 'PYTHONPATH=%s:$PYTHONPATH' % page_set_dir, |
208 'DISPLAY=%s' % X11_DISPLAY, | 240 'DISPLAY=%s' % X11_DISPLAY, |
209 'timeout', '300', | 241 'timeout', '300', |
210 os.path.join(self._telemetry_binaries_dir, 'run_benchmark'), | 242 os.path.join(self._telemetry_binaries_dir, 'run_benchmark'), |
211 '--extra-browser-args=--disable-setuid-sandbox', | 243 '--extra-browser-args=--disable-setuid-sandbox', |
212 '--browser=exact', | 244 '--browser=exact', |
213 '--browser-executable=%s' % self._browser_executable, | 245 '--browser-executable=%s' % self._browser_executable, |
214 SKP_BENCHMARK, | 246 SKP_BENCHMARK, |
215 page_set_name, | 247 '--page-set-name=%s' % page_set_name, |
216 '-o', | 248 '--page-set-base-dir=%s' % page_set_dir, |
217 '/tmp/test.skp', | 249 '--skp-outdir=%s' % TMP_SKP_DIR, |
218 '--skp-outdir=%s' % TMP_SKP_DIR | 250 '--also-run-disabled-tests' |
219 ) | 251 ) |
220 page_set_dst = os.path.join(self._telemetry_binaries_dir, 'page_sets', | |
221 os.path.basename(page_set)) | |
222 wpr_dst = os.path.join(self._telemetry_binaries_dir, 'page_sets', 'data', | |
223 wpr_data_file) | |
224 json_dst = os.path.join(self._telemetry_binaries_dir, 'page_sets', 'data', | |
225 page_set_basename) | |
226 copied_page_set = False | |
227 if not os.path.exists(page_set_dst): | |
228 print 'Copying %s to %s' % (page_set, page_set_dst) | |
229 shutil.copyfile(page_set, page_set_dst) | |
230 wpr_src = os.path.join(os.path.dirname(page_set), 'data', | |
231 wpr_data_file) | |
232 print 'Copying %s to %s' % (wpr_src, wpr_dst) | |
233 shutil.copyfile(wpr_src, wpr_dst) | |
234 json_src = os.path.join(os.path.dirname(page_set), 'data', | |
235 page_set_basename) | |
236 print 'Copying %s to %s' % (json_src, json_dst) | |
237 shutil.copyfile(json_src, json_dst) | |
238 copied_page_set = True | |
239 | 252 |
240 for _ in range(RETRY_RUN_MEASUREMENT_COUNT): | 253 for _ in range(RETRY_RUN_MEASUREMENT_COUNT): |
241 try: | 254 try: |
242 print '\n\n=======Capturing SKP of %s=======\n\n' % page_set | 255 print '\n\n=======Capturing SKP of %s=======\n\n' % page_set |
243 shell_utils.run(' '.join(run_benchmark_cmd), shell=True) | 256 shell_utils.run(' '.join(run_benchmark_cmd), shell=True) |
244 except shell_utils.CommandFailedException: | 257 except shell_utils.CommandFailedException: |
245 # skpicture_printer sometimes fails with AssertionError but the | 258 # skpicture_printer sometimes fails with AssertionError but the |
246 # captured SKP is still valid. This is a known issue. | 259 # captured SKP is still valid. This is a known issue. |
247 pass | 260 pass |
248 | 261 |
(...skipping 12 matching lines...) Expand all Loading... |
261 try: | 274 try: |
262 self._RenameSkpFiles(page_set) | 275 self._RenameSkpFiles(page_set) |
263 # Break out of the retry loop since there were no errors. | 276 # Break out of the retry loop since there were no errors. |
264 break | 277 break |
265 except Exception: | 278 except Exception: |
266 # There was a failure continue with the loop. | 279 # There was a failure continue with the loop. |
267 traceback.print_exc() | 280 traceback.print_exc() |
268 print '\n\n=======Retrying %s=======\n\n' % page_set | 281 print '\n\n=======Retrying %s=======\n\n' % page_set |
269 time.sleep(10) | 282 time.sleep(10) |
270 else: | 283 else: |
271 if copied_page_set: | |
272 os.remove(page_set_dst) | |
273 os.remove(wpr_dst) | |
274 os.remove(json_dst) | |
275 # If we get here then run_benchmark did not succeed and thus did not | 284 # If we get here then run_benchmark did not succeed and thus did not |
276 # break out of the loop. | 285 # break out of the loop. |
277 raise Exception('run_benchmark failed for page_set: %s' % page_set) | 286 raise Exception('run_benchmark failed for page_set: %s' % page_set) |
278 | 287 |
279 if copied_page_set: | |
280 os.remove(page_set_dst) | |
281 os.remove(wpr_dst) | |
282 os.remove(json_dst) | |
283 | |
284 print '\n\n=======Capturing SKP files took %s seconds=======\n\n' % ( | 288 print '\n\n=======Capturing SKP files took %s seconds=======\n\n' % ( |
285 time.time() - start_time) | 289 time.time() - start_time) |
286 | 290 |
287 if self._skia_tools: | 291 if self._skia_tools: |
288 render_pictures_cmd = [ | 292 render_pictures_cmd = [ |
289 os.path.join(self._skia_tools, 'render_pictures'), | 293 os.path.join(self._skia_tools, 'render_pictures'), |
290 '-r', self._local_skp_dir | 294 '-r', self._local_skp_dir |
291 ] | 295 ] |
292 render_pdfs_cmd = [ | 296 render_pdfs_cmd = [ |
293 os.path.join(self._skia_tools, 'render_pdfs'), | 297 os.path.join(self._skia_tools, 'render_pdfs'), |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 default=None) | 450 default=None) |
447 option_parser.add_option( | 451 option_parser.add_option( |
448 '', '--non-interactive', action='store_true', | 452 '', '--non-interactive', action='store_true', |
449 help='Runs the script without any prompts. If this flag is specified and ' | 453 help='Runs the script without any prompts. If this flag is specified and ' |
450 '--skia_tools is specified then the debugger is not run.', | 454 '--skia_tools is specified then the debugger is not run.', |
451 default=False) | 455 default=False) |
452 options, unused_args = option_parser.parse_args() | 456 options, unused_args = option_parser.parse_args() |
453 | 457 |
454 playback = SkPicturePlayback(options) | 458 playback = SkPicturePlayback(options) |
455 sys.exit(playback.Run()) | 459 sys.exit(playback.Run()) |
OLD | NEW |