208 """Run the SkPicturePlayback BuildStep."""
209
210
211 if not os.path.isfile(CREDENTIALS_FILE_PATH):
212
213 self.gs.download_file(CREDENTIALS_GS_PATH, CREDENTIALS_FILE_PATH)
214
215 if not os.path.isfile(CREDENTIALS_FILE_PATH):
216 raise Exception("""Could not locate credentials file in the storage.
217 Please create a credentials file in gs://%s that contains:
218 {
219 "google": {
220 "username": "google_testing_account_username",
221 "password": "google_testing_account_password"
222 }
223 }\n\n""" % CREDENTIALS_GS_PATH)
224
225
226 for archive_file in glob.glob(
227 os.path.join(LOCAL_REPLAY_WEBPAGES_ARCHIVE_DIR, 'skia_*')):
228 os.remove(archive_file)
229
230
231 self._CreateLocalStorageDirs()
232
233
234 start_time = time.time()
235
236
237 for page_set in self._page_sets:
238 if os.path.basename(page_set) == '__init__.py':
239 continue
240 page_set_basename = os.path.basename(page_set).split('.')[0]
241 page_set_json_name = page_set_basename + '.json'
242 wpr_data_file_glob = (
243 page_set.split(os.path.sep)[-1].split('.')[0] + '_*.wprgo')
244 page_set_dir = os.path.dirname(page_set)
245
246 if self._IsChromiumPageSet(page_set):
247 print(
'Using Chromium\'s captured archives for Chromium\'s page sets.')
248 elif self._record:
249
250
251 record_wpr_cmd = (
252 'PYTHONPATH=%s:%s:$PYTHONPATH' % (page_set_dir, self._catapult_dir),
253 'DISPLAY=%s' % X11_DISPLAY,
254 os.path.join(self._telemetry_binaries_dir, 'record_wpr'),
255 '--extra-browser-args="%s"' % self._browser_args,
256 '--browser=exact',
257 '--browser-executable=%s' % self._browser_executable,
258 '%s_page_set' % page_set_basename,
259 '--page-set-base-dir=%s' % page_set_dir
260 )
261 for _ in range(RETRY_RECORD_WPR_COUNT):
262 try:
263 subprocess.check_call(
' '.
join(record_wpr_cmd), shell=
True)
264
265
266
267 for wpr_data_file in glob.glob(os.path.join(
268 LOCAL_REPLAY_WEBPAGES_ARCHIVE_DIR, wpr_data_file_glob)):
269 shutil.copy(
270 os.path.join(LOCAL_REPLAY_WEBPAGES_ARCHIVE_DIR, wpr_data_file),
271 self._local_record_webpages_archive_dir)
272 shutil.copy(
273 os.path.join(LOCAL_REPLAY_WEBPAGES_ARCHIVE_DIR,
274 page_set_json_name),
275 self._local_record_webpages_archive_dir)
276
277
278 break
279 except Exception:
280
281 traceback.print_exc()
282 else:
283
284
285 raise Exception('record_wpr failed for page_set: %s' % page_set)
286
287 else:
288
289 self._DownloadWebpagesArchive(wpr_data_file_glob, page_set_json_name)
290
291 run_benchmark_cmd = [
292 'PYTHONPATH=%s:%s:$PYTHONPATH' % (page_set_dir, self._catapult_dir),
293 'DISPLAY=%s' % X11_DISPLAY,
294 'timeout', '1800',
295 os.path.join(self._telemetry_binaries_dir, 'run_benchmark'),
296 '--extra-browser-args="%s"' % self._browser_args,
297 '--browser=exact',
298 '--browser-executable=%s' % self._browser_executable,
299 SKP_BENCHMARK,
300 '--page-set-name=%s' % page_set_basename,
301 '--page-set-base-dir=%s' % page_set_dir,
302 '--skp-outdir=%s' % TMP_SKP_DIR,
303 '--also-run-disabled-tests',
304 ]
305
306 exclusions = PAGE_SETS_TO_EXCLUSIONS.get(os.path.basename(page_set))
307 if exclusions:
308 run_benchmark_cmd.append('--story-filter-exclude=' + exclusions)
309
310 for _ in range(RETRY_RUN_MEASUREMENT_COUNT):
311 try:
312 print(
'\n\n=======Capturing SKP of %s=======\n\n' % page_set)
313 subprocess.check_call(
' '.
join(run_benchmark_cmd), shell=
True)
314 except subprocess.CalledProcessError:
315
316 traceback.print_exc()
317 print(
'\n\n=======Retrying %s=======\n\n' % page_set)
318 time.sleep(10)
319 continue
320
321 try:
322
323 self._RenameSkpFiles(page_set)
324 except InvalidSKPException:
325
326 traceback.print_exc()
327 print(
'\n\n=======Retrying %s=======\n\n' % page_set)
328 time.sleep(10)
329 continue
330
331
332 break
333 else:
334
335
336 raise Exception('run_benchmark failed for page_set: %s' % page_set)
337
338 print(
'\n\n=======Capturing SKP files took %s seconds=======\n\n' % (
339 time.time() - start_time))
340
341 if self._skia_tools:
342 render_pictures_cmd = [
343 os.path.join(self._skia_tools, 'render_pictures'),
344 '-r', self._local_skp_dir
345 ]
346 render_pdfs_cmd = [
347 os.path.join(self._skia_tools, 'render_pdfs'),
348 '-r', self._local_skp_dir
349 ]
350
351 for tools_cmd in (render_pictures_cmd, render_pdfs_cmd):
352 print(
'\n\n=======Running %s=======' %
' '.
join(tools_cmd))
353 subprocess.check_call(tools_cmd)
354
355 if not self._non_interactive:
356 print(
'\n\n=======Running debugger=======')
357 os.system('%s %s' % (os.path.join(self._skia_tools, 'debugger'),
358 self._local_skp_dir))
359
361
362 if self._upload:
363 print(
'\n\n=======Uploading to %s=======\n\n' % self.gs.target_type())
364
365 dest_dir_name = ROOT_PLAYBACK_DIR_NAME
366 if self._alternate_upload_dir:
367 dest_dir_name = self._alternate_upload_dir
368
369 self.gs.upload_dir_contents(
370 self._local_skp_dir, dest_dir=dest_dir_name)
371
372 print(
'\n\n=======New SKPs have been uploaded to %s =======\n\n' %
373 posixpath.join(self.gs.target_name(), dest_dir_name,
374 SKPICTURES_DIR_NAME))
375
376 else:
377 print(
'\n\n=======Not Uploading to %s=======\n\n' % self.gs.target_type())
378 print(
'Generated resources are available in %s\n\n' % self._local_skp_dir)
379
380 if self._upload_to_partner_bucket:
381 print(
'\n\n=======Uploading to Partner bucket %s =======\n\n' %
382 PARTNERS_GS_BUCKET)
383 partner_gs = GoogleStorageDataStore(PARTNERS_GS_BUCKET)
384 timestamp = datetime.datetime.utcnow().strftime('%Y-%m-%d')
385 upload_dir = posixpath.join(SKPICTURES_DIR_NAME, timestamp)
386 try:
387 partner_gs.delete_path(upload_dir)
388 except subprocess.CalledProcessError:
389 print(
'Cannot delete %s because it does not exist yet.' % upload_dir)
390 print(
'Uploading %s to %s' % (self._local_skp_dir, upload_dir))
391 partner_gs.upload_dir_contents(self._local_skp_dir, upload_dir)
392 print(
'\n\n=======New SKPs have been uploaded to %s =======\n\n' %
393 posixpath.join(partner_gs.target_name(), upload_dir))
394
395 return 0
396
def print(*args, **kwargs)
static SkString join(const CommandLineFlags::StringArray &)