OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2010 Google Inc. All Rights Reserved. | 2 # Copyright 2010 Google Inc. All Rights Reserved. |
3 # | 3 # |
4 # Licensed under the Apache License, Version 2.0 (the "License"); | 4 # Licensed under the Apache License, Version 2.0 (the "License"); |
5 # you may not use this file except in compliance with the License. | 5 # you may not use this file except in compliance with the License. |
6 # You may obtain a copy of the License at | 6 # You may obtain a copy of the License at |
7 # | 7 # |
8 # http://www.apache.org/licenses/LICENSE-2.0 | 8 # http://www.apache.org/licenses/LICENSE-2.0 |
9 # | 9 # |
10 # Unless required by applicable law or agreed to in writing, software | 10 # Unless required by applicable law or agreed to in writing, software |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 options, args = option_parser.parse_args() | 158 options, args = option_parser.parse_args() |
159 options = OptionsWrapper(options, option_parser) # run checks and updates | 159 options = OptionsWrapper(options, option_parser) # run checks and updates |
160 if options.record and options.HasTrafficShaping(): | 160 if options.record and options.HasTrafficShaping(): |
161 [...] | 161 [...] |
162 """ | 162 """ |
163 _TRAFFICSHAPING_OPTIONS = set( | 163 _TRAFFICSHAPING_OPTIONS = set( |
164 ['down', 'up', 'delay_ms', 'packet_loss_rate', 'init_cwnd', 'net']) | 164 ['down', 'up', 'delay_ms', 'packet_loss_rate', 'init_cwnd', 'net']) |
165 _CONFLICTING_OPTIONS = ( | 165 _CONFLICTING_OPTIONS = ( |
166 ('record', ('down', 'up', 'delay_ms', 'packet_loss_rate', 'net', | 166 ('record', ('down', 'up', 'delay_ms', 'packet_loss_rate', 'net', |
167 'spdy', 'use_server_delay')), | 167 'spdy', 'use_server_delay')), |
| 168 ('append', ('down', 'up', 'delay_ms', 'packet_loss_rate', 'net', |
| 169 'spdy', 'use_server_delay')), # same as --record |
168 ('net', ('down', 'up', 'delay_ms')), | 170 ('net', ('down', 'up', 'delay_ms')), |
169 ('server', ('server_mode',)), | 171 ('server', ('server_mode',)), |
170 ) | 172 ) |
171 # The --net values come from http://www.webpagetest.org/. | 173 # The --net values come from http://www.webpagetest.org/. |
172 # https://sites.google.com/a/webpagetest.org/docs/other-resources/2011-fcc-bro
adband-data | 174 # https://sites.google.com/a/webpagetest.org/docs/other-resources/2011-fcc-bro
adband-data |
173 _NET_CONFIGS = ( | 175 _NET_CONFIGS = ( |
174 # key --down --up --delay_ms | 176 # key --down --up --delay_ms |
175 ('dsl', ('1536Kbit/s', '384Kbit/s', '50')), | 177 ('dsl', ('1536Kbit/s', '384Kbit/s', '50')), |
176 ('cable', ( '5Mbit/s', '1Mbit/s', '28')), | 178 ('cable', ( '5Mbit/s', '1Mbit/s', '28')), |
177 ('fios', ( '20Mbit/s', '5Mbit/s', '4')), | 179 ('fios', ( '20Mbit/s', '5Mbit/s', '4')), |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 if 'packet_loss_rate' in self._nondefaults: | 225 if 'packet_loss_rate' in self._nondefaults: |
224 logging.warn('Shaping type, %s, ignores --packet_loss_rate=%s', | 226 logging.warn('Shaping type, %s, ignores --packet_loss_rate=%s', |
225 self.shaping_type, self.packet_loss_rate) | 227 self.shaping_type, self.packet_loss_rate) |
226 if 'init_cwnd' in self._nondefaults: | 228 if 'init_cwnd' in self._nondefaults: |
227 logging.warn('Shaping type, %s, ignores --init_cwnd=%s', | 229 logging.warn('Shaping type, %s, ignores --init_cwnd=%s', |
228 self.shaping_type, self.init_cwnd) | 230 self.shaping_type, self.init_cwnd) |
229 return kwargs | 231 return kwargs |
230 | 232 |
231 def _MassageValues(self): | 233 def _MassageValues(self): |
232 """Set options that depend on the values of other options.""" | 234 """Set options that depend on the values of other options.""" |
| 235 if self.append and not self.record: |
| 236 self._options.record = True |
233 for net_choice, values in self._NET_CONFIGS: | 237 for net_choice, values in self._NET_CONFIGS: |
234 if net_choice == self.net: | 238 if net_choice == self.net: |
235 self._options.down, self._options.up, self._options.delay_ms = values | 239 self._options.down, self._options.up, self._options.delay_ms = values |
236 self._nondefaults.update(['down', 'up', 'delay_ms']) | 240 self._nondefaults.update(['down', 'up', 'delay_ms']) |
237 if not self.shaping_port: | 241 if not self.shaping_port: |
238 self._options.shaping_port = self.port | 242 self._options.shaping_port = self.port |
239 if not self.ssl_shaping_port: | 243 if not self.ssl_shaping_port: |
240 self._options.ssl_shaping_port = self.ssl_port | 244 self._options.ssl_shaping_port = self.ssl_port |
241 if not self.ssl: | 245 if not self.ssl: |
242 self._options.certfile = None | 246 self._options.certfile = None |
(...skipping 29 matching lines...) Expand all Loading... |
272 else: | 276 else: |
273 cache_misses = cachemissarchive.CacheMissArchive( | 277 cache_misses = cachemissarchive.CacheMissArchive( |
274 options.cache_miss_file) | 278 options.cache_miss_file) |
275 if options.server: | 279 if options.server: |
276 AddDnsForward(server_manager, options.server) | 280 AddDnsForward(server_manager, options.server) |
277 else: | 281 else: |
278 host = platformsettings.get_server_ip_address(options.server_mode) | 282 host = platformsettings.get_server_ip_address(options.server_mode) |
279 real_dns_lookup = dnsproxy.RealDnsLookup( | 283 real_dns_lookup = dnsproxy.RealDnsLookup( |
280 name_servers=[platformsettings.get_original_primary_nameserver()]) | 284 name_servers=[platformsettings.get_original_primary_nameserver()]) |
281 if options.record: | 285 if options.record: |
282 http_archive = httparchive.HttpArchive() | 286 httparchive.HttpArchive.AssertWritable(replay_filename) |
283 http_archive.AssertWritable(replay_filename) | 287 if options.append and os.path.exists(replay_filename): |
| 288 http_archive = httparchive.HttpArchive.Load(replay_filename) |
| 289 logging.info('Appending to %s (loaded %d existing responses)', |
| 290 replay_filename, len(http_archive)) |
| 291 else: |
| 292 http_archive = httparchive.HttpArchive() |
284 else: | 293 else: |
285 http_archive = httparchive.HttpArchive.Load(replay_filename) | 294 http_archive = httparchive.HttpArchive.Load(replay_filename) |
286 logging.info('Loaded %d responses from %s', | 295 logging.info('Loaded %d responses from %s', |
287 len(http_archive), replay_filename) | 296 len(http_archive), replay_filename) |
288 server_manager.AppendRecordCallback(real_dns_lookup.ClearCache) | 297 server_manager.AppendRecordCallback(real_dns_lookup.ClearCache) |
289 server_manager.AppendRecordCallback(http_archive.clear) | 298 server_manager.AppendRecordCallback(http_archive.clear) |
290 | 299 |
291 if options.dns_forwarding: | 300 if options.dns_forwarding: |
292 if not options.server_mode: | 301 if not options.server_mode: |
293 AddDnsForward(server_manager, host) | 302 AddDnsForward(server_manager, host) |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 formatter=PlainHelpFormatter(), | 346 formatter=PlainHelpFormatter(), |
338 description=__doc__, | 347 description=__doc__, |
339 epilog='http://code.google.com/p/web-page-replay/') | 348 epilog='http://code.google.com/p/web-page-replay/') |
340 | 349 |
341 option_parser.add_option('--spdy', default=False, | 350 option_parser.add_option('--spdy', default=False, |
342 action='store_true', | 351 action='store_true', |
343 help='Replay via SPDY. (Can be combined with --no-ssl).') | 352 help='Replay via SPDY. (Can be combined with --no-ssl).') |
344 option_parser.add_option('-r', '--record', default=False, | 353 option_parser.add_option('-r', '--record', default=False, |
345 action='store_true', | 354 action='store_true', |
346 help='Download real responses and record them to replay_file') | 355 help='Download real responses and record them to replay_file') |
| 356 option_parser.add_option('--append', default=False, |
| 357 action='store_true', |
| 358 help='Append responses to replay_file.') |
347 option_parser.add_option('-l', '--log_level', default='debug', | 359 option_parser.add_option('-l', '--log_level', default='debug', |
348 action='store', | 360 action='store', |
349 type='choice', | 361 type='choice', |
350 choices=('debug', 'info', 'warning', 'error', 'critical'), | 362 choices=('debug', 'info', 'warning', 'error', 'critical'), |
351 help='Minimum verbosity level to log') | 363 help='Minimum verbosity level to log') |
352 option_parser.add_option('-f', '--log_file', default=None, | 364 option_parser.add_option('-f', '--log_file', default=None, |
353 action='store', | 365 action='store', |
354 type='string', | 366 type='string', |
355 help='Log file to use in addition to writting logs to stderr.') | 367 help='Log file to use in addition to writting logs to stderr.') |
356 option_parser.add_option('-e', '--cache_miss_file', default=None, | 368 option_parser.add_option('-e', '--cache_miss_file', default=None, |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 elif len(args) != 1: | 500 elif len(args) != 1: |
489 option_parser.error('Must specify a replay_file') | 501 option_parser.error('Must specify a replay_file') |
490 else: | 502 else: |
491 replay_filename = args[0] | 503 replay_filename = args[0] |
492 | 504 |
493 return replay(options, replay_filename) | 505 return replay(options, replay_filename) |
494 | 506 |
495 | 507 |
496 if __name__ == '__main__': | 508 if __name__ == '__main__': |
497 sys.exit(main()) | 509 sys.exit(main()) |
OLD | NEW |