| Index: tools/telemetry/telemetry/page/page_runner.py
|
| diff --git a/tools/telemetry/telemetry/page/page_runner.py b/tools/telemetry/telemetry/page/page_runner.py
|
| index 9ec2d348dc654ad955b6ad52f8ae083897ba6601..b29903aad41afcd4e187624cf10914fffc5df00d 100644
|
| --- a/tools/telemetry/telemetry/page/page_runner.py
|
| +++ b/tools/telemetry/telemetry/page/page_runner.py
|
| @@ -71,7 +71,6 @@ class _RunState(object):
|
|
|
| if self.first_page:
|
| self.first_page = False
|
| - test.WillRunPageSet(self.tab)
|
|
|
| def StopBrowser(self):
|
| self._is_tracing = False
|
| @@ -91,7 +90,8 @@ class _RunState(object):
|
|
|
| def StartProfiling(self, page, options):
|
| output_file = os.path.join(options.profiler_dir, page.url_as_file_safe_name)
|
| - if options.page_repeat != 1 or options.pageset_repeat != 1:
|
| + if (options.page_repeat_iters != 1 or options.pageset_repeat_iters != 1 or
|
| + options.page_repeat_secs or options.pageset_repeat_secs):
|
| output_file = _GetSequentialFileName(output_file)
|
| self.browser.StartProfiling(options, output_file)
|
|
|
| @@ -116,7 +116,8 @@ class _RunState(object):
|
| logging.info('Processing trace...')
|
|
|
| trace_file = os.path.join(options.trace_dir, page.url_as_file_safe_name)
|
| - if options.page_repeat != 1 or options.pageset_repeat != 1:
|
| + if (options.page_repeat_iters != 1 or options.pageset_repeat_iters != 1 or
|
| + options.page_repeat_secs or options.pageset_repeat_secs):
|
| trace_file = _GetSequentialFileName(trace_file)
|
| trace_file += '.json'
|
|
|
| @@ -165,6 +166,95 @@ def AddCommandLineOptions(parser):
|
| page_filter_module.PageFilter.AddCommandLineOptions(parser)
|
|
|
|
|
| +def _PrepareAndRunPage(test, page_set, options, page, credentials_path,
|
| + possible_browser, results, state):
|
| + if options.wpr_mode != wpr_modes.WPR_RECORD:
|
| + if page.archive_path and os.path.isfile(page.archive_path):
|
| + possible_browser.options.wpr_mode = wpr_modes.WPR_REPLAY
|
| + else:
|
| + possible_browser.options.wpr_mode = wpr_modes.WPR_OFF
|
| + results_for_current_run = results
|
| + if state.first_page and test.discard_first_result:
|
| + # If discarding results, substitute a dummy object.
|
| + results_for_current_run = type(results)()
|
| + results_for_current_run.StartTest(page)
|
| + tries = 3
|
| + while tries:
|
| + try:
|
| + state.StartBrowser(test, page_set, page, possible_browser,
|
| + credentials_path, page.archive_path)
|
| +
|
| + _WaitForThermalThrottlingIfNeeded(state.browser.platform)
|
| +
|
| + if options.trace_dir:
|
| + state.StartTracing()
|
| + if options.profiler_dir:
|
| + state.StartProfiling(page, options)
|
| +
|
| + try:
|
| + _RunPage(test, page, state.tab, results_for_current_run, options)
|
| + _CheckThermalThrottling(state.browser.platform)
|
| + except exceptions.TabCrashException:
|
| + stdout = ''
|
| + if not options.show_stdout:
|
| + stdout = state.browser.GetStandardOutput()
|
| + stdout = (('\nStandard Output:\n') +
|
| + ('*' * 80) +
|
| + '\n\t' + stdout.replace('\n', '\n\t') + '\n' +
|
| + ('*' * 80))
|
| + logging.warning('Tab crashed: %s%s', page.url, stdout)
|
| + state.StopBrowser()
|
| +
|
| + if options.trace_dir:
|
| + state.StopTracing(page, options)
|
| + if options.profiler_dir:
|
| + state.StopProfiling()
|
| +
|
| + if test.NeedsBrowserRestartAfterEachRun(state.tab):
|
| + state.StopBrowser()
|
| +
|
| + break
|
| + except exceptions.BrowserGoneException:
|
| + logging.warning('Lost connection to browser. Retrying.')
|
| + state.StopBrowser()
|
| + tries -= 1
|
| + if not tries:
|
| + logging.error('Lost connection to browser 3 times. Failing.')
|
| + raise
|
| + results_for_current_run.StopTest(page)
|
| +
|
| +
|
| +def _RunRepeatLoop(test, page_set, options, credentials_path, possible_browser,
|
| + results, state, pages):
|
| + """Repeats each page or pageset for a specified time or iteration limit.
|
| +
|
| + Uses the '--pageset-repeat' and '--page-repeat' cmd line options.
|
| + """
|
| + pageset_start_time = time.time()
|
| + pageset_iters = 0
|
| + while True:
|
| + if (options.pageset_repeat_secs and
|
| + time.time() - pageset_start_time > options.pageset_repeat_secs):
|
| + break
|
| + elif (options.pageset_repeat_iters != 1 and
|
| + pageset_iters >= options.pageset_repeat_iters):
|
| + break
|
| + pageset_iters += 1
|
| + for page in pages:
|
| + page_start_time = time.time()
|
| + page_iters = 0
|
| + while True:
|
| + if (options.page_repeat_secs and
|
| + time.time() - page_start_time > options.page_repeat_secs):
|
| + break
|
| + elif (options.page_repeat_iters != 1 and
|
| + page_iters >= options.page_repeat_iters):
|
| + break
|
| + page_iters += 1
|
| + _PrepareAndRunPage(test, page_set, options, page, credentials_path,
|
| + possible_browser, results, state)
|
| +
|
| +
|
| def Run(test, page_set, options):
|
| """Runs a given test against a given page_set with the given options."""
|
| results = test.PrepareResults(options)
|
| @@ -203,65 +293,12 @@ def Run(test, page_set, options):
|
|
|
| state = _RunState()
|
| # TODO(dtu): Move results creation and results_for_current_run into RunState.
|
| - results_for_current_run = results
|
|
|
| try:
|
| - for page in pages:
|
| - if options.wpr_mode != wpr_modes.WPR_RECORD:
|
| - if page.archive_path and os.path.isfile(page.archive_path):
|
| - possible_browser.options.wpr_mode = wpr_modes.WPR_REPLAY
|
| - else:
|
| - possible_browser.options.wpr_mode = wpr_modes.WPR_OFF
|
| - results_for_current_run = results
|
| - if state.first_page and test.discard_first_result:
|
| - # If discarding results, substitute a dummy object.
|
| - results_for_current_run = type(results)()
|
| - results_for_current_run.StartTest(page)
|
| - tries = 3
|
| - while tries:
|
| - try:
|
| - state.StartBrowser(test, page_set, page, possible_browser,
|
| - credentials_path, page.archive_path)
|
| -
|
| - _WaitForThermalThrottlingIfNeeded(state.browser.platform)
|
| -
|
| - if options.trace_dir:
|
| - state.StartTracing()
|
| - if options.profiler_dir:
|
| - state.StartProfiling(page, options)
|
| -
|
| - try:
|
| - _RunPage(test, page, state.tab, results_for_current_run, options)
|
| - _CheckThermalThrottling(state.browser.platform)
|
| - except exceptions.TabCrashException:
|
| - stdout = ''
|
| - if not options.show_stdout:
|
| - stdout = state.browser.GetStandardOutput()
|
| - stdout = (('\nStandard Output:\n') +
|
| - ('*' * 80) +
|
| - '\n\t' + stdout.replace('\n', '\n\t') + '\n' +
|
| - ('*' * 80))
|
| - logging.warning('Tab crashed: %s%s', page.url, stdout)
|
| - state.StopBrowser()
|
| -
|
| - if options.trace_dir:
|
| - state.StopTracing(page, options)
|
| - if options.profiler_dir:
|
| - state.StopProfiling()
|
| -
|
| - if test.NeedsBrowserRestartAfterEachRun(state.tab):
|
| - state.StopBrowser()
|
| -
|
| - break
|
| - except exceptions.BrowserGoneException:
|
| - logging.warning('Lost connection to browser. Retrying.')
|
| - state.StopBrowser()
|
| - tries -= 1
|
| - if not tries:
|
| - logging.error('Lost connection to browser 3 times. Failing.')
|
| - raise
|
| - results_for_current_run.StopTest(page)
|
| - test.DidRunPageSet(state.tab, results_for_current_run)
|
| + test.WillRunTest(state.tab)
|
| + _RunRepeatLoop(test, page_set, options, credentials_path, possible_browser,
|
| + results, state, pages)
|
| + test.DidRunTest(state.tab, results)
|
| finally:
|
| state.StopBrowser()
|
|
|
| @@ -281,10 +318,8 @@ def _ShuffleAndFilterPageSet(page_set, options):
|
|
|
| if options.pageset_shuffle:
|
| random.Random().shuffle(pages)
|
| - return [page
|
| - for _ in xrange(int(options.pageset_repeat))
|
| - for page in pages
|
| - for _ in xrange(int(options.page_repeat))]
|
| +
|
| + return pages
|
|
|
|
|
| def _CheckArchives(page_set, pages, results):
|
|
|