コード例 #1
0
def main():
  all_metrics = discover.DiscoverMetrics(
      ['/tracing/metrics/all_metrics.html'])

  parser = argparse.ArgumentParser(
      description='Runs metrics on a local trace')
  parser.add_argument('--local-trace-path', type=str,
                      help='The local path to the trace file')
  parser.add_argument('--cloud-trace-link', type=str,
                      help=('Cloud link from where the local trace file was '
                            'downloaded from'))
  parser.add_argument('--metric-name', type=str,
                      help=('Function name of registered metric '
                            '(not filename.) Available metrics are: %s' %
                            ', '.join(all_metrics)))
  parser.add_argument('--output-csv', default='results', type=str,
                      help='Output CSV file path')

  args = parser.parse_args()

  trace_size_in_mib = os.path.getsize(args.local_trace_path) / (2 ** 20)
  # Bails out on trace that are too big. See crbug.com/812631 for more details.
  if trace_size_in_mib > 400:
    print('Trace size is too big: %s MiB' % trace_size_in_mib)
    return 1

  logging.warning('Starting to compute metrics on trace')
  start = time.time()
  mre_result = metric_runner.RunMetric(
      args.local_trace_path, [args.metric_name], {},
      report_progress=False,
      canonical_url=args.cloud_trace_link)
  logging.warning('Processing resulting traces took %.3f seconds' % (
      time.time() - start))

  for f in mre_result.failures:
    print('Running metric failed:')
    print(f.stack)
    return 1

  with tempfile.NamedTemporaryFile() as temp:
    json.dump(mre_result.pairs.get('histograms', []), temp, indent=2,
              sort_keys=True, separators=(',', ': '))
    temp.flush()

    result = histograms_to_csv.HistogramsToCsv(temp.name)
    if result.returncode != 0:
      print('histograms_to_csv.HistogramsToCsv returned %d' % result.returncode)
      return result.returncode
    else:
      with open(args.output_csv, 'w') as f:
        f.write(result.stdout.rstrip())
      print('Output CSV created in file://' + args.output_csv)
コード例 #2
0
    def Format(self, page_test_results):
        histograms = page_test_results.AsHistogramDicts()
        file_descriptor, json_path = tempfile.mkstemp()
        os.close(file_descriptor)
        json.dump(histograms, file(json_path, 'w'))
        vinn_result = histograms_to_csv.HistogramsToCsv(json_path)
        dicts = _ReadCsv(vinn_result.stdout)

        self._output_stream.seek(0)
        if not self._reset_results:
            dicts += _ReadCsv(self._output_stream.read())
            self._output_stream.seek(0)
        _WriteCsv(dicts, self._output_stream)
        self._output_stream.truncate()
コード例 #3
0
def ProcessHistogramDicts(histogram_dicts, options):
    """Convert histogram dicts to CSV and write output in output_dir."""
    with tempfile_ext.NamedTemporaryFile() as hist_file:
        json.dump(histogram_dicts, hist_file)
        hist_file.close()
        vinn_result = histograms_to_csv.HistogramsToCsv(hist_file.name)
        csv_dicts = _ReadCsv(vinn_result.stdout.splitlines())

    output_file = os.path.join(options.output_dir, OUTPUT_FILENAME)
    if not options.reset_results and os.path.isfile(output_file):
        with open(output_file) as input_stream:
            csv_dicts += _ReadCsv(input_stream)

    with open(output_file, 'w') as output_stream:
        _WriteCsv(csv_dicts, output_stream)