예제 #1
0
    def testAsDict(self):
        result = mre_result.MreResult()

        with map_single_trace.TemporaryMapScript("""
      pi.FunctionRegistry.register(
          function MyMapFunction(result, model) {
            var canonicalUrl = model.canonicalUrl;
            result.addPair('result', {
                numProcesses: model.getAllProcesses().length
              });
          });
      """) as map_script:

            module = function_handle.ModuleToLoad(filename=map_script.filename)
            map_handle = function_handle.FunctionHandle(
                modules_to_load=[module], function_name='MyMapFunction')
            job = job_module.Job(map_handle, None)
            failure = failure_module.Failure(job, '2', '3', 'err', 'desc',
                                             'stack')
            result.AddFailure(failure)

            result.AddPair('foo', 'bar')

            result_dict = result.AsDict()

            self.assertEquals(result_dict['failures'], [failure.AsDict()])
            self.assertEquals(result_dict['pairs'], {'foo': 'bar'})
예제 #2
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 = perf_insights_project.PerfInsightsProject()

    all_source_paths = list(project.source_paths)
    all_source_paths.append(project.perf_insights_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)

    if res.returncode != 0:
        try:
            sys.stderr.write(res.stdout)
        except Exception:
            pass
        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
예제 #3
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
예제 #4
0
    def RunReducer(self, reduce_handles_with_keys):
        if self._job.reduce_function_handle:
            self._wq.Reset()

            job_results = mre_result.MreResult()

            for cur in reduce_handles_with_keys:
                handle = cur['handle']
                for key in cur['keys']:
                    self._wq.PostAnyThreadTask(self._Reduce, job_results, key,
                                               handle)

            def _Stop():
                self._wq.Stop()

            self._wq.PostAnyThreadTask(_Stop)
            self._wq.Run()

            return job_results
        return None
예제 #5
0
 def testAddingNonFailure(self):
     result = mre_result.MreResult()
     with self.assertRaises(ValueError):
         result.AddFailure('foo')