[telemetry] Adding --output-format option to enable more user-friendly output.

BUG=162923


Review URL: https://chromiumcodereview.appspot.com/11348284

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@170678 0039d316-1c4b-4281-b951-d872f2087c98
parent 52e97402
...@@ -86,21 +86,16 @@ results! You must return the same dict keys every time.""" ...@@ -86,21 +86,16 @@ results! You must return the same dict keys every time."""
PrintPerfResult(measurement, trace, values, units, data_type) PrintPerfResult(measurement, trace, values, units, data_type)
class CsvBenchmarkResults(BenchmarkResults): class IncrementalBenchmarkResults(BenchmarkResults):
def __init__(self, results_writer): def __init__(self):
super(CsvBenchmarkResults, self).__init__() super(IncrementalBenchmarkResults, self).__init__()
self._results_writer = results_writer self._did_process_header = False
self._did_write_header = False
def DidMeasurePage(self): def DidMeasurePage(self):
super(CsvBenchmarkResults, self).DidMeasurePage() super(IncrementalBenchmarkResults, self).DidMeasurePage()
if not self._did_write_header: if not self._did_process_header:
self._did_write_header = True self.ProcessHeader()
row = ['url']
for name in self.field_names:
row.append('%s (%s)' % (name, self.field_units[name]))
self._results_writer.writerow(row)
row = [self._page.url] row = [self._page.url]
for name in self.field_names: for name in self.field_names:
...@@ -112,8 +107,46 @@ class CsvBenchmarkResults(BenchmarkResults): ...@@ -112,8 +107,46 @@ class CsvBenchmarkResults(BenchmarkResults):
row.append(_Mean(value)) row.append(_Mean(value))
else: else:
row.append(value) row.append(value)
self.OutputRow(row)
def OutputRow(self, row):
raise NotImplementedError()
def ProcessHeader(self):
raise NotImplementedError()
class CsvBenchmarkResults(IncrementalBenchmarkResults):
def __init__(self, results_writer):
super(CsvBenchmarkResults, self).__init__()
self._results_writer = results_writer
def OutputRow(self, row):
self._results_writer.writerow(row) self._results_writer.writerow(row)
def ProcessHeader(self):
self._did_process_header = True
row = ['url']
for name in self.field_names:
row.append('%s (%s)' % (name, self.field_units[name]))
self.OutputRow(row)
class TerminalBlockBenchmarkResults(IncrementalBenchmarkResults):
def __init__(self, output_location):
super(TerminalBlockBenchmarkResults, self).__init__()
self._output_location = output_location
self._header_row = None
def OutputRow(self, row):
for i in range(len(row)):
print >> self._output_location, '%s:' % self._header_row[i], row[i]
print >> self._output_location
def ProcessHeader(self):
self._did_process_header = True
self._header_row = ['url']
for name in self.field_names:
self._header_row.append('%s (%s)' % (name, self.field_units[name]))
# TODO(nduca): Rename to page_benchmark # TODO(nduca): Rename to page_benchmark
class MultiPageBenchmark(page_test.PageTest): class MultiPageBenchmark(page_test.PageTest):
......
...@@ -34,6 +34,12 @@ def Main(benchmark_dir): ...@@ -34,6 +34,12 @@ def Main(benchmark_dir):
options = browser_options.BrowserOptions() options = browser_options.BrowserOptions()
parser = options.CreateParser('%prog [options] <benchmark> <page_set>') parser = options.CreateParser('%prog [options] <benchmark> <page_set>')
parser.add_option('--output-format',
dest='output_format',
default='csv',
help='Output format. Can be "csv" or "terminal-block". '
'Defaults to "%default".')
benchmark = None benchmark = None
if benchmark_name is not None: if benchmark_name is not None:
benchmark = benchmarks[benchmark_name]() benchmark = benchmarks[benchmark_name]()
...@@ -60,7 +66,15 @@ def Main(benchmark_dir): ...@@ -60,7 +66,15 @@ def Main(benchmark_dir):
Use --browser=list to figure out which are available.\n""" Use --browser=list to figure out which are available.\n"""
sys.exit(1) sys.exit(1)
results = multi_page_benchmark.CsvBenchmarkResults(csv.writer(sys.stdout)) if options.output_format == 'csv':
results = multi_page_benchmark.CsvBenchmarkResults(csv.writer(sys.stdout))
elif options.output_format == 'terminal-block':
results = multi_page_benchmark.TerminalBlockBenchmarkResults(sys.stdout)
else:
raise Exception('Invalid --output-format value: "%s". Valid values are '
'"csv" and "terminal-block".'
% options.output_format)
with page_runner.PageRunner(ps) as runner: with page_runner.PageRunner(ps) as runner:
runner.Run(options, possible_browser, benchmark, results) runner.Run(options, possible_browser, benchmark, results)
# When using an exact executable, assume it is a reference build for the # When using an exact executable, assume it is a reference build for the
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment