Ejemplo n.º 1
0
 def test_parse_lines_as_metrics(self):
     lines = [
         ':::MLM 123 clock : { "value": "START", "metadata": {} }',
         ':::MLM 124 quality : { "value": "77.1", "metadata": {} }',
         ':::MLM 125 clock : { "value": "END", "metadata": {} }'
     ]
     expected = [
         metrics_file.Metric(123, 'clock', 'START', {}),
         metrics_file.Metric(124, 'quality', '77.1', {}),
         metrics_file.Metric(125, 'clock', 'END', {})
     ]
     parsed, errors = log_converter.parse_lines_as_metrics(lines)
     self.assertEqual(errors, [])
     self.assertEqual(parsed, expected)
Ejemplo n.º 2
0
def _convert_line_to_metric(line):
  """Converts a single log line into a Metric object."""
  m = LINE_REGEX.match(line)
  if m is None:
    raise ParsingError('Could not parse: {}'.format(line))
  j = json.loads(m.group(3))
  d = metrics_file.Metric(
      float(m.group(1)), m.group(2), j['value'], j['metadata'])
  return d
Ejemplo n.º 3
0
    def test_parse_lines_as_metrics(self):
        log_lines = [
            ':::MLL 123 clock : { "value": "START", "metadata": {} }',
            ':::MLL 124 quality : { "value": "77.1", "metadata": {} }',
            ':::MLL 125 clock : { "value": "END", "metadata": {} }',
        ]

        with tempfile.NamedTemporaryFile(mode='w', delete=False) as f:
            f.writelines('%s\n' % l for l in log_lines)

        expected = metrics_file.BenchmarkRun([
            metrics_file.Metric(123, 'clock', 'START', {}),
            metrics_file.Metric(124, 'quality', '77.1', {}),
            metrics_file.Metric(125, 'clock', 'END', {})
        ])

        log_f = log_lines_file.LogLineFile(f.name)
        parsed, errors = log_f.as_benchmark_run()

        self.assertEqual(errors, [])
        self.assertEqual(parsed, expected)
Ejemplo n.º 4
0
    def test_convert_line_to_metric_cases(self):
        self._assert_expected_metric(
            (':::MLL 123.456 /c1/c2/c3.key: '
             '{"value": 80.123, "metadata": '
             '{"lineno": 81, "file": "some_dir/some_file.py"}}'),
            metrics_file.Metric(123.456, '/c1/c2/c3.key', 80.123, {
                'lineno': 81,
                'file': 'some_dir/some_file.py'
            }))

        self._assert_expected_metric(
            ':::MLL 123 custom_metric: {"value": 80.123, "metadata": {}}',
            metrics_file.Metric(123, 'custom_metric', 80.123, {}))

        self._assert_expected_metric(
            ':::MLL 123 c1-c2-c3: {"value": 80.123, "metadata": {}}',
            metrics_file.Metric(123, 'c1-c2-c3', 80.123, {}))

        self._assert_expected_metric(
            ':::MLL 123 c1-c2-c3.c4: {"value": 80.123, "metadata": {}}',
            metrics_file.Metric(123, 'c1-c2-c3.c4', 80.123, {}))
Ejemplo n.º 5
0
    def test_convert_line_to_metric(self):
        line = ':::MLM 123 foo : { "value": "bar", "metadata": {} }'

        expected = metrics_file.Metric(123, 'foo', 'bar', {})
        self.assertEqual(
            log_converter.convert_line_to_metric(line)[0], expected)