Exemplo n.º 1
0
  def GetAutotestMetricValue(self, report_file):
    """Gets metric value from autotest benchmark report.

    Report example:
      {"avg_fps_1000_fishes": {
         "summary": {
           "units": "fps",
           "type": "scalar",
           "value": 56.733810392225671,
           "improvement_direction": "up"
         },
         ...,
       },
       ...,
      }
      self.metric = "avg_fps_1000_fishes/summary/value"

    Args:
      report_file: Path to benchmark report.

    Returns:
      Metric value in benchmark report.
      None if self.metric is undefined or metric does not exist in the report.
    """
    if not self.metric:
      return None

    report = json_lib.ParseJsonFileWithComments(report_file)
    metric_value = json_lib.GetNestedDictValue(report, self.metric.split('/'))
    if metric_value is None:
      logging.error('Cannot get metric %s from %s', self.metric, report_file)
      return None
    if self.metric_take_average:
      return float(sum(metric_value)) / len(metric_value)
    return metric_value
Exemplo n.º 2
0
  def testGetNestedDictValue(self):
    """Test that GetNestedDictValue is correct."""
    NESTED_DICT = {
        'lv1.1': {
            'lv2.1': {'value': '1.1'},
            'lv2.2': {'value': '1.2'}},
        'lv1.2': {
            'lv2.1': {'value': '2.1'},
            'lv2.2': {'value': '2.2'}}}
    self.assertEqual(
        '1.1',
        json_lib.GetNestedDictValue(NESTED_DICT, ['lv1.1', 'lv2.1', 'value']))
    self.assertEqual(
        '2.1',
        json_lib.GetNestedDictValue(NESTED_DICT, ['lv1.2', 'lv2.1', 'value']))
    # level 2 key missing
    self.assertIsNone(
        json_lib.GetNestedDictValue(NESTED_DICT, ['lv1.1', 'lv2.3', 'value']))
    # level 1 key missing
    self.assertIsNone(
        json_lib.GetNestedDictValue(NESTED_DICT, ['lv1.3', 'lv2.1', 'value']))
    # no level 3 key
    self.assertIsNone(
        json_lib.GetNestedDictValue(NESTED_DICT,
                                    ['lv1.1', 'lv2.1', 'lv3', 'value']))

    # no level 4
    self.assertIsNone(
        json_lib.GetNestedDictValue(NESTED_DICT,
                                    ['lv1.1', 'lv2.1', 'value', '1.1']))