xref: /aosp_15_r20/external/angle/src/tests/py_utils/angle_metrics.py (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1# Copyright 2023 The ANGLE Project Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4#
5# Utility for handling ANGLE perf metrics, separate file as it's
6# called by both the test runner and the post-processing script.
7
8import collections
9import json
10import logging
11import statistics
12
13
14def ConvertToSkiaPerf(angle_metrics_json_files):
15    grouped_results = collections.defaultdict(list)
16    for fn in angle_metrics_json_files:
17        with open(fn) as f:
18            metrics = json.load(f)
19            for group in metrics:
20                for d in group:
21                    k = (('suite', d['name']), ('renderer', d['backend'].lstrip('_')),
22                         ('test', d['story']), ('metric', d['metric'].lstrip('.')), ('units',
23                                                                                     d['units']))
24                    grouped_results[k].append(float(d['value']))
25
26    results = []
27    for k, v in grouped_results.items():
28        results.append({
29            'key': dict(k),
30            'measurements': {
31                'stat': [{
32                    'value': 'mean',
33                    'measurement': statistics.mean(v),
34                }, {
35                    'value': 'stdev',
36                    'measurement': statistics.stdev(v) if len(v) > 1 else 0,
37                }],
38            },
39        })
40
41    logging.info('angle_metrics to skia perf: %d entries' % len(results))
42
43    return results
44