Exemplo n.º 1
0
def MapSingleTrace(trace_handle, job, extra_import_options=None):
    assert (type(extra_import_options) is types.NoneType
            or type(extra_import_options) is types.DictType), (
                'extra_import_options should be a dict or None.')
    project = tracing_project.TracingProject()

    all_source_paths = list(project.source_paths)
    all_source_paths.append(project.trace_processor_root_path)

    result = mre_result.MreResult()

    with trace_handle.PrepareFileForProcessing() as prepared_trace_handle:
        js_args = [
            json.dumps(prepared_trace_handle.AsDict()),
            json.dumps(job.AsDict()),
        ]
        if extra_import_options:
            js_args.append(json.dumps(extra_import_options))

        res = vinn.RunFile(
            _MAP_SINGLE_TRACE_CMDLINE_PATH,
            source_paths=all_source_paths,
            js_args=js_args,
            # Use 8gb heap space to make sure we don't OOM'ed on big trace.
            v8_args=['--max-old-space-size=8192'])

    if res.returncode != 0:
        sys.stderr.write(res.stdout)
        result.AddFailure(
            failure.Failure(job, trace_handle.canonical_url, 'Error',
                            'vinn runtime error while mapping trace.',
                            'vinn runtime error while mapping trace.',
                            'Unknown stack'))
        return result

    for line in res.stdout.split('\n'):
        m = re.match('^MRE_RESULT: (.+)', line, re.DOTALL)
        if m:
            found_dict = json.loads(m.group(1))
            failures = [
                failure.Failure.FromDict(f, job,
                                         _FAILURE_NAME_TO_FAILURE_CONSTRUCTOR)
                for f in found_dict['failures']
            ]

            for f in failures:
                result.AddFailure(f)

            for k, v in found_dict['pairs'].iteritems():
                result.AddPair(k, v)

        else:
            if len(line) > 0:
                sys.stderr.write(line)
                sys.stderr.write('\n')

    if not (len(result.pairs) or len(result.failures)):
        raise InternalMapError('Internal error: No results were produced!')

    return result
Exemplo n.º 2
0
def CompareSamples(sample_a, sample_b, metric, data_format='chartjson'):
    """Compare the values of a metric from two samples from benchmark output.

  Args:
    sample_a, sample_b (str): comma-separated lists of paths to the benchmark
        output.
    metric (str): Metric name in slash-separated format [2 or 3 part].
    data_format (str): The format the samples are in. Supported values are:
        'chartjson', 'valueset', 'buildbot'.
  Returns:
    JSON encoded dict with the values parsed form the samples and the result of
    the hypothesis testing comparison of the samples under the 'result' key.
    Possible values for the result key are:
      'NEED_MORE_DATA', 'REJECT' and 'FAIL_TO_REJECT'.
    Where the null hypothesis is that the samples belong to the same population.
    i.e. a 'REJECT' result would make it reasonable to conclude that
    there is a significant difference between the samples. (e.g. a perf
    regression).
  """

    method = FORMAT_TO_METHOD[data_format]
    project = tracing_project.TracingProject()
    all_source_paths = list(project.source_paths)

    def MakeAbsPaths(l):
        return ','.join(map(os.path.abspath, l.split(',')))

    return vinn.RunFile(_COMPARE_SAMPLES_CMD_LINE,
                        source_paths=all_source_paths,
                        js_args=[
                            method,
                            MakeAbsPaths(sample_a),
                            MakeAbsPaths(sample_b), metric
                        ])
Exemplo n.º 3
0
def MapSingleTrace(results, trace_handle, map_function_handle):
  project = perf_insights_project.PerfInsightsProject()

  all_source_paths = list(project.source_paths)

  pi_path = os.path.abspath(os.path.join(os.path.dirname(__file__),
                                         '..'))
  all_source_paths.append(pi_path)
  run_info = trace_handle.run_info

  with trace_handle.Open() as trace_file:
    js_args = [
      json.dumps(run_info.AsDict()),
      json.dumps(map_function_handle.AsDict()),
      os.path.abspath(trace_file.name),
      json.dumps(run_info.metadata)
    ]

    res = vinn.RunFile(
      os.path.join(pi_path, 'perf_insights', 'map_single_trace_cmdline.html'),
      source_paths=all_source_paths,
      js_args=js_args)

  if res.returncode != 0:
    try:
      sys.stderr.write(res.stdout)
    except Exception:
      pass
    results.AddValue(value_module.FailureValue(
        run_info,
        'Error', 'vinn runtime error while mapping trace.',
        'vinn runtime error while mapping trace.', 'Unknown stack'))
    return


  found_at_least_one_result=False
  for line in res.stdout.split('\n'):
    m = re.match('^MAP_RESULT_VALUE: (.+)', line, re.DOTALL)
    if m:
      found_dict = json.loads(m.group(1))
      if found_dict['type'] == 'failure':
        cls = _FAILURE_NAME_TO_FAILURE_CONSTRUCTOR.get(found_dict['name'], None)
        if not cls:
          cls = value_module.FailureValue
      else:
        cls = value_module.Value
      found_value = cls.FromDict(run_info, found_dict)

      results.AddValue(found_value)
      found_at_least_one_result = True

    else:
      if len(line) > 0:
        sys.stderr.write(line)
        sys.stderr.write('\n')

  if found_at_least_one_result == False:
    raise InternalMapError('Internal error: No results were produced!')
Exemplo n.º 4
0
def MapSingleTrace(trace_handle, map_function_handle):
  project = perf_insights_project.PerfInsightsProject()

  all_source_paths = list(project.source_paths)

  pi_path = os.path.abspath(os.path.join(os.path.dirname(__file__),
                                         '..'))
  all_source_paths.append(pi_path)

  result = mre_result.MreResult()

  with trace_handle.PrepareFileForProcessing() as prepared_trace_handle:
    js_args = [
      json.dumps(prepared_trace_handle.AsDict()),
      json.dumps(map_function_handle.AsDict())
    ]

    res = vinn.RunFile(
      os.path.join(pi_path, 'perf_insights', 'map_single_trace_cmdline.html'),
      source_paths=all_source_paths,
      js_args=js_args)

  if res.returncode != 0:
    try:
      sys.stderr.write(res.stdout)
    except Exception:
      pass
    result.AddFailure(failure.Failure(
        map_function_handle.AsUserFriendlyString(), trace_handle.canonical_url,
        'Error', 'vinn runtime error while mapping trace.',
        'vinn runtime error while mapping trace.', 'Unknown stack'))
    return

  for line in res.stdout.split('\n'):
    m = re.match('^MRE_RESULT: (.+)', line, re.DOTALL)
    if m:
      found_dict = json.loads(m.group(1))
      failures = [failure.Failure.FromDict(
                    f, _FAILURE_NAME_TO_FAILURE_CONSTRUCTOR)
                  for f in found_dict['failures']]

      for f in failures:
        result.AddFailure(f)

      for k, v in found_dict['pairs'].iteritems():
        result.AddPair(k, v)

    else:
      if len(line) > 0:
        sys.stderr.write(line)
        sys.stderr.write('\n')

  if not (len(result.pairs) or len(result.failures)):
    raise InternalMapError('Internal error: No results were produced!')

  return result
Exemplo n.º 5
0
 def testRunFileStdoutPiping(self):
     file_path = self.GetTestFilePath('simple.js')
     tmp_dir = tempfile.mkdtemp()
     try:
         temp_file_name = os.path.join(tmp_dir, 'out_file')
         with open(temp_file_name, 'w') as f:
             vinn.RunFile(file_path, stdout=f)
         with open(temp_file_name, 'r') as f:
             self.assertEquals(f.read(), 'Hello W0rld from simple.js\n')
     finally:
         shutil.rmtree(tmp_dir)
Exemplo n.º 6
0
def ReduceMapResults(job_results, key, file_handle, job):
    project = perf_insights_project.PerfInsightsProject()

    all_source_paths = list(project.source_paths)
    all_source_paths.append(project.perf_insights_root_path)

    with file_handle.PrepareFileForProcessing() as prepared_file_handle:
        js_args = [
            key,
            json.dumps(prepared_file_handle.AsDict()),
            json.dumps(job.AsDict()),
        ]

        res = vinn.RunFile(_REDUCE_MAP_RESULTS_CMDLINE_PATH,
                           source_paths=all_source_paths,
                           js_args=js_args)

    if res.returncode != 0:
        try:
            sys.stderr.write(res.stdout)
        except Exception:
            pass
        job_results.AddFailure(
            failure.Failure(job, job.map_function_handle, None, 'Error',
                            'vinn runtime error while reducing results.',
                            'Unknown stack'))
        return

    for line in res.stdout.split('\n'):
        m = re.match('^JOB_(RESULTS|FAILURE): (.+)', line, re.DOTALL)
        if m:
            found_type = m.group(1)
            found_dict = json.loads(m.group(2))
            if found_type == 'FAILURE':
                try:
                    sys.stderr.write(res.stdout)
                except Exception:
                    pass
                job_results.AddFailure(
                    failure.Failure(
                        job, job.map_function_handle, None, 'Error',
                        'vinn runtime error while reducing results.',
                        'Unknown stack'))

            elif found_type == 'RESULTS':
                job_results.AddPair(key, found_dict[key])
        else:
            if len(line) > 0:
                sys.stderr.write(line)
                sys.stderr.write('\n')

    if len(job_results.pairs) == 0 and len(job_results.failures) == 0:
        raise map_single_trace.InternalMapError(
            'Internal error: No results were produced!')
Exemplo n.º 7
0
def ConvertChartJson(chart_json):
    """Convert chart_json to Histograms.

  Args:
    chart_json: path to a file containing chart-json

  Returns:
    a Vinn result object whose 'returncode' indicates whether there was an
    exception, and whose 'stdout' contains HistogramSet json.
  """
    return vinn.RunFile(
        os.path.join(os.path.dirname(__file__),
                     'convert_chart_json_cmdline.html'),
        source_paths=tracing_project.TracingProject().source_paths,
        js_args=[os.path.abspath(chart_json)])
def HistogramsToCsv(json_path):
    """Convert HistogramSet JSON to CSV.

  Args:
    json_path: path to a file containing HistogramSet JSON

  Returns:
    a Vinn result object whose 'returncode' indicates whether there was an
    exception, and whose 'stdout' contains CSV.
  """
    return vinn.RunFile(os.path.join(os.path.dirname(__file__),
                                     'histograms_to_csv_cmdline.html'),
                        source_paths=list(
                            tracing_project.TracingProject().source_paths),
                        js_args=[os.path.abspath(json_path)])
Exemplo n.º 9
0
def MergeHistograms(json_path):
  """Merge Histograms.

  Args:
    json_path: Path to a HistogramSet JSON file.
  Returns:
    HistogramSet dicts of the merged Histograms.
  """
  result = vinn.RunFile(
      _MERGE_HISTOGRAMS_CMD_LINE,
      source_paths=list(tracing_project.TracingProject().source_paths),
      js_args=[os.path.abspath(json_path)])
  if result.returncode != 0:
    sys.stderr.write(result.stdout)
    raise Exception('vinn merge_histograms_cmdline.html returned ' +
                    str(result.returncode))
  return json.loads(result.stdout)
Exemplo n.º 10
0
def MergeHistograms(json_path, groupby=()):
  """Merge Histograms.

  Args:
    json_path: Path to a HistogramSet JSON file.
    groupby: Array of grouping keys (name, benchmark, time, storyset_repeat,
             story_repeat, story, label)
  Returns:
    HistogramSet dicts of the merged Histograms.
  """
  result = vinn.RunFile(
      _MERGE_HISTOGRAMS_CMD_LINE,
      source_paths=list(tracing_project.TracingProject().source_paths),
      js_args=[os.path.abspath(json_path)] + list(groupby))
  if result.returncode != 0:
    sys.stderr.write(result.stdout)
    raise Exception('vinn merge_histograms_cmdline.html returned ' +
                    str(result.returncode))
  return json.loads(result.stdout)
Exemplo n.º 11
0
def DiscoverMetrics(modules_to_load):
    """ Returns a list of registered metrics.

  Args:
    modules_to_load: a list of modules (string) to be loaded before discovering
      the registered metrics.
  """
    assert isinstance(modules_to_load, list)
    project = tracing_project.TracingProject()
    all_source_paths = list(project.source_paths)

    res = vinn.RunFile(_DISCOVER_CMD_LINE,
                       source_paths=all_source_paths,
                       js_args=modules_to_load)

    if res.returncode != 0:
        raise RuntimeError('Error running metrics_discover_cmdline: ' +
                           res.stdout)
    else:
        return [str(m) for m in json.loads(res.stdout)]
Exemplo n.º 12
0
def main():
    # Create argument parser
    parser = argparse.ArgumentParser()
    parser.add_argument('systrace_file',
                        metavar='SYSTRACE_FILE',
                        help='systrace file to analyze')
    parser.add_argument('-e',
                        metavar='EVENT_LOG',
                        help='android event log file')
    args = parser.parse_args()

    this_script_path = os.path.dirname(os.path.realpath(__file__))

    # Find chromium-trace directory and vinn binary as offset from this script
    chromium_trace_path = os.path.normpath(this_script_path +
                                           '/../../../external/chromium-trace')
    if not os.path.exists(chromium_trace_path):
        sys.exit('Can\'t find chromium-trace in your source tree')

    vinn_path = chromium_trace_path + '/catapult/third_party/vinn/'
    if not os.path.exists(vinn_path):
        sys.exit('Can\'t find vinn in your source tree')

    sys.path.append(vinn_path)
    import vinn

    # Find source paths and construct vinn launch arguments
    tracing_path = chromium_trace_path + '/catapult/tracing/'
    gldist_path = chromium_trace_path + '/catapult/tracing/third_party/gl-matrix/dist/'
    source_paths_arg = [tracing_path, gldist_path]
    js_args_arg = [args.systrace_file]
    if args.e is not None:
        js_args_arg += [args.e]
    res = vinn.RunFile(this_script_path + '/analysis.html',
                       source_paths=source_paths_arg,
                       js_args=js_args_arg,
                       stdout=sys.stdout,
                       stdin=sys.stdin)
    return res.returncode
Exemplo n.º 13
0
 def testRunFileWithV8Args(self):
     file_path = self.GetTestFilePath('simple.js')
     vinn.RunFile(file_path, v8_args=['--foo', '--bar=True'])
     v8_args = self.mock_popen.call_args[0][0]
     self.assertIn('--foo', v8_args)
Exemplo n.º 14
0
 def testQuit274Handling(self):
     file_path = self.GetTestFilePath('quit_274_test.js')
     res = vinn.RunFile(file_path, source_paths=[self.test_data_dir])
     self.assertEquals(res.returncode, 238)
Exemplo n.º 15
0
def MapSingleTrace(trace_handle, job, extra_import_options=None, timeout=None):
    assert (isinstance(
        extra_import_options,
        (type(None),
         dict))), ('extra_import_options should be a dict or None.')
    project = tracing_project.TracingProject()

    all_source_paths = list(project.source_paths)
    all_source_paths.append(project.trace_processor_root_path)

    result = mre_result.MreResult()

    with trace_handle.PrepareFileForProcessing() as prepared_trace_handle:
        js_args = [
            json.dumps(prepared_trace_handle.AsDict()),
            json.dumps(job.AsDict()),
        ]
        if extra_import_options:
            js_args.append(json.dumps(extra_import_options))

        # Use 8gb heap space to make sure we don't OOM'ed on big trace, but not
        # on ARM devices since we use 32-bit d8 binary.
        if platform.machine() == 'armv7l' or platform.machine() == 'aarch64':
            v8_args = None
        else:
            v8_args = ['--max-old-space-size=8192']

        try:
            res = vinn.RunFile(_MAP_SINGLE_TRACE_CMDLINE_PATH,
                               source_paths=all_source_paths,
                               js_args=js_args,
                               v8_args=v8_args,
                               timeout=timeout)
        except RuntimeError as e:
            result.AddFailure(
                failure.Failure(job, trace_handle.canonical_url, 'Error',
                                'vinn runtime error while mapping trace.',
                                e.message, 'Unknown stack'))
            return result

    stdout = res.stdout
    if not isinstance(stdout, str):
        stdout = stdout.decode('utf-8', errors='replace')

    if res.returncode != 0:
        sys.stderr.write(stdout)
        result.AddFailure(
            failure.Failure(job, trace_handle.canonical_url, 'Error',
                            'vinn runtime error while mapping trace.',
                            'vinn runtime error while mapping trace.',
                            'Unknown stack'))
        return result

    for line in stdout.split('\n'):
        m = re.match('^MRE_RESULT: (.+)', line, re.DOTALL)
        if m:
            found_dict = json.loads(m.group(1))
            failures = [
                failure.Failure.FromDict(f, job,
                                         _FAILURE_NAME_TO_FAILURE_CONSTRUCTOR)
                for f in found_dict['failures']
            ]

            for f in failures:
                result.AddFailure(f)

            for k, v in found_dict['pairs'].items():
                result.AddPair(k, v)

        else:
            if len(line) > 0:
                sys.stderr.write(line)
                sys.stderr.write('\n')

    if not (len(result.pairs) or len(result.failures)):
        raise InternalMapError('Internal error: No results were produced!')

    return result