def statsFor(name, filters='wc -l'): cmd = 'grep "DevTools console .%s." "%s"' % (name, out_file) cmd += ' | ' + filters output = shell(cmd) or '0' if len(output) > 7: cli_helpers.Info(' %-26s%s' % ('[%s]:' % name, cmd)) cli_helpers.Info(' ' + output.replace('\n', '\n ')) else: cli_helpers.Info(' %-16s%-8s %s' % ('[%s]:' % name, output, cmd))
def _PrintRunInfo(out_file, chrome_log_file=False, results_details=True): try: if results_details: _PrintResultsHTMLInfo(out_file) except Exception as e: cli_helpers.Error('Could not print results.html tests: %s' % e) cli_helpers.Info('Stdout/Stderr Log: %s' % out_file) if chrome_log_file: cli_helpers.Info('Chrome Log: %s.chrome.log' % out_file) cli_helpers.Info(' Total output: %d' % _CountLogLines(out_file)) cli_helpers.Info(' Total Console: %d' % _CountLogLines(out_file, r'DevTools console')) cli_helpers.Info(' [security]: %d' % _CountLogLines(out_file, r'DevTools console .security.')) cli_helpers.Info(' [network]: %d' % _CountLogLines(out_file, r'DevTools console .network.')) chrome_log = '%s.chrome.log' % out_file if os.path.isfile(chrome_log): cli_helpers.Info(' [javascript]: %d' % _CountLogLines(chrome_log, r'Uncaught .*Error')) if results_details: missing_urls = _ExtractMissingURLsFromLog(out_file) if missing_urls: cli_helpers.Info('Missing URLs in the archive:') for missing_url in missing_urls: cli_helpers.Info(' - %s' % missing_url)
def _StartPinpointJob(self, configuration): """Creates, starts a Pinpoint job and returns its URL.""" try: resp = pinpoint_service.NewJob( start_git_hash='HEAD', end_git_hash='HEAD', target='performance_test_suite', patch=self._GetBranchIssueUrl(), bug_id=self.bug_id or '', story=self.story, extra_test_args='--pageset-repeat=%d' % self.repeat, configuration=configuration, benchmark='system_health.common_%s' % ('desktop' if self._IsDesktop() else 'mobile')) except request.RequestError as e: cli_helpers.Comment( 'Failed to start a Pinpoint job for {config} automatically:\n {err}', config=configuration, err=e.content) return cli_helpers.Info('Started a Pinpoint job for {configuration} at {url}', configuration=configuration, url=resp['jobUrl']) return resp['jobUrl']
def _PrintResultsHTMLInfo(out_file): results_file = out_file + '.results.html' histogram_json = out_file + '.hist.json' histogram_csv = out_file + '.hist.csv' cli_helpers.Run([RESULTS2JSON, results_file, histogram_json], env=_PrepareEnv()) cli_helpers.Run([HISTOGRAM2CSV, histogram_json, histogram_csv], env=_PrepareEnv()) cli_helpers.Info('Metrics results: file://{path}', path=results_file) names = set([ 'console:error:network', 'console:error:js', 'console:error:all', 'console:error:security' ]) with open(histogram_csv) as f: for line in f.readlines(): line = line.split(',') if line[0] in names: cli_helpers.Info(' %-26s%s' % ('[%s]:' % line[0], line[2]))
def _DeleteExistingWpr(self): """Deletes current WPR archive.""" archive, used_elsewhere = self._ExistingWpr() if archive is None or used_elsewhere: return cli_helpers.Info('Deleting WPR: {archive}', archive=archive) if os.path.exists(archive): os.remove(archive) archive_sha1 = archive + '.sha1' if os.path.exists(archive_sha1): os.remove(archive_sha1)
def _PrintRunInfo(self, out_file, results_details=True): try: if results_details: _PrintResultsHTMLInfo(out_file) except Exception as e: cli_helpers.Error('Could not print results.html tests: %s' % e) def shell(cmd): return subprocess.check_output(cmd, shell=True).rstrip() def statsFor(name, filters='wc -l'): cmd = 'grep "DevTools console .%s." "%s"' % (name, out_file) cmd += ' | ' + filters output = shell(cmd) or '0' if len(output) > 7: cli_helpers.Info(' %-26s%s' % ('[%s]:' % name, cmd)) cli_helpers.Info(' ' + output.replace('\n', '\n ')) else: cli_helpers.Info(' %-16s%-8s %s' % ('[%s]:' % name, output, cmd)) cli_helpers.Info('Stdout/Stderr Log: %s' % out_file) if self._IsDesktop( ): # Mobile test runner does not product the log file. cli_helpers.Info('Chrome Log: %s.chrome.log' % out_file) cli_helpers.Info( ' Total output: %s' % subprocess.check_output(['wc', '-l', out_file]).rstrip()) cli_helpers.Info( ' Total Console: %s' % shell('grep "DevTools console" "%s" | wc -l' % out_file)) statsFor('security') statsFor('network', 'cut -d " " -f 20- | sort | uniq -c | sort -nr') chrome_log = '%s.chrome.log' % out_file if os.path.isfile(chrome_log): cmd = 'grep "Uncaught .*Error" "%s"' % chrome_log count = shell(cmd + '| wc -l') cli_helpers.Info(' %-16s%-8s %s' % ('[javascript]:', count, cmd))
def testPrintsInfo(self, print_mock): cli_helpers.Info('foo {sval} {ival}', sval='s', ival=42) print_mock.assert_called_once_with('foo s 42')