Ejemplo n.º 1
0
def RunMetricOnTraces(filenames, metrics,
                      extra_import_options=None, report_progress=True):
  trace_handles = []
  for filename in filenames:
    filename_url = 'file://' + filename
    trace_handles.append(file_handle.URLFileHandle(filename_url, filename_url))

  return RunMetricOnTraceHandles(trace_handles, metrics, extra_import_options,
                                 report_progress)
Ejemplo n.º 2
0
def RunMetric(filename, metrics, extra_import_options=None,
              report_progress=True, canonical_url=None):
  filename_url = 'file://' + filename
  if canonical_url is None:
    canonical_url = filename_url
  trace_handle = file_handle.URLFileHandle(canonical_url, filename_url)
  result = RunMetricOnTraceHandles(
      [trace_handle], metrics, extra_import_options, report_progress)
  return result[canonical_url]
Ejemplo n.º 3
0
def RunMetricOnTraces(filenames, metrics, extra_import_options=None):
    trace_handles = [
        file_handle.URLFileHandle(f, 'file://%s' % f) for f in filenames
    ]
    job = _GetMetricRunnerHandle(metrics)
    runner = map_runner.MapRunner(
        trace_handles,
        job,
        extra_import_options=extra_import_options,
        progress_reporter=gtest_progress_reporter.GTestProgressReporter())
    map_results = runner.RunMapper()
    return map_results
Ejemplo n.º 4
0
def RunMetricOnSingleTrace(filename, metrics, extra_import_options=None,
                           canonical_url=None):
  """A simplified RunMetric() that skips using MapRunner.

  This avoids the complexity of multithreading and progress
  reporting.
  """
  filename_url = 'file://' + filename
  if canonical_url is None:
    canonical_url = filename_url
  trace_handle = file_handle.URLFileHandle(canonical_url, filename_url)
  job = _GetMetricRunnerHandle(metrics)
  return map_single_trace.MapSingleTrace(
      trace_handle, job, extra_import_options=extra_import_options)
    def GetTraceHandles(self):
        trace_handles = []

        files = _GetFilesIn(self.directory)
        for rel_filename in files:
            filename = os.path.join(self.directory, rel_filename)

            url = self.url_resolver(filename)
            if url is None:
                url = _DefaultUrlResover(filename)

            th = file_handle.URLFileHandle(url, 'file://' + filename)
            trace_handles.append(th)

        return trace_handles
Ejemplo n.º 6
0
def ExecuteTraceMappingCode(trace_file_path,
                            process_trace_func_code,
                            extra_import_options=None,
                            trace_canonical_url=None):
    """Execute |process_trace_func_code| on the input |trace_file_path|.

  process_trace_func_code must contain a function named 'process_trace' with
  signature as follows:

    function processTrace(results, model) {
       // call results.addPair(<key>, <value>) to add data to results object.
    }

  Whereas results is an instance of tr.mre.MreResult, and model is an instance
  of tr.model.Model which was resulted from parsing the input trace.

  Returns:
    This function returns the dictionay that represents data collected in
    |results|.

  Raises:
    RuntimeError if there is any error with execute trace mapping code.
  """

    with TemporaryMapScript("""
     //# sourceURL=processTrace
      %s;
      tr.mre.FunctionRegistry.register(processTrace);
  """ % process_trace_func_code) as map_script:
        handle = function_handle.FunctionHandle(
            [function_handle.ModuleToLoad(filename=map_script.filename)],
            function_name='processTrace')
        mapping_job = job_module.Job(handle)
        trace_file_path = os.path.abspath(trace_file_path)
        if not trace_canonical_url:
            trace_canonical_url = 'file://%s' % trace_file_path
        trace_handle = file_handle.URLFileHandle(trace_file_path,
                                                 trace_canonical_url)
        results = MapSingleTrace(trace_handle, mapping_job,
                                 extra_import_options)
        if results.failures:
            raise RuntimeError('Failures mapping trace:\n%s' %
                               ('\n'.join(str(f) for f in results.failures)))
        return results.pairs
Ejemplo n.º 7
0
def _ProcessTracesWithMapper(mapper_handle_str, traces, output_file):
    map_handle = function_handle.FunctionHandle.FromUserFriendlyString(
        mapper_handle_str)
    job = job_module.Job(map_handle)

    trace_handles = [
        file_handle.URLFileHandle(f, 'file://%s' % f) for f in traces
    ]

    runner = map_runner.MapRunner(
        trace_handles,
        job,
        progress_reporter=progress_reporter.ProgressReporter())

    results = runner.RunMapper()
    results_dict = {k: v.AsDict() for k, v in results.iteritems()}
    _DumpToOutputJson(results_dict, output_file)

    return _GetExitCodeForResults(results)
Ejemplo n.º 8
0
def RunMetricOnTraces(filenames,
                      metrics,
                      extra_import_options=None,
                      report_progress=True):
    trace_handles = [
        file_handle.URLFileHandle(f, 'file://%s' % f) for f in filenames
    ]
    job = _GetMetricRunnerHandle(metrics)
    with open(os.devnull, 'w') as devnull_f:
        o_stream = sys.stdout
        if report_progress:
            o_stream = devnull_f

        runner = map_runner.MapRunner(
            trace_handles,
            job,
            extra_import_options=extra_import_options,
            progress_reporter=gtest_progress_reporter.GTestProgressReporter(
                output_stream=o_stream))
        map_results = runner.RunMapper()

    return map_results