OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
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 | |
4 # found in the LICENSE file. | |
5 | |
6 """Record webapp interactions using Web Page Replay for Endure test. | |
7 | |
8 Usage: | |
9 ./record_endure.py [options] test_or_suite_1 [test_or_suite_2] ... | |
Nirnimesh
2012/08/06 21:36:45
remove ./
prefix python (so that it works on win)
| |
10 Please make sure that perf_endure.py is in the current working directory. | |
11 Examples: | |
12 1) ./record_endure.py perf.ChromeEndureGmailTest | |
13 | |
14 The above command runs each test in perf.ChromeEndureGmailTest. By default, | |
15 it runs each test for 30 secs and saves the archive file to 'archive.wpr' in | |
16 the current working directory. | |
17 | |
18 2) ./record_endure.py --test-length=40 \\ | |
dennis_jeffrey
2012/08/06 21:33:46
just put a single \ at the end of this line, not 2
| |
19 --archive-file="/home/user/ChromeEndureGmailTest.wpr" \\ | |
dennis_jeffrey
2012/08/06 21:33:46
just put a single \ at the end of this line, not 2
| |
20 perf.ChromeEndureGmailTest | |
21 | |
22 The above command runs each test for 40 seconds and saves the archive to | |
23 /home/user/ChromeEndureGmailTest.wpr | |
24 """ | |
25 | |
26 import optparse | |
27 import os | |
28 import subprocess | |
29 import sys | |
30 | |
31 import perf | |
32 import webpagereplay | |
33 | |
34 | |
35 class PlainHelpFormatter(optparse.IndentedHelpFormatter): | |
36 """Format the help message of this script.""" | |
37 | |
38 def format_description(self, description): | |
39 if description: | |
40 return description + '\n' | |
41 else: | |
42 return '' | |
43 | |
44 | |
45 class Recorder(object): | |
46 """Record webapp interactions of Endure tests via Web Page Replay.""" | |
47 | |
48 @classmethod | |
49 def _ParseArgs(cls): | |
50 parser = optparse.OptionParser( | |
51 usage='%prog [options] test_or_suite_1 [test_or_suite_2] ...', | |
52 formatter=PlainHelpFormatter(), | |
53 description=__doc__) | |
54 message = 'Length of each test in seconds. Default value is 30 secs.' | |
55 parser.add_option('--test-length', type='int', default=30, | |
56 help=message) | |
57 message = 'Path and name of the archive file. Default value is ' \ | |
58 '<CURRENT_WORKING_DIR>/archive.wpr' | |
59 parser.add_option('--archive-file', type='string', default='archive.wpr', | |
60 help=message) | |
61 options, args = parser.parse_args() | |
62 if len(args) < 1: | |
63 parser.error('Invalid arguments. Use --help to see usage.') | |
64 return options, args | |
65 | |
66 @classmethod | |
67 def Main(cls): | |
68 """Set up Web Page Replay and run Endure tests.""" | |
69 options, args = cls._ParseArgs() | |
70 test_length = options.test_length | |
71 # Use a greater value than test length to disable stats. | |
72 perf_stats_interval = test_length + 60 | |
73 archive_path = os.path.abspath(options.archive_file) | |
74 tests = args[0:] | |
75 script_path = 'src/chrome/test/data/chrome_endure/' \ | |
76 'webpagereplay/wpr_deterministic.js' | |
slamm_google
2012/08/06 20:58:44
It is redundant to have this path here.
Is there a
dennis_jeffrey
2012/08/06 21:33:46
We need to be able to start WPR in record mode, ru
| |
77 replay_options = [ | |
78 '--record', | |
79 '--inject_scripts', perf.FormatChromePath(script_path), | |
80 ] | |
81 with webpagereplay.ReplayServer(archive_path, replay_options): | |
82 env = os.environ.copy() | |
83 env.update({ | |
84 'TEST_LENGTH': str(test_length), | |
85 'PERF_STATS_INTERVAL': str(perf_stats_interval), | |
86 'WPR_RECORD': '1', | |
87 'DO_NOT_RESTART_PYTHON_FOR_PYAUTO': '1', | |
88 }) | |
89 | |
90 cmd = ['python', 'perf_endure.py'] | |
91 cmd.extend(tests) | |
92 print cmd | |
93 code = subprocess.call(cmd, env=env) | |
94 print 'Shutting down server.' | |
95 if (code == 0 and os.path.exists(archive_path) and | |
96 os.path.isfile(archive_path)): | |
97 print 'Archive is saved to %s' % archive_path | |
98 return 0 | |
99 else: | |
100 print ('Error in recording. The output archive might be invalid. ' + | |
101 'See log: %s' % webpagereplay.LOG_PATH) | |
102 return 1 | |
103 | |
104 | |
105 if __name__ == '__main__': | |
106 sys.exit(Recorder().Main()) | |
OLD | NEW |