2 # Copyright (c) 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
7 """Run the webpages_playback automation script."""
14 sys.path.insert(0, os.getcwd())
16 from common.py.utils import gs_utils
17 from common.py.utils import shell_utils
20 SKP_VERSION_FILE = 'SKP_VERSION'
23 def _get_skp_version():
24 """Find an unused SKP version."""
25 current_skp_version = None
26 with open(SKP_VERSION_FILE) as f:
27 current_skp_version = int(f.read().rstrip())
29 # Find the first SKP version which has no uploaded SKPs.
30 new_version = current_skp_version + 1
32 gs_path = 'playback_%d/skps' % new_version
33 if not gs_utils.GSUtils().does_storage_object_exist('chromium-skia-gm',
39 def main(chrome_src_path, browser_executable):
40 browser_executable = os.path.realpath(browser_executable)
41 skp_version = _get_skp_version()
42 print 'SKP_VERSION=%d' % skp_version
44 if os.environ.get('CHROME_HEADLESS'):
45 # Start Xvfb if running on a bot.
47 shell_utils.run('sudo Xvfb :0 -screen 0 1280x1024x24 &', shell=True)
49 # It is ok if the above command fails, it just means that DISPLAY=:0
53 upload_dir = 'playback_%d' % skp_version
54 webpages_playback_cmd = [
55 'python', os.path.join(os.path.dirname(os.path.realpath(__file__)),
56 'webpages_playback.py'),
58 '--browser_executable', browser_executable,
61 '--alternate_upload_dir', upload_dir,
62 '--chrome_src_path', chrome_src_path,
66 shell_utils.run(webpages_playback_cmd)
68 # Clean up any leftover browser instances. This can happen if there are
69 # telemetry crashes, processes are not always cleaned up appropriately by
70 # the webpagereplay and telemetry frameworks.
71 procs = subprocess.check_output(['ps', 'ax'])
72 for line in procs.splitlines():
73 if browser_executable in line:
74 pid = line.strip().split(' ')[0]
75 if pid != str(os.getpid()) and not 'python' in line:
77 shell_utils.run(['kill', '-9', pid])
78 except shell_utils.CommandFailedException as e:
81 print 'Refusing to kill self.'
83 print 'writing %s: %s' % (SKP_VERSION_FILE, skp_version)
84 with open(SKP_VERSION_FILE, 'w') as f:
85 f.write(str(skp_version))
88 if '__main__' == __name__:
89 if len(sys.argv) != 3:
90 print >> sys.stderr, 'USAGE: %s <chrome src path> <browser executable>'